Skip to content

Instantly share code, notes, and snippets.

@vladdu
Last active August 29, 2015 13:56
Show Gist options
  • Save vladdu/8841089 to your computer and use it in GitHub Desktop.
Save vladdu/8841089 to your computer and use it in GitHub Desktop.
Scripts to indent Erlang files from the command line
;;; File: emacs-indent-erlang
;;; adapted from http://www.cslab.pepperdine.edu/warford/BatchIndentationEmacs.html
;; this has to be set to the real path on your system
(add-to-list 'load-path "~/.emacs.d/elpa/erlang-20131025.6")
(load-library "erlang")
;; comment out the call to untabify if you want the mixed tabs and spaces
(defun emacs-indent-function ()
"Format the whole buffer."
(erlang-mode)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max))
(delete-trailing-whitespace)
(save-buffer)
)
#!/bin/sh
# File: erl-indent
# Opens a set of files in emacs and executes the emacs-indent-function.
# Assumes the function named emacs-indent-function is defined in the
# file named emacs-indent-file.
#
# adapted from http://www.cslab.pepperdine.edu/warford/BatchIndentationEmacs.html
if [ $# -eq 0 ]
then
echo "erl-indent requires at least one argument." 1>&2
echo "Usage: erl-indent files-to-indent" 1>&2
exit 1
fi
while [ $# -ge 1 ]
do
if [ -d $1 ]
then
echo "Argument of erl-indent $1 cannot be a directory." 1>&2
exit 1
fi
# Check for existence of file:
ls $1 2> /dev/null | grep $1 > /dev/null
if [ $? != 0 ]
then
echo "erl-indent: $1 not found." 1>&2
exit 1
fi
echo "Indenting $1 with emacs in batch mode..."
emacs -batch $1 -l ~/bin/emacs-indent-erlang -f emacs-indent-function
echo
shift 1
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment