Created
October 18, 2012 07:25
-
-
Save cdkamat/3910275 to your computer and use it in GitHub Desktop.
Emacs function to batch untabify and reindent
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
;;; File: emacs-format-file | |
;; http://www.cslab.pepperdine.edu/warford/BatchIndentationEmacs.html | |
;; to be run as -- | |
;; emacs -batch *.[ch] -l ~/src/scripts/emacs-format-file -f emacs-format-function | |
(defun emacs-format-function () | |
"Format the whole buffer." | |
(if (< 1 (count-windows)) | |
(delete-other-windows (selected-window))) | |
(catch 'tag | |
(while t | |
(c-mode) | |
(c-set-style "linux") | |
(setq indent-tabs-mode 'nil) | |
(setq c-basic-offset 4) | |
;; can add a save hook to delete trailing whitespaces | |
(untabify (point-min) (point-max)) | |
(indent-region (point-min) (point-max) nil) | |
(if buffer-file-name ; nil for *scratch* buffer | |
(progn | |
(write-file buffer-file-name) | |
(kill-buffer (current-buffer))) | |
(throw 'tag t))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment