GNU bug report logs -
#78579
30.0.92; Global variant of delete-trailing-whitespace-mode
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
On Sat, May 24, 2025 at 11:15 AM Stefan Monnier via Bug reports for GNU
Emacs, the Swiss army knife of text editors <bug-gnu-emacs <at> gnu.org> wrote:
> > `delete-trailing-whitespace-mode` was introduced in commit 8a19c249f81.
> > Should there also be a `global-delete-trailing-whitespace-mode`?
> > This would allow
> > (global-delete-trailing-whitespace-mode 1)
> > and turning it off in an individual buffer with
> > (delete-trailing-whitespace-mode -1)
>
> To define such a mode, we'll need to know when to enable it and when
> not: I'd be surprised if adding `delete-trailing-whitespace` globally
> to `before-save-hook` doesn't cause problems in various circumstances.
>
> I don't have enough experience with that, so I'll let others decide if
> and how to do it.
>
FWIW, this is how I manage that and even then I might enable it for
markdown mode:
(defun my/before-save-hook ()
"Delete trailing white space before saving a buffer, except
`markdown-mode'."
(unless (derived-mode-p 'markdown-mode)
(delete-trailing-whitespace)))
(add-hook 'before-save-hook #'my/before-save-hook)
I suppose an exclusion mode list or some other conditionals could be baked
into the mode.
[Message part 2 (text/html, inline)]
This bug report was last modified 20 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.