Skip to content

Instantly share code, notes, and snippets.

@calas
Created May 12, 2010 21:19
Show Gist options
  • Save calas/399138 to your computer and use it in GitHub Desktop.
Save calas/399138 to your computer and use it in GitHub Desktop.
;; http://blog.tuxicity.se/elisp/emacs/2010/05/07/clean-up-buffer-or-region-in-emacs.html
(defun clean-up-buffer-or-region ()
"Untabifies, indents and deletes trailing whitespace from buffer or region."
(interactive)
(save-excursion
(unless (region-active-p)
(mark-whole-buffer))
(untabify (region-beginning) (region-end))
(indent-region (region-beginning) (region-end))
(save-restriction
(narrow-to-region (region-beginning) (region-end))
(delete-trailing-whitespace))))
(global-set-key (kbd "C-c n") 'clean-up-buffer-or-region)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment