Two Productivity Packages by James Cherti (Chair-tea): bufferfile.el and stripspace.el
Where I got the Idea
Introduction
Today I'll show you two simple yet powerful Emacs packages that improve file management and code cleanness.
bufferfile.el
bufferfile is a package that lets you rename and delete files while automatically handling their associated buffers. This eliminates the common workflow issue where you need to:
Close a buffer
Rename a file
Reopen the file
Usage Demo
Let me show you how it works:
Open a file: C-x C-f some-file.txt
Rename it with M-x brf (or M-x bufferfile-rename)
Delete a file with M-x bdf (or M-x bufferfile-delete)
Configuration
;; Rename and delete buffer file names with their associated buffers (use-package bufferfile t ( "https://github.com/jamescherti/bufferfile.el" )) ;; Set this if you want version control integration (setq bufferfile-use-vc t) (defalias 'brf 'bufferfile-rename) (defalias 'bdf 'bufferfile-delete)
stripspace.el
stripspace automatically removes trailing whitespace before saving files. It works silently in the background to keep your files clean.
Key Features
Automatically removes trailing whitespace when saving
Preserves cursor position after whitespace removal
Works across programming, text, org, and configuration files
Can even be configured to only clean files that were initially clean, which helps to avoid accidentally "fixing" whitespace in files where you didn't intend to make such changes
Usage Demo
Open a file with some trailing whitespace
Add more trailing spaces
Save the file
Notice how the trailing whitespace is removed but the cursor position stays where you expect
Configuration
(use-package stripspace :ensure t :commands stripspace-local-mode ;; Enable for prog-mode-hook, text-mode-hook, prog-mode-hook :hook ((prog-mode . stripspace-local-mode) (text-mode . stripspace-local-mode) (org-mode . stripspace-local-mode) (conf-mode . stripspace-local-mode)) :custom ;; The `stripspace-only-if-initially-clean' option: ;; - nil to always delete trailing whitespace. ;; - Non-nil to only delete whitespace when the buffer is clean initially. ;; (The initial cleanliness check is performed when `stripspace-local-mode' ;; is enabled.) (stripspace-only-if-initially-clean nil) ;; Enabling `stripspace-restore-column' preserves the cursor's column position ;; even after stripping spaces. This is useful in scenarios where you add ;; extra spaces and then save the file. Although the spaces are removed in the ;; saved file, the cursor remains in the same position, ensuring a consistent ;; editing experience without affecting cursor placement. (stripspace-restore-column t) (stripspace-verbose t))
Conclusion
Both packages are available on MELPA and GitHub. They're lightweight, focused on doing one thing well, and integrate nicely into your existing workflow.
Try them out and let me know what you think in the comments!
Links
bufferfile.el: https://github.com/jamescherti/bufferfile.el
stripspace.el: https://melpa.org/#/stripspace