unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Temporarily disable a write hook?
@ 2017-07-14 15:03 Skip Montanaro
  2017-07-14 15:11 ` Yuri Khan
  0 siblings, 1 reply; 5+ messages in thread
From: Skip Montanaro @ 2017-07-14 15:03 UTC (permalink / raw)
  To: Help GNU Emacs

I'm a Python programmer, so I often edit Python source. I don't want
trailing whitespace. That holds true for almost everything else I edit
(C, SQL, Bash, etc...). In fact, even if I'm editing text files (ReST,
Markdown, LaTeX, whatever), I want this behavior. Accordingly, I have
this in ~/.emacs:

(add-hook 'before-save-hook 'delete-trailing-whitespace)

Well, I got burned by this. I was editing a CSV file in which one cell
in the last column of a row ended with a space. It was, unfortunately,
a regular expression, so the space was significant.

Given that I *do* want to zap trailing whitespace on write *almost all
the time*, how best to solve this issue? Is there a way to
conditionally invoke the before-save-hook, or do I simply write my own
wrapper which stares at the file extension to decide whether to call
delete-trailing-whitespace? I was hoping that save-buffer didn't pay
attention to the numeric prefix, but that was too much to ask. It is
intimately concerned with the value of the numeric prefix. (I suppose
I could write my own wrapper for save-buffer which suppresses the
before-save-hook if the numeric prefix is negative, or something, but
I'd be opening myself up for a later behavioral change to Emacs.) Also
out-of-the-ordinary in this particular example, though the file was in
CSV format, I didn't give it a ".csv" extension for some reason, so I
couldn't just say, "ah, it ends in '.csv', avoid the call to
(delete-trailing-whitespace)." Oh, the tangled webs we weave...

Skip



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

end of thread, other threads:[~2017-07-14 17:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-14 15:03 Temporarily disable a write hook? Skip Montanaro
2017-07-14 15:11 ` Yuri Khan
2017-07-14 15:43   ` Skip Montanaro
2017-07-14 16:13     ` Lele Gaifax
2017-07-14 17:29       ` Skip Montanaro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).