emacsでファイルをインデントするスクリプト
emacsでサンプルとか他人からもらったファイルをいじって行くとき、ファイルのインデントの流儀がemacsと違うとTabを押したときに残念な気分になる。下のファイルに実行権限をつけてPATHの通ったところにおいてやると
$ emacs-format-file *.cc
とすることでインデントが揃う。
参考urlによればこの書き方(最初2行と最後1行)でmac、linux、windowsのどれでも動くらしい。とりあえずmacとlinuxでは動いている。
参考
- http://www.emacswiki.org/emacs/EmacsScripts#toc3
- http://www.cslab.pepperdine.edu/warford/BatchIndentationEmacs.html
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