Skip to content

Commit fc90ee7

Browse files
committed
Fixes #63: Add trailing whitespace cleanup
1 parent 146fc32 commit fc90ee7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ In addition to *minimal-emacs.d*, startup speed is influenced by your computer's
5151
- [How to enable the menu-bar, the tool-bar, dialogs, the contextual menu, and tooltips?](#how-to-enable-the-menu-bar-the-tool-bar-dialogs-the-contextual-menu-and-tooltips)
5252
- [Customizations: Packages (post-init.el)](#customizations-packages-post-initel)
5353
- [Optimization: Native Compilation](#optimization-native-compilation)
54+
- [Automatic removal of trailing whitespace on save](#automatic-removal-of-trailing-whitespace-on-save)
5455
- [How to activate recentf, savehist, saveplace, and auto-revert?](#how-to-activate-recentf-savehist-saveplace-and-auto-revert)
5556
- [Activating autosave](#activating-autosave)
5657
- [auto-save-mode (Prevent data loss in case of crashes)](#auto-save-mode-prevent-data-loss-in-case-of-crashes)
@@ -226,6 +227,38 @@ Native compilation enhances Emacs performance by converting Elisp code into nati
226227
(compile-angel-on-load-mode))
227228
```
228229

230+
### Automatic removal of trailing whitespace on save
231+
232+
**Trailing whitespace** refers to any spaces or tabs that appear after the last non-whitespace character on a line. These characters have no semantic value and can lead to unnecessary diffs in version control, inconsistent formatting, or visual clutter. Removing them improves code clarity and consistency.
233+
234+
The **stripspace** Emacs package provides `stripspace-local-mode`, a minor mode that automatically removes trailing whitespace and blank lines at the end of the buffer when saving.
235+
236+
To enable **stripspace** and automatically delete trailing whitespace, add the following configuration to `~/.emacs.d/post-init.el`:
237+
```elisp
238+
(use-package stripspace
239+
:ensure t
240+
241+
;; Enable for prog-mode-hook, text-mode-hook, conf-mode-hook
242+
:hook ((prog-mode . stripspace-local-mode)
243+
(text-mode . stripspace-local-mode)
244+
(conf-mode . stripspace-local-mode))
245+
246+
:custom
247+
;; The `stripspace-only-if-initially-clean' option:
248+
;; - nil to always delete trailing whitespace.
249+
;; - Non-nil to only delete whitespace when the buffer is clean initially.
250+
;; (The initial cleanliness check is performed when `stripspace-local-mode'
251+
;; is enabled.)
252+
(stripspace-only-if-initially-clean nil)
253+
254+
;; Enabling `stripspace-restore-column' preserves the cursor's column position
255+
;; even after stripping spaces. This is useful in scenarios where you add
256+
;; extra spaces and then save the file. Although the spaces are removed in the
257+
;; saved file, the cursor remains in the same position, ensuring a consistent
258+
;; editing experience without affecting cursor placement.
259+
(stripspace-restore-column t))
260+
```
261+
229262
### How to activate recentf, savehist, saveplace, and auto-revert?
230263

231264
The recentf, savehist, saveplace, and auto-revert built-in packages are already configured by *minimal-emacs.d*. All you need to do is activate them by adding the following to `~/.emacs.d/post-init.el`:

0 commit comments

Comments
 (0)