From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pengji Zhang Newsgroups: gmane.emacs.bugs Subject: bug#65035: 29.1; Port flycheck-emacs-lisp-initialize-packages to flymake Date: Sun, 10 Nov 2024 09:33:30 +0800 Message-ID: <87y11rj2j9.fsf@pengjiz.com> References: <87o73b6vmk.fsf@pengjiz.com> <86o73bds9e.fsf@gnu.org> <87ed44s8o7.fsf@pengjiz.com> <86y11sn4rw.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39836"; mail-complaints-to="usenet@ciao.gmane.io" Cc: joaotavora@gmail.com, 65035@debbugs.gnu.org To: Eli Zaretskii , sbaugh@janestreet.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 10 02:34:26 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t9wqN-000ABB-Dx for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Nov 2024 02:34:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9wq4-00057H-N8; Sat, 09 Nov 2024 20:34:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9wq3-00056k-JF for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 20:34:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t9wq3-00079a-B8 for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 20:34:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=0RzN0ReTYNl/hvsUELkvGHWL9RXPnq1Qu+9ORBZYjEY=; b=jKHW9A8tABoeeiyhpDKhbqV/jZ8PUPMRfJL33W4Qie1zCy4PJLYkP5jnm++Q3L4Lo8uynrnZIBrrh8ohbP8mGPwIKxVBXCevrKbaa38k6H9WugXuTzLI8ty0fJPiMzLSFnjngmv/985IxVFd6vqs8lV+huul2Avh76BVHEtlCmLhiXs47N5B/BIp7WH61NGkaZYsWyAOvBidU/K0u1dH+vqR/2bHwPGTRhKT/kbNRXzREvrlMI1xYBPNT04v4auaYmhW22gjzbo8c/iVlF8ADtA4uXI8DAH+MmIdmXkaiIBaK07Wu1UKmhNVMUDd/TiHOb88XR9Zl/p6PIzvDqMaLA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t9wq2-0002qi-L1 for bug-gnu-emacs@gnu.org; Sat, 09 Nov 2024 20:34:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Pengji Zhang Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Nov 2024 01:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65035 X-GNU-PR-Package: emacs Original-Received: via spool by 65035-submit@debbugs.gnu.org id=B65035.173120244010940 (code B ref 65035); Sun, 10 Nov 2024 01:34:02 +0000 Original-Received: (at 65035) by debbugs.gnu.org; 10 Nov 2024 01:34:00 +0000 Original-Received: from localhost ([127.0.0.1]:55005 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t9wq0-0002qN-4O for submit@debbugs.gnu.org; Sat, 09 Nov 2024 20:34:00 -0500 Original-Received: from fout-b8-smtp.messagingengine.com ([202.12.124.151]:40107) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t9wpx-0002q7-Ow for 65035@debbugs.gnu.org; Sat, 09 Nov 2024 20:33:58 -0500 Original-Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id 713EE1140100; Sat, 9 Nov 2024 20:33:52 -0500 (EST) Original-Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Sat, 09 Nov 2024 20:33:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1731202432; x=1731288832; bh=0RzN0ReTYN l/hvsUELkvGHWL9RXPnq1Qu+9ORBZYjEY=; b=gBcRZV3yFVdgwSUX4Fr48fgYvE keQtkAUin9ohMgozzpAiWDXdYmJAId6cHwXTkL5MxcLtwjoWVCKTnFzh3jEjCkMv OJN38eCNzc7U3nKfsgoDl9Gk5fxTexX/1RwKnt/Ghac4cbQZqfuzd9Ss28SZ6LKy XmlXASodTOmvN3ZEKZKAnam2DpgrJeOlzKjersfZBuD3z0SGGs5wlvFP03YHYPIL V1zhf1+K2yV6s7VbcAABpSBO2m+h41Ul6gQP/4UYqHe7uN9IEXzqBDWvDDsJMDRS B9CS974IWcEu8cvS2mr/8zHf9tHOiGsWWWft16SmstbXt65JxAC+FqdBz6QA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1731202432; x=1731288832; bh=0RzN0ReTYNl/hvsUELkvGHWL9RXPnq1Qu+9 ORBZYjEY=; b=AH4GNw7e8b4hWO8S33EDS/G3aQJjP6YI3QX2DAyDiRc2BShgL8k ik9+Sjg95ByaN0+KC+vSS0kIRTB02k5PB00LLU6nHbcW9EL/5sIK6NX8RHcFDnpB i0RmBNM/2YyUtozPKhECIXOs2fkkVxRFRBKrJOCxwacNvu+xjJOY+VQ0e4ZoGTPT ngEB68t/xsucj475WfqGyVpyBm1+CMgQqJf9uvoyQe64Zt1yCH4few6oocDtaH9p NNEZIhPS77uO16+EnIj1SdHUfRBw859K1sHqSpIj7BjGf6QNIF58qffzJ0kB6Wvp WQbao6dSdC2JuBRDCi7jaGyM/j47wl/7gIg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrtdelgdefiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufgjfhffkfggtgesmhdtreertddttdenucfh rhhomheprfgvnhhgjhhiucgkhhgrnhhguceomhgvsehpvghnghhjihiirdgtohhmqeenuc ggtffrrghtthgvrhhnpeeifffgieeulefgjeejiedvleehffffueeiiefhhfffveejuefh gedvhfekgfelkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehmvgesphgvnhhgjhhiiidrtghomhdpnhgspghrtghpthhtohepgedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepvghlihiisehgnhhurdhorhhgpdhrtghpthhtoh epshgsrghughhhsehjrghnvghsthhrvggvthdrtghomhdprhgtphhtthhopeeihedtfeeh seguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepjhhorghothgrvhhorhgrse hgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i16614472:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 9 Nov 2024 20:33:50 -0500 (EST) In-Reply-To: <86y11sn4rw.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:295163 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii 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 --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-Add-option-elisp-flymake-byte-compile-activate-packa.patch Content-Transfer-Encoding: quoted-printable >From 6d34dcc9de1f99c795d0a6bcaa416e29c8500eed Mon Sep 17 00:00:00 2001 From: Pengji Zhang 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=3DUTF-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=C3=A3o T=C3=A1vora --- 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-warnin= g', and In most cases, having it enabled leads to a large amount of false positives. =20 +--- +*** 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 =20 --- 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 =20 (defvar bytecomp--inhibit-lexical-cookie-warning) =20 +(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=3D 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-compi= le*")) ;; 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) --=20 2.47.0 --=-=-=--