From unknown Sun Jun 22 04:28:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#12259: [Mathieu Boespflug] Add delete-trailing-whitespace to list of safe eval forms Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: mboes@tweag.net, bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 Aug 2012 13:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 12259 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 12259@debbugs.gnu.org Cc: Mathieu Boespflug X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Mathieu Boespflug Received: via spool by submit@debbugs.gnu.org id=B.134564157628060 (code B ref -1); Wed, 22 Aug 2012 13:20:02 +0000 Received: (at submit) by debbugs.gnu.org; 22 Aug 2012 13:19:36 +0000 Received: from localhost ([127.0.0.1]:42880 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T4AqJ-0007IT-VY for submit@debbugs.gnu.org; Wed, 22 Aug 2012 09:19:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39361) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T4AqE-0007II-2G for submit@debbugs.gnu.org; Wed, 22 Aug 2012 09:19:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T4Apj-00077w-KZ for submit@debbugs.gnu.org; Wed, 22 Aug 2012 09:19:01 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:52123) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4Apj-00077r-EB for submit@debbugs.gnu.org; Wed, 22 Aug 2012 09:18:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4Apf-0005Al-Cy for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2012 09:18:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T4ApX-000761-4n for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2012 09:18:51 -0400 Received: from ironport2-out.teksavvy.com ([206.248.154.182]:37238) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4ApW-00075q-TZ for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2012 09:18:43 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAG6Zu09MCpcJ/2dsb2JhbABEtBGBCIIVAVxPAwECHSYYDRYhiA6YUqE3iwgJhTMDozOBWIMFgToJ X-IronPort-AV: E=Sophos;i="4.75,637,1330923600"; d="scan'208";a="196425218" Received: from 76-10-151-9.dsl.teksavvy.com (HELO pastel.home) ([76.10.151.9]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 22 Aug 2012 09:18:41 -0400 Received: by pastel.home (Postfix, from userid 20848) id 61DBA4EA3D; Wed, 22 Aug 2012 09:18:40 -0400 (EDT) From: Stefan Monnier Message-ID: Date: Wed, 22 Aug 2012 09:18:40 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.118.235.17 X-Spam-Score: -6.2 (------) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.2 (------) --=-=-= Content-Type: text/plain Mistakenly sent to emacs-devel. --=-=-= Content-Type: message/rfc822 Content-Disposition: inline Return-Path: X-Original-To: monnier@iro.umontreal.ca Delivered-To: monnier@iro.umontreal.ca Received: from perlin.iro.umontreal.ca (perlin.iro.umontreal.ca [132.204.24.51]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id 8A2BE869EA for ; Mon, 20 Aug 2012 14:39:28 -0400 (EDT) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by perlin.iro.umontreal.ca (Postfix) with ESMTP id 4B96C830003 for ; Mon, 20 Aug 2012 14:38:44 -0400 (EDT) Received: from localhost ([::1]:37732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3Ws6-0002HP-RF for monnier@iro.umontreal.ca; Mon, 20 Aug 2012 14:38:42 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48241) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <0xbadcode@gmail.com>) id 1T3Ws1-0002H4-6d for emacs-devel@gnu.org; Mon, 20 Aug 2012 14:38:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <0xbadcode@gmail.com>) id 1T3Wry-0008OE-LO for emacs-devel@gnu.org; Mon, 20 Aug 2012 14:38:37 -0400 Received: from mail-gg0-f169.google.com ([209.85.161.169]:43471) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <0xbadcode@gmail.com>) id 1T3Wry-0008O2-I1 for emacs-devel@gnu.org; Mon, 20 Aug 2012 14:38:34 -0400 Received: by ggnf4 with SMTP id f4so5792315ggn.0 for ; Mon, 20 Aug 2012 11:38:33 -0700 (PDT) Received: by 10.50.100.134 with SMTP id ey6mr10999211igb.4.1345487913420; Mon, 20 Aug 2012 11:38:33 -0700 (PDT) Received: from santiago.tweag.net ([216.252.64.250]) by mx.google.com with ESMTPS id a3sm13480625igd.7.2012.08.20.11.38.32 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 20 Aug 2012 11:38:32 -0700 (PDT) From: Mathieu Boespflug To: emacs-devel@gnu.org Subject: Add delete-trailing-whitespace to list of safe eval forms Date: Mon, 20 Aug 2012 14:35:50 -0400 Message-ID: <87r4r1e7i1.fsf@santiago.tweag.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.161.169 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+monnier=iro.umontreal.ca@gnu.org Sender: emacs-devel-bounces+monnier=iro.umontreal.ca@gnu.org X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=-1.873, requis 5, BAYES_00 -2.60, RCVD_BY_IP 0.07, RECEIVED_FROM_NOUNK 0.66, SPF_HELO_PASS -0.00) X-DIRO-MailScanner-From: emacs-devel-bounces+monnier=iro.umontreal.ca@gnu.org X-Spam-Status: No MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="====-=-=" --====-=-= Content-Type: text/plain Content-Disposition: inline Hi, I'm trying to add the delete-trailing-whitespace hook to the .dir-locals.el of a project. Because .dir-locals.el does not support adding hooks directly, I use an eval clause, as follows: ((nil (eval . (add-hook 'write-contents-functions 'delete-trailing-whitespace)))) write-contents-functions is a buffer local hook whereas write-file-hook and before-save-hook are not, so the above does not tamper with the user's preferences when editing files in other directories. The above is problematic however, because Emacs 23 asks the user whether to run this eval expression *every time the user opens a file in that directory*. Emacs 24 is better because it allows the user to say "yes" once and for all and have Emacs never ask again, but it still asks the first time. However, I have noticed that by default Emacs already blesses certain eval forms as being safe in .dir-locals.el and in mode lines. Here is the content of safe-local-eval-forms in emacs 23.1: ((add-hook (quote write-file-hooks) (quote time-stamp))) and emacs 24.1: ((add-hook (quote write-file-hooks) (quote time-stamp)) (add-hook (quote write-file-functions) (quote time-stamp)) (add-hook (quote before-save-hook) (quote time-stamp))) It seems as though, if evaluation forms that add 'time-stamp to various hooks that all run around the time a file is saved are deemed safe by default, surely evaluation forms that add 'delete-trailing-whitespace should equally be deemed safe by default. I have attached a patch at the end of this email that considers eval forms that add 'delete-trailing-whitespace to various hooks safe by default. But ideally this patch would be superseded by adding a mechanism that allows .dir-locals.el to add predefined functions to hooks (at least buffer local ones) without having to use eval. That way we wouldn't have to write patches such as this one for every new sensible stock function that people want to have executed on file saves. Regards, -- Mathieu --====-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-files.el-say-adding-delete-trailing-whitespace-to-ho.patch >>From 5f71b0dc3bc3b09cfb58d26ca6643b4e4a013a31 Mon Sep 17 00:00:00 2001 From: Mathieu Boespflug Date: Mon, 20 Aug 2012 14:25:49 -0400 Subject: [PATCH] files.el: say adding 'delete-trailing-whitespace to hooks is safe. --- lisp/files.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/files.el b/lisp/files.el index 5caa468..0b6f60f 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -2837,7 +2837,9 @@ symbol and VAL is a value that is considered safe." ;; This should be here at least as long as Emacs supports write-file-hooks. '((add-hook 'write-file-hooks 'time-stamp) (add-hook 'write-file-functions 'time-stamp) - (add-hook 'before-save-hook 'time-stamp)) + (add-hook 'before-save-hook 'time-stamp) + (add-hook 'write-file-functions 'delete-trailing-whitespace) + (add-hook 'write-content-functions 'delete-trailing-whitespace)) "Expressions that are considered safe in an `eval:' local variable. Add expressions to this list if you want Emacs to evaluate them, when they appear in an `eval' local variable specification, without first -- 1.7.11.4 --====-=-=-- --=-=-=-- From unknown Sun Jun 22 04:28:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#12259: Add delete-trailing-whitespace to list of safe eval forms In-Reply-To: Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 Aug 2012 14:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12259 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Mathieu Boespflug Cc: 12259@debbugs.gnu.org Received: via spool by 12259-submit@debbugs.gnu.org id=B12259.13456462292685 (code B ref 12259); Wed, 22 Aug 2012 14:38:02 +0000 Received: (at 12259) by debbugs.gnu.org; 22 Aug 2012 14:37:09 +0000 Received: from localhost ([127.0.0.1]:43482 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T4C3P-0000hC-OM for submit@debbugs.gnu.org; Wed, 22 Aug 2012 10:37:09 -0400 Received: from ironport2-out.teksavvy.com ([206.248.154.182]:8937) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T4C3D-0000gY-V5 for 12259@debbugs.gnu.org; Wed, 22 Aug 2012 10:36:56 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAG6Zu09MCpcJ/2dsb2JhbABEtBGBCIIVAQEEAVYjBQsLDiYSFBgNHgaIHAW6CZBEA6MzgViDBYFD X-IronPort-AV: E=Sophos;i="4.75,637,1330923600"; d="scan'208";a="196432317" Received: from 76-10-151-9.dsl.teksavvy.com (HELO pastel.home) ([76.10.151.9]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 22 Aug 2012 10:36:29 -0400 Received: by pastel.home (Postfix, from userid 20848) id 684B74EA3D; Wed, 22 Aug 2012 10:36:29 -0400 (EDT) From: Stefan Monnier Message-ID: References: <87r4r1e7i1.fsf@santiago.tweag.net> Date: Wed, 22 Aug 2012 10:36:29 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.9 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) > It seems as though, if evaluation forms that add 'time-stamp to various > hooks that all run around the time a file is saved are deemed safe by > default, surely evaluation forms that add 'delete-trailing-whitespace > should equally be deemed safe by default. Agreed, thanks. > I have attached a patch at the end of this email that considers eval > forms that add 'delete-trailing-whitespace to various hooks safe by > default. Actually, I wonder whether we want to accept/encourage those uses instead of (add-hook 'before-save-hook 'delete-trailing-whitespace). IOW I think we should only add the before-save-hook version but not the others (and I guess the same holds for time-stamp, tho we'll probably keep the other ones for time-stamp for backward-compatibility reasons). > But ideally this patch would be superseded by adding a mechanism that > allows .dir-locals.el to add predefined functions to hooks (at least > buffer local ones) without having to use eval. Why? > That way we wouldn't have to write patches such as this one for every > new sensible stock function that people want to have executed on > file saves. You don't have to write patches like this one. You can just customize safe-local-eval-forms. There is a problem, indeed, tho: if you customize this var and we later add things to it, you'll keep using your customized version and won't benefit from the expanded list. So we should keep the default value of safe-local-eval-forms as nil, and allow things like those add-hook some other way (e.g. a new var). Stefan From unknown Sun Jun 22 04:28:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#12259: Add delete-trailing-whitespace to list of safe eval forms Resent-From: Glenn Morris Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 Aug 2012 16:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12259 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stefan Monnier Cc: 12259@debbugs.gnu.org, Mathieu Boespflug Received: via spool by 12259-submit@debbugs.gnu.org id=B12259.134565271212020 (code B ref 12259); Wed, 22 Aug 2012 16:26:01 +0000 Received: (at 12259) by debbugs.gnu.org; 22 Aug 2012 16:25:12 +0000 Received: from localhost ([127.0.0.1]:43582 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T4Djz-00037n-7N for submit@debbugs.gnu.org; Wed, 22 Aug 2012 12:25:11 -0400 Received: from fencepost.gnu.org ([208.118.235.10]:38672) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T4Djx-00037h-FB for 12259@debbugs.gnu.org; Wed, 22 Aug 2012 12:25:10 -0400 Received: from rgm by fencepost.gnu.org with local (Exim 4.71) (envelope-from ) id 1T4DjX-0001Xo-Cn; Wed, 22 Aug 2012 12:24:43 -0400 From: Glenn Morris References: <87r4r1e7i1.fsf@santiago.tweag.net> X-Spook: enigma Leitrim infowar Bin Laden Mantis Hamas chameleon X-Ran: MiPBnMEY:~i^D"Ju}O94'U:|>W0+Y"X{X'>y{p_jk'YP>6JN^soA>$"{1i4{lIE:L!{*U9 X-Hue: yellow X-Attribution: GM Date: Wed, 22 Aug 2012 12:24:43 -0400 In-Reply-To: (Stefan Monnier's message of "Wed, 22 Aug 2012 10:36:29 -0400") Message-ID: <3v7gsq99o4.fsf@fencepost.gnu.org> User-Agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Score: -7.1 (-------) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -7.1 (-------) Stefan Monnier wrote: > Actually, I wonder whether we want to accept/encourage those uses > instead of (add-hook 'before-save-hook 'delete-trailing-whitespace). OT: I wouldn't encourage that either. :) Blind application of such a hook has removed trailing whitespace that was supposed to be there in the Emacs sources a few times. > You don't have to write patches like this one. You can just customize > safe-local-eval-forms. There is a problem, indeed, tho: if you > customize this var and we later add things to it, you'll keep using your > customized version and won't benefit from the expanded list. > So we should keep the default value of safe-local-eval-forms as nil, and > allow things like those add-hook some other way (e.g. a new var). (add-to-list 'safe-local-eval-forms ...) There's also the long-standing Todo item to create a "diff-list" custom type http://debbugs.gnu.org/7812, and use it for such things. From unknown Sun Jun 22 04:28:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#12259: Add delete-trailing-whitespace to list of safe eval forms Resent-From: Mathieu Boespflug Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 Aug 2012 16:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12259 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stefan Monnier Cc: 12259@debbugs.gnu.org Received: via spool by 12259-submit@debbugs.gnu.org id=B12259.134565415914334 (code B ref 12259); Wed, 22 Aug 2012 16:50:02 +0000 Received: (at 12259) by debbugs.gnu.org; 22 Aug 2012 16:49:19 +0000 Received: from localhost ([127.0.0.1]:43634 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T4E7K-0003j8-Lg for submit@debbugs.gnu.org; Wed, 22 Aug 2012 12:49:19 -0400 Received: from mail-yx0-f172.google.com ([209.85.213.172]:52631) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from <0xbadcode@gmail.com>) id 1T4Dpg-0003He-8b for 12259@debbugs.gnu.org; Wed, 22 Aug 2012 12:31:05 -0400 Received: by yenm5 with SMTP id m5so836697yen.3 for <12259@debbugs.gnu.org>; Wed, 22 Aug 2012 09:30:38 -0700 (PDT) Received: by 10.50.186.130 with SMTP id fk2mr2839065igc.60.1345653033041; Wed, 22 Aug 2012 09:30:33 -0700 (PDT) Received: from santiago.tweag.net ([216.252.64.250]) by mx.google.com with ESMTPS id ua5sm3322208igb.10.2012.08.22.09.30.31 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 22 Aug 2012 09:30:32 -0700 (PDT) From: Mathieu Boespflug References: <87r4r1e7i1.fsf@santiago.tweag.net> Date: Wed, 22 Aug 2012 12:27:47 -0400 In-Reply-To: (Stefan Monnier's message of "Wed, 22 Aug 2012 10:36:29 -0400") Message-ID: <87r4qyao3g.fsf@santiago.tweag.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.6 (--) X-Mailman-Approved-At: Wed, 22 Aug 2012 12:49:17 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) >> I have attached a patch at the end of this email that considers eval >> forms that add 'delete-trailing-whitespace to various hooks safe by >> default. > > Actually, I wonder whether we want to accept/encourage those uses > instead of (add-hook 'before-save-hook 'delete-trailing-whitespace). The problem with the method above is that before-save-hook isn't made a buffer-local variable by hack-local-variables. Therefore, using (add-hook 'before-save-hook 'delete-trailing-whitespace) causes delete-trailing-whitespace to be run even for buffers that are not in the directory hierarchy of .dir-locals.el. This is undesirable because .dir-locals.el is often used by free software projects to enforce a common set of guidelines and style for editing code. Any changes to hooks should therefore ideally be directory local, so as to apply only to those files that are part of some particular free software repository. > IOW I think we should only add the before-save-hook version but not > the others (and I guess the same holds for time-stamp, tho we'll > probably keep the other ones for time-stamp for backward-compatibility > reasons). (See above.) >> But ideally this patch would be superseded by adding a mechanism that >> allows .dir-locals.el to add predefined functions to hooks (at least >> buffer local ones) without having to use eval. > > Why? Because using eval for the purposes of adding new functions to hooks feels overkill, and causes several problems. The affecting-hooks-that-are-not-buffer-local problem is one of them. Another problem is that there are many equivalent ways of modifying a hook (using add-hook, using setq, etc), so adding new entries to safe-local-eval-forms would never catch them all. >> That way we wouldn't have to write patches such as this one for every >> new sensible stock function that people want to have executed on >> file saves. > > You don't have to write patches like this one. You can just customize > safe-local-eval-forms. There is a problem, indeed, tho: if you > customize this var and we later add things to it, you'll keep using your > customized version and won't benefit from the expanded list. > So we should keep the default value of safe-local-eval-forms as nil, and > allow things like those add-hook some other way (e.g. a new var). ... and that's the third problem caused by using eval to set hooks. Besides, customizing safe-local-eval-forms isn't a great solution in the scenario discussed above: the whole point for a free software project to have a .dir-locals.el at the root of the repo is so that none of the (potentially hundreds of) developers of that project need to fiddle with customize manually. -- Mathieu From unknown Sun Jun 22 04:28:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#12259: Add delete-trailing-whitespace to list of safe eval forms Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 23 Aug 2012 11:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12259 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Glenn Morris Cc: 12259@debbugs.gnu.org, Mathieu Boespflug Received: via spool by 12259-submit@debbugs.gnu.org id=B12259.134572270029023 (code B ref 12259); Thu, 23 Aug 2012 11:52:02 +0000 Received: (at 12259) by debbugs.gnu.org; 23 Aug 2012 11:51:40 +0000 Received: from localhost ([127.0.0.1]:44669 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T4Vwm-0007Y0-5b for submit@debbugs.gnu.org; Thu, 23 Aug 2012 07:51:39 -0400 Received: from ironport2-out.teksavvy.com ([206.248.154.182]:17083) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T4Vwj-0007Xs-Jf for 12259@debbugs.gnu.org; Thu, 23 Aug 2012 07:51:34 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAG6Zu09FpZ+X/2dsb2JhbABEtBGBCIIVAQEEAVYjEAsOJhIUGA0kiBwFugmQRAOWKolrgx6BWIMF X-IronPort-AV: E=Sophos;i="4.75,637,1330923600"; d="scan'208";a="196505937" Received: from 69-165-159-151.dsl.teksavvy.com (HELO pastel.home) ([69.165.159.151]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 23 Aug 2012 07:51:02 -0400 Received: by pastel.home (Postfix, from userid 20848) id 430B558ADD; Thu, 23 Aug 2012 07:51:02 -0400 (EDT) From: Stefan Monnier Message-ID: References: <87r4r1e7i1.fsf@santiago.tweag.net> <3v7gsq99o4.fsf@fencepost.gnu.org> Date: Thu, 23 Aug 2012 07:51:02 -0400 In-Reply-To: <3v7gsq99o4.fsf@fencepost.gnu.org> (Glenn Morris's message of "Wed, 22 Aug 2012 12:24:43 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.9 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) >> Actually, I wonder whether we want to accept/encourage those uses >> instead of (add-hook 'before-save-hook 'delete-trailing-whitespace). > OT: I wouldn't encourage that either. :) > Blind application of such a hook has removed trailing whitespace that > was supposed to be there in the Emacs sources a few times. That's a different issue. The question is not whether it's a good idea for a user to use such a setting but: - whether having such a setting in the file-(or directory-)local variables can be used as an attack vector. - which hook to use. And I believe before-save-hook is always the better choice here. > (add-to-list 'safe-local-eval-forms ...) > There's also the long-standing Todo item to create a "diff-list" custom > type http://debbugs.gnu.org/7812, and use it for such things. Indeed for safe-local-eval-forms a simple diff-list would be sufficient since safe-local-eval-forms is really a set (implemented as a list) so we don't need to worry about ordering/repetitions/... Could someone provide a patch for that? Stefan From unknown Sun Jun 22 04:28:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#12259: Add delete-trailing-whitespace to list of safe eval forms Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 23 Aug 2012 12:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12259 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Mathieu Boespflug Cc: 12259@debbugs.gnu.org Received: via spool by 12259-submit@debbugs.gnu.org id=B12259.134572441531509 (code B ref 12259); Thu, 23 Aug 2012 12:21:01 +0000 Received: (at 12259) by debbugs.gnu.org; 23 Aug 2012 12:20:15 +0000 Received: from localhost ([127.0.0.1]:44726 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T4WOU-0008C8-PL for submit@debbugs.gnu.org; Thu, 23 Aug 2012 08:20:15 -0400 Received: from ironport2-out.teksavvy.com ([206.248.154.182]:45969) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T4WOT-0008C2-0H for 12259@debbugs.gnu.org; Thu, 23 Aug 2012 08:20:13 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ai0FAG6Zu09FpZ+X/2dsb2JhbABEsEiDSYEIghUBAQQBViMFCwsOJhIUGA0kLoduBboJixsHhSIDozOBWIMFgToJ X-IronPort-AV: E=Sophos;i="4.75,637,1330923600"; d="scan'208";a="196507532" Received: from 69-165-159-151.dsl.teksavvy.com (HELO pastel.home) ([69.165.159.151]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 23 Aug 2012 08:19:42 -0400 Received: by pastel.home (Postfix, from userid 20848) id CD76058ADD; Thu, 23 Aug 2012 08:19:41 -0400 (EDT) From: Stefan Monnier Message-ID: References: <87r4r1e7i1.fsf@santiago.tweag.net> <87r4qyao3g.fsf@santiago.tweag.net> Date: Thu, 23 Aug 2012 08:19:41 -0400 In-Reply-To: <87r4qyao3g.fsf@santiago.tweag.net> (Mathieu Boespflug's message of "Wed, 22 Aug 2012 12:27:47 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.9 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) >>> I have attached a patch at the end of this email that considers eval >>> forms that add 'delete-trailing-whitespace to various hooks safe by >>> default. >> Actually, I wonder whether we want to accept/encourage those uses >> instead of (add-hook 'before-save-hook 'delete-trailing-whitespace). > The problem with the method above is that before-save-hook isn't made > a buffer-local variable by hack-local-variables. Therefore, using > (add-hook 'before-save-hook 'delete-trailing-whitespace) causes > delete-trailing-whitespace to be run even for buffers that are not in > the directory hierarchy of .dir-locals.el. Indeed, you have to use (add-hook 'before-save-hook 'delete-trailing-whitespace nil t) With very few (historical) exceptions, all hooks are neither global-only nor buffer-local-only, so the "nil t" args should always be used for buffer-local settings. So we have a bug in the current setting of safe-local-eval-forms. >>> But ideally this patch would be superseded by adding a mechanism that >>> allows .dir-locals.el to add predefined functions to hooks (at least >>> buffer local ones) without having to use eval. >> Why? > Because using eval for the purposes of adding new functions to hooks > feels overkill, and causes several problems. The > affecting-hooks-that-are-not-buffer-local problem is one of them. > Another problem is that there are many equivalent ways of modifying > a hook (using add-hook, using setq, etc), so adding new entries to > safe-local-eval-forms would never catch them all. setq is a wrong way to modify a hook, and safe-local-eval-forms does not need to catch them all, only to allow the ones that are known safe and that are useful. That fact that using eval is overkill doesn't matter, since safe-local-eval-forms restricts this "overkill power" to something very much less powerful. The shape of the setting has to be ": ", so for adding a function to a hook, it could be "add-hook: (write-file-functions time-stamp)", but that's not terribly more convenient than "eval: (add-hook 'write-file-functions 'time-stamp)" while having the disadvantage that eval re-uses an existing syntax. Now, admittedly, because of the `local' argument, the choice is really between add-hook: (write-file-functions time-stamp) and eval: (add-hook 'write-file-functions 'time-stamp nil t) or eval: (add-local-hook 'write-file-functions 'time-stamp) I much prefer one of the last two since it is familiar to Elisp coders, and for those for whom it's not familiar, it's a useful syntax to learn since they can also use it in their .emacs. >> You don't have to write patches like this one. You can just customize >> safe-local-eval-forms. There is a problem, indeed, tho: if you >> customize this var and we later add things to it, you'll keep using your >> customized version and won't benefit from the expanded list. >> So we should keep the default value of safe-local-eval-forms as nil, and >> allow things like those add-hook some other way (e.g. a new var). > ... and that's the third problem caused by using eval to set hooks. No, the same problem would appear with a special "add-hook" setting, since we'd need a new safe-local-add-hooks which would suffer from the same complications. > Besides, customizing safe-local-eval-forms isn't a great solution in the > scenario discussed above: the whole point for a free software project to > have a .dir-locals.el at the root of the repo is so that none of the > (potentially hundreds of) developers of that project need to fiddle with > customize manually. There's no clearly safe subset of Elisp, so we're limited to listing a few known safe cases which we know are used. Note that adding an element to safe-local-eval-forms is a lot easier than changing your .emacs so that the files of project X (and only those files) are opened with the right settings, so the use of .dir-local.el is still very useful even if it has to use an eval form that's not in the default value of safe-local-eval-forms. I've just installed the patch below in the emacs-24 branch. Stefan === modified file 'lisp/files.el' --- lisp/files.el 2012-08-15 16:29:11 +0000 +++ lisp/files.el 2012-08-23 12:15:31 +0000 @@ -2837,7 +2837,8 @@ ;; This should be here at least as long as Emacs supports write-file-hooks. '((add-hook 'write-file-hooks 'time-stamp) (add-hook 'write-file-functions 'time-stamp) - (add-hook 'before-save-hook 'time-stamp)) + (add-hook 'before-save-hook 'time-stamp nil t) + (add-hook 'before-save-hook 'delete-trailing-whitespace nil t)) "Expressions that are considered safe in an `eval:' local variable. Add expressions to this list if you want Emacs to evaluate them, when they appear in an `eval' local variable specification, without first From unknown Sun Jun 22 04:28:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#12259: Add delete-trailing-whitespace to list of safe eval forms Resent-From: Mathieu Boespflug Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 23 Aug 2012 13:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12259 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stefan Monnier Cc: 12259@debbugs.gnu.org Received: via spool by 12259-submit@debbugs.gnu.org id=B12259.13457270432857 (code B ref 12259); Thu, 23 Aug 2012 13:05:02 +0000 Received: (at 12259) by debbugs.gnu.org; 23 Aug 2012 13:04:03 +0000 Received: from localhost ([127.0.0.1]:44740 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T4X4s-0000jo-2s for submit@debbugs.gnu.org; Thu, 23 Aug 2012 09:04:03 -0400 Received: from mail-iy0-f172.google.com ([209.85.210.172]:56502) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from <0xbadcode@gmail.com>) id 1T4X4p-0000jc-Mx for 12259@debbugs.gnu.org; Thu, 23 Aug 2012 09:04:00 -0400 Received: by iabz21 with SMTP id z21so1301947iab.3 for <12259@debbugs.gnu.org>; Thu, 23 Aug 2012 06:03:28 -0700 (PDT) Received: by 10.42.156.1 with SMTP id x1mr1124662icw.51.1345727008787; Thu, 23 Aug 2012 06:03:28 -0700 (PDT) Received: from santiago.tweag.net ([216.252.64.250]) by mx.google.com with ESMTPS id at10sm10553722igc.16.2012.08.23.06.03.22 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 23 Aug 2012 06:03:24 -0700 (PDT) From: Mathieu Boespflug References: <87r4r1e7i1.fsf@santiago.tweag.net> <87r4qyao3g.fsf@santiago.tweag.net> Date: Thu, 23 Aug 2012 09:00:37 -0400 In-Reply-To: (Stefan Monnier's message of "Thu, 23 Aug 2012 08:19:41 -0400") Message-ID: <87sjbdvk3u.fsf@santiago.tweag.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.6 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) > I've just installed the patch below in the emacs-24 branch. Thanks Stefan. That should do the trick. -- Mathieu > === modified file 'lisp/files.el' > --- lisp/files.el 2012-08-15 16:29:11 +0000 > +++ lisp/files.el 2012-08-23 12:15:31 +0000 > @@ -2837,7 +2837,8 @@ > ;; This should be here at least as long as Emacs supports write-file-hooks. > '((add-hook 'write-file-hooks 'time-stamp) > (add-hook 'write-file-functions 'time-stamp) > - (add-hook 'before-save-hook 'time-stamp)) > + (add-hook 'before-save-hook 'time-stamp nil t) > + (add-hook 'before-save-hook 'delete-trailing-whitespace nil t)) > "Expressions that are considered safe in an `eval:' local variable. > Add expressions to this list if you want Emacs to evaluate them, when > they appear in an `eval' local variable specification, without first From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 25 22:47:01 2012 Received: (at control) by debbugs.gnu.org; 26 Aug 2012 02:47:01 +0000 Received: from localhost ([127.0.0.1]:49064 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T5SsO-00033a-KK for submit@debbugs.gnu.org; Sat, 25 Aug 2012 22:47:01 -0400 Received: from mail-pb0-f44.google.com ([209.85.160.44]:34381) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T5SsK-00033Q-B2 for control@debbugs.gnu.org; Sat, 25 Aug 2012 22:46:56 -0400 Received: by pbbrr4 with SMTP id rr4so5474184pbb.3 for ; Sat, 25 Aug 2012 19:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:mime-version:content-type; bh=4OiMoxehdv+BM91lq3ndV48zGAlJbwAb2Yoy8jV7AvI=; b=q1FNqGw+lVDr+EXY6q5AmEA6tGIRnSrNNZPhzgFcmnoNPLF/yO/MobX+aWieVrC+hM m/S794aiOIhDJ9xbw889blQYOTyrZsHqcwF1bxLoGnNZz/c+FHLT6vQNkyupaNDVV5ru ymSSsVMHcHlthhlA/IZJgvGaeqlzbNosmjQVxOTvVPvLFXW6isLZ3hJJNxro9Sy5B/CZ wkVqcaa4yLKukyM25E5C30BjkzgGBLWsV/C37dNDPlwlKtQLNy97i3KcWwFKbL71Ca8Z xmuDx2SNl+IoBh/P2mqO3WKzNKiqJn3wFjQgnlhUgNFbdTJXhQiMaEo1UtD+0Vhe3LeS tssw== Received: by 10.66.9.2 with SMTP id v2mr20660567paa.65.1345949170867; Sat, 25 Aug 2012 19:46:10 -0700 (PDT) Received: from ulysses (cm162.gamma80.maxonline.com.sg. [202.156.80.162]) by mx.google.com with ESMTPS id po4sm8553892pbb.13.2012.08.25.19.46.08 (version=SSLv3 cipher=OTHER); Sat, 25 Aug 2012 19:46:10 -0700 (PDT) From: Chong Yidong To: control@debbugs.gnu.org Subject: close 12259 Date: Sun, 26 Aug 2012 10:46:06 +0800 Message-ID: <87wr0m9xqp.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) close 12259 thanks