GNU bug report logs -
#65035
29.1; Port flycheck-emacs-lisp-initialize-packages to flymake
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
João Távora <joaotavora <at> gmail.com> writes:
> Feel free to use my patch of course. Stefan noted some time ago
> that -f package-initialize is the wrong flag to ask Emacs -Q to use
> elpa though, so there's something better.
Thanks! I prepared a new patch based on yours.
Regards,
Pengji
[0001-Add-option-elisp-flymake-byte-compile-activate-packa.patch (text/x-patch, inline)]
From be772ff2f3bae82977d6c54fa84960f721ba088e Mon Sep 17 00:00:00 2001
From: Pengji Zhang <me <at> pengjiz.com>
Date: Fri, 25 Oct 2024 19:44:44 +0800
Subject: [PATCH] Add option 'elisp-flymake-byte-compile-activate-packages'
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This option controls whether the Flymake Emacs Lisp
byte-compiler should activate user installed packages before
checking the source buffer. (Bug#65035)
* lisp/progmodes/elisp-mode.el
(elisp-flymake-byte-compile-user-file-p): New predicate function
to check if a buffer is visiting a user file.
(elisp-flymake-byte-compile-activate-packages): New option.
(elisp-flymake--byte-compile-activate-packages): New variable
for caching.
(elisp-flymake-byte-compile): Use the new option.
* etc/NEWS: Announce the new option.
Co-authored-by: João Távora <joaotavora <at> gmail.com>
---
etc/NEWS | 7 ++++++
lisp/progmodes/elisp-mode.el | 41 ++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index a6c2c895985..090f4293c8e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -413,6 +413,13 @@ This affects calls to 'warn', 'lwarn', 'display-warning', and
In most cases, having it enabled leads to a large amount of false
positives.
+---
+*** New user option 'elisp-flymake-byte-compile-activate-packages'.
+This option controls whether or not the Flymake byte-compiler backend
+should activate user installed packages before compiling the source
+buffer. By default, it is set to activate packages when checking user
+configuration files. Set it to nil to restore the previous behavior.
+
** DocView
---
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 2f931daedc7..8a9dce5d3f6 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -2190,6 +2190,39 @@ elisp-flymake-byte-compile-load-path
(defvar bytecomp--inhibit-lexical-cookie-warning)
+(defun elisp-flymake-byte-compile-user-file-p (buffer)
+ "Return non-nil if BUFFER is visiting a user file.
+That means either the file is `user-init-file' or it is in
+`user-emacs-directory'."
+ (when-let* ((file (buffer-local-value 'buffer-file-truename buffer)))
+ (or (and user-emacs-directory
+ (file-in-directory-p file user-emacs-directory))
+ (and user-init-file
+ (string= file (abbreviate-file-name
+ (file-truename user-init-file)))))))
+
+(defcustom elisp-flymake-byte-compile-activate-packages
+ #'elisp-flymake-byte-compile-user-file-p
+ "Whether to activate packages for Flymake elisp byte-compilation.
+If the value is nil, do not activate installed packages. If the value
+is a function, it is called with one argument, the source buffer to be
+checked, and installed packages are activated if the function returns
+non-nil. Otherwise, packages are always activated.
+
+Note that for efficiency the return value of the predicate function is
+cached the first time it is called. Type \\[revert-buffer-quick] to
+invalidate the cached value."
+ :type '(choice
+ (const :tag "Don't activate" nil)
+ (const :tag "Always activate" t)
+ (const :tag "Activate for user files"
+ elisp-flymake-byte-compile-user-file-p)
+ (function :tag "Predicate function"))
+ :group 'lisp)
+
+(defvar-local elisp-flymake--byte-compile-activate-packages :unset
+ "Cached value for `elisp-flymake-byte-compile-activate-packages'.")
+
;;;###autoload
(defun elisp-flymake-byte-compile (report-fn &rest _args)
"A Flymake backend for elisp byte compilation.
@@ -2205,6 +2238,12 @@ elisp-flymake-byte-compile
(save-restriction
(widen)
(write-region (point-min) (point-max) temp-file nil 'nomessage))
+ (when (eq elisp-flymake--byte-compile-activate-packages :unset)
+ (setq elisp-flymake--byte-compile-activate-packages
+ (if (functionp elisp-flymake-byte-compile-activate-packages)
+ (funcall elisp-flymake-byte-compile-activate-packages
+ source-buffer)
+ elisp-flymake-byte-compile-activate-packages)))
(let* ((output-buffer (generate-new-buffer " *elisp-flymake-byte-compile*"))
;; Hack: suppress warning about missing lexical cookie in
;; *scratch* buffers.
@@ -2223,6 +2262,8 @@ elisp-flymake-byte-compile
;; "--eval" "(setq load-prefer-newer t)" ; for testing
,@(mapcan (lambda (path) (list "-L" path))
elisp-flymake-byte-compile-load-path)
+ ,@(when elisp-flymake--byte-compile-activate-packages
+ '("-f" "package-activate-all"))
,@warning-suppression-opt
"-f" "elisp-flymake--batch-compile-for-flymake"
,temp-file)
--
2.47.0
This bug report was last modified 169 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.