all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: 12259@debbugs.gnu.org
Cc: Mathieu Boespflug <mboes@tweag.net>
Subject: bug#12259: [Mathieu Boespflug] Add delete-trailing-whitespace to list of safe eval forms
Date: Wed, 22 Aug 2012 09:18:40 -0400	[thread overview]
Message-ID: <jwvr4qzxdzz.fsf-monnier+emacs@gnu.org> (raw)

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

Mistakenly sent to emacs-devel.


[-- Attachment #2: Type: message/rfc822, Size: 6729 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 1976 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.1.2: 0001-files.el-say-adding-delete-trailing-whitespace-to-ho.patch --]
[-- Type: text/x-patch, Size: 1135 bytes --]

>From 5f71b0dc3bc3b09cfb58d26ca6643b4e4a013a31 Mon Sep 17 00:00:00 2001
From: Mathieu Boespflug <mboes@cs.mcgill.ca>
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


         reply	other threads:[~2012-08-22 13:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-20 18:35 Add delete-trailing-whitespace to list of safe eval forms Mathieu Boespflug
2012-08-22 13:18 ` Stefan Monnier [this message]
2012-08-22 14:36   ` bug#12259: " Stefan Monnier
2012-08-22 16:24     ` Glenn Morris
2012-08-23 11:51       ` Stefan Monnier
2012-08-22 16:27     ` Mathieu Boespflug
2012-08-23 12:19       ` Stefan Monnier
2012-08-23 13:00         ` Mathieu Boespflug

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvr4qzxdzz.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=12259@debbugs.gnu.org \
    --cc=mboes@tweag.net \
    /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 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.