refactor(syntax): separate out implementations

As `+emacs-lisp-non-package-mode` handles both flymake and flycheck,
making two internal modes that then `+emacs-lisp-non-package-mode`
calls, makes the code cleaner
This commit is contained in:
Jeetaditya Chatterjee 2023-09-10 23:34:05 +01:00
parent c37f314f14
commit b50b2c4640
No known key found for this signature in database
GPG key ID: 4A1E5568BA34D124

View file

@ -338,41 +338,23 @@ as `+emacs-lisp-non-package-mode' will enable it and disable the other checkers.
(ignore-errors (delete-file tmp-file)) (ignore-errors (delete-file tmp-file))
(kill-buffer out-buf)))))))) (kill-buffer out-buf))))))))
;;;###autoload (define-minor-mode +emacs-lisp--flymake-non-package-mode
(define-minor-mode +emacs-lisp-non-package-mode ""
"Reduce flycheck/flymake verbosity where it is appropriate.
Essentially, this means in any elisp file that either:
- Is not a theme in `custom-theme-load-path',
- Lacks a `provide' statement,
- Lives in a project with a .doommodule file,
- Is a dotfile (like .dir-locals.el or .doomrc).
This generally applies to your private config (`doom-user-dir') or Doom's source
\(`doom-emacs-dir')."
:since "3.0.0" :since "3.0.0"
(unless (and (or (bound-and-true-p flycheck-mode) (if +emacs-lisp--flymake-non-package-mode
(bound-and-true-p flymake-mode))
(not (+emacs-lisp--in-package-buffer-p)))
(setq +emacs-lisp-non-package-mode nil))
(when (derived-mode-p 'emacs-lisp-mode)
(add-hook 'after-save-hook #'+emacs-lisp-non-package-mode nil t))
(if (not +emacs-lisp-non-package-mode)
(if (modulep! :checkers syntax +flymake)
;; flymake
(progn
(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
(when (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)))
(if (modulep! :checkers syntax +flymake)
;; flymake
(progn (progn
(remove-hook! 'flymake-diagnostic-functions :local #'elisp-flymake-checkdoc #'elisp-flymake-byte-compile) (remove-hook! 'flymake-diagnostic-functions :local #'elisp-flymake-checkdoc #'elisp-flymake-byte-compile)
(add-hook 'flymake-diagnostic-functions #'+emacs-lisp-reduced-flymake-byte-compile)) (add-hook 'flymake-diagnostic-functions #'+emacs-lisp-reduced-flymake-byte-compile nil t))
;; flycheck (add-hook! 'flymake-diagnostic-functions :local #'elisp-flymake-checkdoc #'elisp-flymake-byte-compile)
(remove-hook 'flymake-diagnostic-functions #'+emacs-lisp-reduced-flymake-byte-compile t)))
(define-minor-mode +emacs-lisp--flycheck-non-package-mode
""
:since "3.0.0"
(if (not +emacs-lisp--flycheck-non-package-mode)
(when (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))
(with-memoization (get 'flycheck-disabled-checkers 'initial-value) (with-memoization (get 'flycheck-disabled-checkers 'initial-value)
flycheck-disabled-checkers) flycheck-disabled-checkers)
(setq-local flycheck-emacs-lisp-check-form (setq-local flycheck-emacs-lisp-check-form
@ -396,7 +378,30 @@ This generally applies to your private config (`doom-user-dir') or Doom's source
0 0 (error-message-string e))))) 0 0 (error-message-string e)))))
,(read (default-toplevel-value 'flycheck-emacs-lisp-check-form)))) ,(read (default-toplevel-value 'flycheck-emacs-lisp-check-form))))
flycheck-disabled-checkers (cons 'emacs-lisp-checkdoc flycheck-disabled-checkers (cons 'emacs-lisp-checkdoc
flycheck-disabled-checkers))))) flycheck-disabled-checkers))))
;;;###autoload
(define-minor-mode +emacs-lisp-non-package-mode
"Reduce flycheck/flymake verbosity where it is appropriate.
Essentially, this means in any elisp file that either:
- Is not a theme in `custom-theme-load-path',
- Lacks a `provide' statement,
- Lives in a project with a .doommodule file,
- Is a dotfile (like .dir-locals.el or .doomrc).
This generally applies to your private config (`doom-user-dir') or Doom's source
\(`doom-emacs-dir')."
:since "3.0.0"
(unless (and (or (bound-and-true-p flycheck-mode)
(bound-and-true-p flymake-mode))
(not (+emacs-lisp--in-package-buffer-p)))
(setq +emacs-lisp-non-package-mode nil))
(when (derived-mode-p 'emacs-lisp-mode)
(add-hook 'after-save-hook #'+emacs-lisp-non-package-mode nil t))
(let ((toggle (if +emacs-lisp-non-package-mode +1 -1)))
(if (modulep! :checkers syntax +flymake)
(+emacs-lisp--flymake-non-package-mode toggle)
(+emacs-lisp--flycheck-non-package-mode toggle))))
;; ;;