Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id A060A429E28 for ; Mon, 16 Jan 2012 01:04:24 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ACkJCM+XXJaK for ; Mon, 16 Jan 2012 01:04:23 -0800 (PST) Received: from guru.guru-group.fi (guru-group.fi [87.108.86.66]) by olra.theworths.org (Postfix) with ESMTP id 7A2A8429E26 for ; Mon, 16 Jan 2012 01:04:23 -0800 (PST) Received: by guru.guru-group.fi (Postfix, from userid 501) id 8A7FD68057; Mon, 16 Jan 2012 11:04:27 +0200 (EET) From: Tomi Ollila To: Subject: [PATCH 3/3] RFC: batch-tools.el Date: Mon, 16 Jan 2012 11:04:16 +0200 Message-Id: <1326704656-26102-3-git-send-email-tomi.ollila@iki.fi> X-Mailer: git-send-email 1.7.6.1 In-Reply-To: <1326704656-26102-1-git-send-email-tomi.ollila@iki.fi> References: <1326704656-26102-1-git-send-email-tomi.ollila@iki.fi> Cc: Tomi Ollila X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Jan 2012 09:04:24 -0000 --- 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