Emacs (post v21) includes a function to delete trailing whitespace from a file. How would I make delete-trailing-whitespace
available in the Magit staging area (from magit-status
) so that I can remove trailing whitespace from individual hunks or entire files?
This is Sean's snippet, adjusted for Magit v2:
(defun my-magit-delete-trailing-whitespace-from-file ()
"Remove whitespace from the current file."
(interactive)
(save-excursion
(magit-diff-visit-file-worktree (magit-file-at-point))
(delete-trailing-whitespace)
(save-buffer)
(kill-buffer))
(magit-refresh))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With