Created
July 8, 2011 14:02
-
-
Save perusio/1071894 to your computer and use it in GitHub Desktop.
How to have your files always tidy: no trailing spaces, no tabs and properly indented on emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Clean up the current buffer: indent it, remove tabs and delete the | |
;;; trailing whitespace. | |
(defun tidy-up-buffer () | |
" Do a cleanup of the current buffer: tabs, spaces and indent | |
it." | |
(interactive) | |
(indent-buffer) | |
(delete-trailing-whitespace) | |
(untabify-buffer)) | |
;;; Do a general buffer cleanup before save. Markdown and text modes don't dig "blind" automatic indentation. | |
(add-hook 'before-save-hook #'(lambda() (unless (member major-mode '(fundamental-mode debian-changelog-mode debian-control-mode markdown-mode text-mode)) (tidy-up-buffer)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to enable on a local buffer basis do:
(add-hook 'php-mode-hook #'(lambda() (set (make-local-var'before-save-hook) #'tidy-up-buffer)))
Replace
php-mode-hook
with whichever mode you want this to tidying up to be active.