Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vermiculus/8177389 to your computer and use it in GitHub Desktop.
Save vermiculus/8177389 to your computer and use it in GitHub Desktop.
(defun *magit-delete-trailing-whitespace-from-file ()
"Removes whitespace from the current item."
(interactive)
(save-excursion
(magit-visit-item)
(delete-trailing-whitespace)
(save-buffer)
(kill-buffer))
(magit-refresh))
@vermiculus
Copy link
Author

Yes; Magit's maintainer provided his own version on my SO question:

(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 a reader is seeing this in the far future, I'd check the SO post for any possible updates for new Magit versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment