emacs-ess/ESS — pull request #12 by haxney (2012-04-26 01:17:13+00:00)
Title: Reindent elisp

Now that whitespace style and line-ending conventions are established, reindent
all elisp files accordingly.

This is accomplished by the following code

(require 'cl)

(defun recursive-files (dir func)
(loop with before-save-hook
for (file is-dir)
in (directory-files-and-attributes dir t "^[^.]")
if is-dir
do (recursive-files file func)
else
if (string-match ".*\.el$" file)
do (with-current-buffer (find-file-noselect file)
(funcall func)
(basic-save-buffer)
(kill-buffer))))

(recursive-files "/path/to/ess" #'(lambda ()
(whitespace-cleanup)
(indent-region (point-min) (point-max))))

This will walk through all elisp files under "/path/to/ess" and clean up
whitespace and re-indent the file. The `whitespace-cleanup' in the `lambda' is
necessary because `indent-region' will not replace tabs with spaces if a line is
already indented to the correct column using tabs. Running `whitespace-cleanup'
first ensures that the file is indented strictly with spaces.

A stricter version of this would be:

(recursive-files "~/work/ESS" #'(lambda ()
(while (re-search-forward "\t" nil t)
(replace-match " "))
(indent-region (point-min) (point-max))))

Which would remove all tab characters from all elisp files. This patch only runs
`whitespace-cleanup' to remove leading tabs.