Skip to content

Instantly share code, notes, and snippets.

@evanmcc
Created December 17, 2014 20:42
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 evanmcc/25e513b122c03f433e8c to your computer and use it in GitHub Desktop.
Save evanmcc/25e513b122c03f433e8c to your computer and use it in GitHub Desktop.
#!/usr/bin/env emacs --script
;; should likely be called with 2</dev/null to suppress the various
;; output to the shell.
;; I think that this is going to fail non-emacs24 installs, since
;; 'package isn't installed by default there. You'll see this error:
;; "Symbol's function definition is void: package-initialize"
;; `brew install emacs` should fix you up, though.
(package-initialize)
;; note of course that this will work for non-erlang files, it's just
;; that I care about erlang and it isn't installed by default. just
;; add your mode to the to the mode list if you need others
(let ((l '(erlang)))
(dolist (mode l)
(if (not (package-installed-p mode))
(package-install mode))))
(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))))
(dolist (file command-line-args-left)
(find-file file)
;; apparently emacs doesn't region-indent to a fixpoint, run this a
;; couple of times. *sigh*
(clean-up-buffer-or-region)
(clean-up-buffer-or-region)
(clean-up-buffer-or-region)
(save-buffer))
(kill-emacs 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment