From ffd2654aa3166f767ed2eafebfc9cae34d75f454 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 2 Feb 2024 18:47:15 -0500 Subject: [PATCH] fix(emacs-lisp): non-package-mode: only enable in elisp buffers This prevents +emacs-lisp-non-package-mode from being activated in non-elisp buffers. Amend: #7341 Close: #7645 Co-authored-by: PatrickNorton --- modules/lang/emacs-lisp/autoload.el | 19 ++++++++++++------- modules/lang/emacs-lisp/config.el | 9 +++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/modules/lang/emacs-lisp/autoload.el b/modules/lang/emacs-lisp/autoload.el index 6aeab83f4..a9cbffc48 100644 --- a/modules/lang/emacs-lisp/autoload.el +++ b/modules/lang/emacs-lisp/autoload.el @@ -379,6 +379,7 @@ as `+emacs-lisp-non-package-mode' will enable it and disable the other checkers. ,(read (default-toplevel-value 'flycheck-emacs-lisp-check-form)))) flycheck-disabled-checkers (cons 'emacs-lisp-checkdoc flycheck-disabled-checkers)))) + ;;;###autoload (define-minor-mode +emacs-lisp-non-package-mode "Reduce flycheck/flymake verbosity where it is appropriate. @@ -394,15 +395,19 @@ This generally applies to your private config (`doom-user-dir') or Doom's source :since "3.0.0" (unless (and (or (bound-and-true-p flycheck-mode) (bound-and-true-p flymake-mode)) + (derived-mode-p 'emacs-lisp-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))) - (cond ((modulep! :checkers syntax +flymake) - (+emacs-lisp--flymake-non-package-mode toggle)) - ((modulep! :checkers syntax) - (+emacs-lisp--flycheck-non-package-mode toggle))))) + (when-let ((modesym (cond ((modulep! :checkers syntax +flymake) + #'+emacs-lisp--flymake-non-package-mode) + ((modulep! :checkers syntax) + #'+emacs-lisp--flycheck-non-package-mode)))) + (if (not +emacs-lisp-non-package-mode) + (when (symbol-value modesym) + (funcall modesym -1)) + (when (derived-mode-p 'emacs-lisp-mode) + (add-hook 'after-save-hook #'+emacs-lisp-non-package-mode nil t)) + (funcall modesym +1)))) ;; diff --git a/modules/lang/emacs-lisp/config.el b/modules/lang/emacs-lisp/config.el index 90c613053..3cabce3b6 100644 --- a/modules/lang/emacs-lisp/config.el +++ b/modules/lang/emacs-lisp/config.el @@ -95,10 +95,11 @@ See `+emacs-lisp-non-package-mode' for details.") ;; Ensure straight sees modifications to installed packages #'+emacs-lisp-init-straight-maybe-h) - ;; UX: Both Flycheck's and Flymake's two - ;; emacs-lisp checkers produce a *lot* of false positives in non-packages - ;; (like Emacs configs or elisp scripts), so I disable `checkdoc' (`emacs-lisp-checkdoc', `elisp-flymake-checkdoc') - ;; and set `byte-compile-warnings' to a subset that makes more sense (see `+emacs-lisp-linter-warnings') + ;; UX: Both Flycheck's and Flymake's two emacs-lisp checkers produce a *lot* + ;; of false positives in non-packages (like Emacs configs or elisp + ;; scripts), so I disable `checkdoc' (`emacs-lisp-checkdoc', + ;; `elisp-flymake-checkdoc') and set `byte-compile-warnings' to a subset + ;; that makes more sense (see `+emacs-lisp-linter-warnings') (add-hook! '(flycheck-mode-hook flymake-mode-hook) #'+emacs-lisp-non-package-mode) (defadvice! +syntax--fix-elisp-flymake-load-path (orig-fn &rest args)