From: Pengji Zhang <me@pengjiz.com>
To: Eli Zaretskii <eliz@gnu.org>, sbaugh@janestreet.com
Cc: joaotavora@gmail.com, 65035@debbugs.gnu.org
Subject: bug#65035: 29.1; Port flycheck-emacs-lisp-initialize-packages to flymake
Date: Sun, 10 Nov 2024 09:33:30 +0800 [thread overview]
Message-ID: <87y11rj2j9.fsf@pengjiz.com> (raw)
In-Reply-To: <86y11sn4rw.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 302 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
> I think the doc string should explicitly mention
> elisp-flymake-byte-compile-user-file-p, since it is used as the
> default value of the option.
>
> [...]
>
> Please add a :version tag here.
Thanks for the review! Fixed in the attached updated patch.
Pengji
[-- Attachment #2: 0001-Add-option-elisp-flymake-byte-compile-activate-packa.patch --]
[-- Type: text/x-patch, Size: 5232 bytes --]
From 6d34dcc9de1f99c795d0a6bcaa416e29c8500eed Mon Sep 17 00:00:00 2001
From: Pengji Zhang <me@pengjiz.com>
Date: Sun, 10 Nov 2024 09:30:01 +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@gmail.com>
---
etc/NEWS | 7 ++++++
lisp/progmodes/elisp-mode.el | 46 ++++++++++++++++++++++++++++++++++++
2 files changed, 53 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..3905300c9a8 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -2190,6 +2190,44 @@ 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.
+
+The default value is a predicate function
+`elisp-flymake-byte-compile-user-file-p' (which see), and that means
+packages are activated only for user configuration files.
+
+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
+ :version "31.1")
+
+(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 +2243,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 +2267,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
next prev parent reply other threads:[~2024-11-10 1:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 10:04 bug#65035: 29.1; Port flycheck-emacs-lisp-initialize-packages to flymake Antonio Romano via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-23 9:01 ` Pengji Zhang
2024-10-23 10:32 ` Eli Zaretskii
2024-10-23 11:15 ` João Távora
2024-10-25 11:50 ` Pengji Zhang
2024-11-09 9:19 ` Eli Zaretskii
2024-11-10 1:33 ` Pengji Zhang [this message]
2024-11-12 21:56 ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-14 11:18 ` Pengji Zhang
2024-11-14 13:25 ` Ship Mints
2024-11-30 9:48 ` Eli Zaretskii
2024-12-14 9:33 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y11rj2j9.fsf@pengjiz.com \
--to=me@pengjiz.com \
--cc=65035@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=joaotavora@gmail.com \
--cc=sbaugh@janestreet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).