Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save vermiculus/8177389 to your computer and use it in GitHub Desktop.

Select an option

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))
@Xparx
Copy link
Copy Markdown

Xparx commented Sep 17, 2015

This code is obsolete with the latest version of magit. My fix was editing line 5 to:

(magit-diff-visit-file-worktree (magit-file-at-point))

@vermiculus
Copy link
Copy Markdown
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