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: Fri, 25 Oct 2024 19:50:48 +0800 Message-ID: <87ed44s8o7.fsf@pengjiz.com> References: <87o73b6vmk.fsf@pengjiz.com> <86o73bds9e.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="13847"; mail-complaints-to="usenet@ciao.gmane.io" Cc: sbaugh@janestreet.com, Eli Zaretskii , =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= To: 65035@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 25 13:51:56 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 1t4IrD-0003Ok-CH for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 25 Oct 2024 13:51:55 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t4Iqr-00074e-AM; Fri, 25 Oct 2024 07:51:33 -0400 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 1t4Iqp-000748-GT for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2024 07:51:31 -0400 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 1t4Iqp-0003SS-7g for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2024 07:51:31 -0400 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=lFkoXcwAkRHZG7AZOV3x5bvhG51RkGNJ5w9lQT6q/x0=; b=MdnMK3UGl0eho/8Emb0D61mD5KmbMFxuE8HG2ih2SMwQaVsBl96+v3kj6WDcHq4qIXbgM01uJ0br5h5rEaXGXqt5hIapdihdoNMopht5uFh55WJIV0FFvw+YuGyld0YRg8zLTTt/ku/NTxEzsl/t4AeaeHHYvb/zhQvvhgjus5SrtPd2arvwF8VTC+eSJVbj8tmNUSBhkG0YSKSCUEIvMIOGK9UJQBtBjn3RXMhXgd9ypO+Wu6SB+mmjlDqIxdCZALK79SOGHlQu1SLllJg2xQ3kLvMKPBcX1B/QjJMVLXXjSTwEvQ8MQ3fNed7YIFMiwxsoXTO8O4Bz34bqynXSVA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t4IrK-0008An-3M for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2024 07:52:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Pengji Zhang Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 25 Oct 2024 11:52: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.172985710431391 (code B ref 65035); Fri, 25 Oct 2024 11:52:02 +0000 Original-Received: (at 65035) by debbugs.gnu.org; 25 Oct 2024 11:51:44 +0000 Original-Received: from localhost ([127.0.0.1]:37581 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t4Ir2-0008AE-0E for submit@debbugs.gnu.org; Fri, 25 Oct 2024 07:51:44 -0400 Original-Received: from fout-b3-smtp.messagingengine.com ([202.12.124.146]:52111) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t4Iqz-0008A0-Mx for 65035@debbugs.gnu.org; Fri, 25 Oct 2024 07:51:42 -0400 Original-Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.stl.internal (Postfix) with ESMTP id 32AF91140133; Fri, 25 Oct 2024 07:51:03 -0400 (EDT) Original-Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Fri, 25 Oct 2024 07:51:03 -0400 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=1729857063; x=1729943463; bh=lFkoXcwAkR HZG7AZOV3x5bvhG51RkGNJ5w9lQT6q/x0=; b=QMJ/EdWn2UO5B9a9aLjwVyIXPG 4xDDLMgSOvRsnyAX7CqbsQ3kTkXzRp0Mg5NZg9kBR4T4YI7ZRsE+kfLyhOSEMks9 G5z2yBsLEZ0akLYQnAy1RUEY/IJQ0tNK6548qCOAGyKAQFQz9cvyMfYYRDmJxVak BmpUPCQggSoJF2GKHGOABWl9JNgwizJkltS+YMnEMOqHYBO/Rwrt0TJ43gvmT7K9 P4hV2lA7I7c4R4x5g1KngJShI0Ry12/a3gNZbyX6yI4CK9KnbhR48wlkbJqk7NL1 mphdZ3+Q1MNLCCLyyCq1sHcNTIcf+jqlLEK4Li5TB6bvMpHMsp77ZyRAlhwg== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1729857063; x=1729943463; bh=lFkoXcwAkRHZG7AZOV3x5bvhG51R kGNJ5w9lQT6q/x0=; b=ci1evgEjPGcwJ0sgzXyHxldjk3pK7yoOK7cRYh2+oY/+ CAebqCTTMVA4FO4UxXyesEoPWgEsCDEg3BBtXz0FY1UUdLFnAKt1DvqESDWA3L8S 47JIkf2+Y8nEapIlmbnVOTUVk+poeOFzTubrGszAUHlsb4+edLO4kJzB3/tCf2Qq JjcGpWDbH0V/vnh2ozzOxsIABNcu54qBV5HP4E9AHGO8aTxero/+B7PGWcd2dM3H cmQVsBdhejIOWi4nClZ8s3LYymjR0Sx5GP8QMqt8AZfHe0KSQafYEMRIarKafM3Z 4f/SuUVO1Oz6BW/XaLCibwOHusiq1n3edlxdMTaxEA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdejvddggeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefujghffffkgggtsehmtderredttdejnecu hfhrohhmpefrvghnghhjihcukghhrghnghcuoehmvgesphgvnhhgjhhiiidrtghomheqne cuggftrfgrthhtvghrnhepkeevieekgfeiudeuvefgieevfeejhfffkefhgeegfedtgeek tdegueejffdugeetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepmhgvsehpvghnghhjihiirdgtohhmpdhnsggprhgtphhtthhopeegpdhmohgu vgepshhmthhpohhuthdprhgtphhtthhopeeihedtfeehseguvggssghughhsrdhgnhhurd horhhgpdhrtghpthhtohepshgsrghughhhsehjrghnvghsthhrvggvthdrtghomhdprhgt phhtthhopehjohgrohhtrghvohhrrgesghhmrghilhdrtghomhdprhgtphhtthhopegvlh hiiiesghhnuhdrohhrgh X-ME-Proxy: Feedback-ID: i16614472:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 25 Oct 2024 07:51:01 -0400 (EDT) In-Reply-To: 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:294224 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Jo=C3=A3o T=C3=A1vora 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 --=-=-= 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 be772ff2f3bae82977d6c54fa84960f721ba088e Mon Sep 17 00:00:00 2001 From: Pengji Zhang 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=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 | 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-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..8a9dce5d3f6 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -2190,6 +2190,39 @@ 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. + +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-compi= le*")) ;; 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) --=20 2.47.0 --=-=-=--