Skip to content

Instantly share code, notes, and snippets.

@magnars
Created July 4, 2012 17:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnars/3048595 to your computer and use it in GitHub Desktop.
Save magnars/3048595 to your computer and use it in GitHub Desktop.
cleanup-buffer.el
(defun cleanup-buffer-safe ()
"Perform a bunch of safe operations on the whitespace content of a buffer.
Does not indent buffer, because it is used for a before-save-hook, and that
might be bad."
(interactive)
(untabify-buffer)
(delete-trailing-whitespace)
(set-buffer-file-coding-system 'utf-8))
(defun cleanup-buffer ()
"Perform a bunch of operations on the whitespace content of a buffer.
Including indent-buffer, which should not be called automatically on save."
(interactive)
(cleanup-buffer-safe)
(indent-buffer))
(global-set-key (kbd "C-c n") 'cleanup-buffer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment