[PATCH 3/3] RFC: batch-tools.el
Tomi Ollila
tomi.ollila at iki.fi
Mon Jan 16 01:04:16 PST 2012
---
emacs -q -batch -l ../contrib/batch-tools.el -f batch-whitespace-cleanup \
with-indent *.el
was used to produce previous patch
emacs/batch-tools.el | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
create mode 100644 emacs/batch-tools.el
diff --git a/emacs/batch-tools.el b/emacs/batch-tools.el
new file mode 100644
index 0000000..e83f825
--- /dev/null
+++ b/contrib/batch-tools.el
@@ -0,0 +1,37 @@
+;;
+;; Use this code to clean whitespace in (and optionally reindent) files
+;;
+;; Usage: emacs -q -batch -l batch-tools.el \
+;; -f batch-whitespace-cleanup [with-indent] files...
+
+;; Borrows code fron batch-byte-compile. License: GPL3+
+
+(defun batch-whitespace-cleanup ()
+ "Run 'whitespace-cleanup' on the files remaining on the command line.
+If first arg is 'with-indent' do indent-region over the whole file too.
+Use this from the command line, with `-batch';
+it won't work in an interactive Emacs."
+ ;; command-line-args-left is what is left of the command line (from startup.el)
+ ;; (defvar command-line-args-left) ;Avoid 'free variable' warning
+ (if (not noninteractive)
+ (error "'batch-whitespace-cleanup' is to be used only with -batch"))
+ (let (filename do-indent)
+ (if (string= (car command-line-args-left) "with-indent")
+ (setq do-indent t
+ command-line-args-left (cdr command-line-args-left)))
+ (while command-line-args-left
+ (setq filename (expand-file-name (car command-line-args-left))
+ command-line-args-left (cdr command-line-args-left))
+ (if (file-directory-p filename)
+ ;; Directory as argument.
+ (message (concat "Skipping directory '" filename "'"))
+ ;; Specific file argument
+ (if (file-exists-p filename)
+ (with-temp-buffer
+ (message (concat "Loading file " filename "..."))
+ (find-file filename)
+ (whitespace-cleanup)
+ (if do-indent
+ (indent-region (point-min) (point-max)))
+ (save-buffer))
+ (message (concat "Skipping nonexisteng file '" filename "'")))))))
--
1.7.6.4
More information about the notmuch
mailing list