Using emacs reformat source files in batch

30 Nov 2008

In a previous post, I present some emacs functions for code reformatting. These are great for interactive work, but what if you need to do this to a whole source directory in bulk or done automatically once a night? Here's a small shell script that does just that.:

if [ -z "$1" ]; then
    echo  usage: $0 file-to-indent file2 file3 ...
    exit 1

for i in $@; do
    echo Loading $i
    emacs --batch --load ~/.emacs --file $i \
        --execute '(buffer-cleanup)' --execute '(save-buffer)'

Definitely not the most efficient system, but hopefully this doesn't need to be high performance.

Comment 2013-06-26 by None

emacs --batch $1 -l ./emacs -f buffer_cleanup -f save-buffer

works in latest emacs