Sunday, November 30, 2008

Using emacs reformat source files in batch

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.:

#!/bin/bash
# PUBLIC DOMAIN
if [ -z "$1" ]; then
    echo  usage: $0 file-to-indent file2 file3 ...
    exit 1
fi

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

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

0 comments: