emacsでファイルをインデントするスクリプト

emacsでサンプルとか他人からもらったファイルをいじって行くとき、ファイルのインデントの流儀がemacsと違うとTabを押したときに残念な気分になる。下のファイルに実行権限をつけてPATHの通ったところにおいてやると

$ emacs-format-file *.cc

とすることでインデントが揃う。

参考urlによればこの書き方(最初2行と最後1行)でmaclinuxwindowsのどれでも動くらしい。とりあえずmaclinuxでは動いている。

参考

emacs-format-file:

:;exec emacs -batch -l   "$0" -f : "$@" --no-site-file -q  # -*- Emacs-Lisp -*-
;     @emacs -batch -l "%~f0" -f :  %*  --no-site-file -q  & goto :EOF

; indent specified file(s) with emacs indent-region
; http://www.emacswiki.org/emacs/EmacsScripts
; http://www.cslab.pepperdine.edu/warford/BatchIndentationEmacs.html

(defun : ()
  (dolist (f (nthcdr 5 command-line-args))
    (find-file f)
    ;; (c-set-style "stroustrup")
    (indent-region (point-min) (point-max) nil)
    (untabify (point-min) (point-max))
    (save-buffer))
)
;:EOF