feat(emacs-lisp): add reduced-flymake-byte-compile
This is a flymake backend that gives a reduced set of byte compiler warnings in accordance too `+emacs-lisp-linter-warnings`
This commit is contained in:
parent
2e67ad18e9
commit
e976351424
1 changed files with 74 additions and 9 deletions
|
@ -277,9 +277,71 @@ https://emacs.stackexchange.com/questions/10230/how-to-indent-keywords-aligned"
|
||||||
file-base)))))))
|
file-base)))))))
|
||||||
(not (locate-dominating-file default-directory ".doommodule")))))
|
(not (locate-dominating-file default-directory ".doommodule")))))
|
||||||
|
|
||||||
|
(defvar-local +emacs-lisp-reduced-flymake-byte-compile--process nil)
|
||||||
|
|
||||||
|
(defun +emacs-lisp-reduced-flymake-byte-compile (report-fn &rest _args)
|
||||||
|
"A Flymake backend for warnings from the elisp byte compiler
|
||||||
|
|
||||||
|
This checker reduces the amount of false positives the byte compiler throws off
|
||||||
|
compared too `elisp-flymake-byte-compile'. The linter warnings that are enabled
|
||||||
|
are set by `+emacs-lisp-linter-warnings'
|
||||||
|
|
||||||
|
This backend does not need to be added directly
|
||||||
|
as `+emacs-lisp-non-package-mode' will enable it and disable the other checkers."
|
||||||
|
;; if a process already exists. kill it.
|
||||||
|
(when (and +emacs-lisp-reduced-flymake-byte-compile--process
|
||||||
|
(process-live-p +emacs-lisp-reduced-flymake-byte-compile--process))
|
||||||
|
(kill-process +emacs-lisp-reduced-flymake-byte-compile--process))
|
||||||
|
(let ((source (current-buffer))
|
||||||
|
(tmp-file (make-temp-file "+emacs-lisp-byte-compile-src"))
|
||||||
|
(out-buf (generate-new-buffer "+emacs-lisp-byte-compile-out")))
|
||||||
|
;; write the content to a temp file
|
||||||
|
(save-restriction
|
||||||
|
(widen)
|
||||||
|
(write-region nil nil tmp-file nil 'nomessage))
|
||||||
|
;; make the process
|
||||||
|
(setq +emacs-lisp-reduced-flymake-byte-compile--process
|
||||||
|
(make-process
|
||||||
|
:name "+emacs-reduced-flymake"
|
||||||
|
:noquery t
|
||||||
|
:connetion-type 'pipe
|
||||||
|
:buffer out-buf
|
||||||
|
:command `(,(expand-file-name invocation-name invocation-directory)
|
||||||
|
"-Q"
|
||||||
|
"--batch"
|
||||||
|
,@(mapcan (fn! (list "-L" %)) elisp-flymake-byte-compile-load-path)
|
||||||
|
;; this is what silences the byte compiler
|
||||||
|
"--eval" ,(prin1-to-string `(setq doom-modules ',doom-modules
|
||||||
|
doom-disabled-packages ',doom-disabled-packages
|
||||||
|
byte-compile-warnings ',+emacs-lisp-linter-warnings)
|
||||||
|
)
|
||||||
|
"-f" "elisp-flymake--batch-compile-for-flymake"
|
||||||
|
,tmp-file)
|
||||||
|
:stderr "*stderr of +elisp-flymake-byte-compile-out*"
|
||||||
|
:sentinel
|
||||||
|
;; deal with the process when it exits
|
||||||
|
(lambda (proc _event)
|
||||||
|
(when (memq (process-status proc) '(exit signal))
|
||||||
|
(unwind-protect
|
||||||
|
(cond
|
||||||
|
;; if the buffer is dead or the process is not the same, log the process as old.
|
||||||
|
((or (not (buffer-live-p source))
|
||||||
|
(not (with-current-buffer source (eq proc +emacs-lisp-reduced-flymake-byte-compile--process))))
|
||||||
|
(flymake-log :warning "byte compile process %s is old" proc))
|
||||||
|
;; if the process exited without problem process the buffer
|
||||||
|
((zerop (process-exit-status proc))
|
||||||
|
(elisp-flymake--byte-compile-done report-fn source out-buf))
|
||||||
|
;; otherwise something else horrid has gone wrong and we panic
|
||||||
|
(t (funcall report-fn :panic
|
||||||
|
:explanation
|
||||||
|
(format "byte compile process %s died" proc))))
|
||||||
|
;; cleanup
|
||||||
|
(ignore-errors (delete-file tmp-file))
|
||||||
|
(kill-buffer out-buf))))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-minor-mode +emacs-lisp-non-package-mode
|
(define-minor-mode +emacs-lisp-non-package-mode
|
||||||
"Reduce flycheck verbosity where it is appropriate.
|
"Reduce flycheck/flymake verbosity where it is appropriate.
|
||||||
|
|
||||||
Essentially, this means in any elisp file that either:
|
Essentially, this means in any elisp file that either:
|
||||||
- Is not a theme in `custom-theme-load-path',
|
- Is not a theme in `custom-theme-load-path',
|
||||||
|
@ -300,14 +362,17 @@ This generally applies to your private config (`doom-user-dir') or Doom's source
|
||||||
(if (modulep! :checkers syntax +flymake)
|
(if (modulep! :checkers syntax +flymake)
|
||||||
;; flymake
|
;; flymake
|
||||||
(progn
|
(progn
|
||||||
(add-hook 'flymake-diagnostic-functions #'elisp-flymake-checkdoc nil t))
|
(add-hook! 'flymake-diagnostic-functions :local #'elisp-flymake-checkdoc #'elisp-flymake-byte-compile)
|
||||||
|
(remove-hook 'flymake-diagnostic-functions #'+emacs-lisp-reduced-flymake-byte-compile))
|
||||||
;; flycheck
|
;; flycheck
|
||||||
(when (get 'flycheck-disabled-checkers 'initial-value)
|
(when (get 'flycheck-disabled-checkers 'initial-value)
|
||||||
(setq-local flycheck-disabled-checkers (get 'flycheck-disabled-checkers 'initial-value))
|
(setq-local flycheck-disabled-checkers (get 'flycheck-disabled-checkers 'initial-value))
|
||||||
(kill-local-variable 'flycheck-emacs-lisp-check-form)))
|
(kill-local-variable 'flycheck-emacs-lisp-check-form)))
|
||||||
(if (modulep! :checkers syntax +flymake)
|
(if (modulep! :checkers syntax +flymake)
|
||||||
;; flymake
|
;; flymake
|
||||||
(remove-hook 'flymake-diagnostic-functions #'elisp-flymake-checkdoc t)
|
(progn
|
||||||
|
(remove-hook! 'flymake-diagnostic-functions :local #'elisp-flymake-checkdoc #'elisp-flymake-byte-compile)
|
||||||
|
(add-hook 'flymake-diagnostic-functions #'+emacs-lisp-reduced-flymake-byte-compile))
|
||||||
;; flycheck
|
;; flycheck
|
||||||
(with-memoization (get 'flycheck-disabled-checkers 'initial-value)
|
(with-memoization (get 'flycheck-disabled-checkers 'initial-value)
|
||||||
flycheck-disabled-checkers)
|
flycheck-disabled-checkers)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue