Unobtrusively trim extraneous white-space *ONLY* in lines edited.
Emacs Lisp
282
70 commits
updated Jun 13, 2025
"Unobtrusive" is doing double duty here.
ws-butler is keeping frivolous whitespace at bay in the background.
show-trailing-whitespace, seeing whitespace is
wasted mental energy.By default, ws-butler preserves "virtual spaces" in front of point if necessary. The file on disk is cleaned up however.
This can be disabled with ws-butler-keep-whitespace-before-point.
There might be lines you don't want to get trimmed, e.g. spaces in multi-line
strings. The behavior can be customized through ws-butler-trim-predicate. This
variable should hold a function that expects 2 arguments (region beginning and
end) and should return true only for regions that one wants to get trimmed. As
an example
(setq ws-butler-trim-predicate
(lambda (beg end)
(not (eq 'font-lock-string-face
(get-text-property end 'face)))))
use-package configuration(use-package ws-butler :ensure t :hook (prog-mode . ws-butler-mode))
To use ws-butler, require it and add ws-butler-mode as a hook on any mode where you would like it to be enabled. For example, to enable for all programming language modes, add this to your .emacs:
(require 'ws-butler)
(add-hook 'prog-mode-hook #'ws-butler-mode)
Alternatively, you can use ws-butler-global-mode to turn it on everywhere.
apt-get install elpa-ws-butler
I started by trimming all spaces at EOL in source code in a "write-file-hook" when I started programming. It seemed like a great idea.
Then I got a job working on a code base where no one else trimmed spaces, so my commits became super noisy. I wanted to stop being the "white space" police, so switched to ws-trim.
post-command-hook and trims white space while you
edit.post-command-hook.I started experimenting with using highlight-changes-mode to trim only
lines I touch on save.
Now, the dependency on highlight-changes-mode has been removed and we
handle change changing through text properties ourselves.
Emacs Lisp
96.0%
Makefile
4.0%
Unobtrusively trim extraneous white-space *ONLY* in lines edited.
Emacs Lisp
282
70 commits
updated Jun 13, 2025
"Unobtrusive" is doing double duty here.
ws-butler is keeping frivolous whitespace at bay in the background.
show-trailing-whitespace, seeing whitespace is
wasted mental energy.By default, ws-butler preserves "virtual spaces" in front of point if necessary. The file on disk is cleaned up however.
This can be disabled with ws-butler-keep-whitespace-before-point.
There might be lines you don't want to get trimmed, e.g. spaces in multi-line
strings. The behavior can be customized through ws-butler-trim-predicate. This
variable should hold a function that expects 2 arguments (region beginning and
end) and should return true only for regions that one wants to get trimmed. As
an example
(setq ws-butler-trim-predicate
(lambda (beg end)
(not (eq 'font-lock-string-face
(get-text-property end 'face)))))
use-package configuration(use-package ws-butler :ensure t :hook (prog-mode . ws-butler-mode))
To use ws-butler, require it and add ws-butler-mode as a hook on any mode where you would like it to be enabled. For example, to enable for all programming language modes, add this to your .emacs:
(require 'ws-butler)
(add-hook 'prog-mode-hook #'ws-butler-mode)
Alternatively, you can use ws-butler-global-mode to turn it on everywhere.
apt-get install elpa-ws-butler
I started by trimming all spaces at EOL in source code in a "write-file-hook" when I started programming. It seemed like a great idea.
Then I got a job working on a code base where no one else trimmed spaces, so my commits became super noisy. I wanted to stop being the "white space" police, so switched to ws-trim.
post-command-hook and trims white space while you
edit.post-command-hook.I started experimenting with using highlight-changes-mode to trim only
lines I touch on save.
Now, the dependency on highlight-changes-mode has been removed and we
handle change changing through text properties ourselves.
Emacs Lisp
96.0%
Makefile
4.0%