all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#65035: 29.1; Port flycheck-emacs-lisp-initialize-packages to flymake
@ 2023-08-03 10:04 Antonio Romano via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-10-23  9:01 ` Pengji Zhang
  0 siblings, 1 reply; 5+ messages in thread
From: Antonio Romano via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-08-03 10:04 UTC (permalink / raw)
  To: 65035



Flycheck includes the "flycheck-emacs-lisp-initialize-packages"
customizable variable, which allows packages to be initialized in the
Emacs subprocess used to lint the elisp file. With this variable, it is
possible for the linter to be aware of autoloads from installed
packages.

I think that having such option on the built-in alternative "flymake"
would be a good quality-of-life addition, as this would make it more
suitable for linting personal configuration and only one M-x away from
any user who would want to try it.

Thanks in advance









^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#65035: 29.1; Port flycheck-emacs-lisp-initialize-packages to flymake
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Pengji Zhang @ 2024-10-23  9:01 UTC (permalink / raw)
  To: 65035

Hi!

I am switching to Flymake and I missed this feature as well. I think
this bug report is related:

    https://debbugs.gnu.org/cgi/bugreport.cgi?bug=48452

In that thread João gave a patch that implements this feature (sort of):

    https://debbugs.gnu.org/cgi/bugreport.cgi?bug=48452#43

Although it was not installed.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#65035: 29.1; Port flycheck-emacs-lisp-initialize-packages to flymake
  2024-10-23  9:01 ` Pengji Zhang
@ 2024-10-23 10:32   ` Eli Zaretskii
  2024-10-23 11:15     ` João Távora
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2024-10-23 10:32 UTC (permalink / raw)
  To: Pengji Zhang, sbaugh; +Cc: João Távora, 65035

> From: Pengji Zhang <me@pengjiz.com>
> Date: Wed, 23 Oct 2024 17:01:23 +0800
> 
> I am switching to Flymake and I missed this feature as well. I think
> this bug report is related:
> 
>     https://debbugs.gnu.org/cgi/bugreport.cgi?bug=48452
> 
> In that thread João gave a patch that implements this feature (sort of):
> 
>     https://debbugs.gnu.org/cgi/bugreport.cgi?bug=48452#43
> 
> Although it was not installed.

Adding Spencer, who nowadays maintains Flymake, and João.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#65035: 29.1; Port flycheck-emacs-lisp-initialize-packages to flymake
  2024-10-23 10:32   ` Eli Zaretskii
@ 2024-10-23 11:15     ` João Távora
  2024-10-25 11:50       ` Pengji Zhang
  0 siblings, 1 reply; 5+ messages in thread
From: João Távora @ 2024-10-23 11:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: sbaugh, 65035, Pengji Zhang

On Wed, Oct 23, 2024 at 11:33 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Pengji Zhang <me@pengjiz.com>
> > Date: Wed, 23 Oct 2024 17:01:23 +0800
> >
> > I am switching to Flymake and I missed this feature as well. I think
> > this bug report is related:
> >
> >     https://debbugs.gnu.org/cgi/bugreport.cgi?bug=48452
> >
> > In that thread João gave a patch that implements this feature (sort of):
> >
> >     https://debbugs.gnu.org/cgi/bugreport.cgi?bug=48452#43
> >
> > Although it was not installed.
>
> Adding Spencer, who nowadays maintains Flymake, and João.

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.

João





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#65035: 29.1; Port flycheck-emacs-lisp-initialize-packages to flymake
  2024-10-23 11:15     ` João Távora
@ 2024-10-25 11:50       ` Pengji Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: Pengji Zhang @ 2024-10-25 11:50 UTC (permalink / raw)
  To: 65035; +Cc: sbaugh, Eli Zaretskii, João Távora

[-- Attachment #1: Type: text/plain, Size: 304 bytes --]

João Távora <joaotavora@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


[-- Attachment #2: 0001-Add-option-elisp-flymake-byte-compile-activate-packa.patch --]
[-- Type: text/x-patch, Size: 5034 bytes --]

From be772ff2f3bae82977d6c54fa84960f721ba088e Mon Sep 17 00:00:00 2001
From: Pengji Zhang <me@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@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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-25 11:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.