From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: automate Emacs beautifyer ? Date: Thu, 26 Aug 2004 09:26:02 -0600 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <412E010A.4090005@yahoo.com> References: <412B6422.1040601@yahoo.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1093534253 20970 80.91.224.253 (26 Aug 2004 15:30:53 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 26 Aug 2004 15:30:53 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Aug 26 17:30:29 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1C0MCq-0001bR-00 for ; Thu, 26 Aug 2004 17:30:28 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C0MHT-0005UX-9T for geh-help-gnu-emacs@m.gmane.org; Thu, 26 Aug 2004 11:35:15 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!proxad.net!newsfeed.stueberl.de!fu-berlin.de!uni-berlin.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 88 Original-X-Trace: news.uni-berlin.de VTxJtVxx3CdakZiIqImQZgYvpzkFcBZ664dQjT2bL6kO6bUEA= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2 X-Accept-Language: en-us Original-Xref: shelby.stanford.edu gnu.emacs.help:124949 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:20299 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:20299 Michael Slass wrote: > Kevin Rodgers writes: >>for file in *.vhdl; do >> # Long options for readability: >> emacs --batch --visit=$file \ >> --funcall=vhdl-beautify-buffer --funcall=save-buffer >> # Short options for brevity: >> # emacs -batch $file -f vhdl-beautify-buffer -f save-buffer >>done >> >>See the "Command Line Arguments" section of the Emacs manual, >>especially the "Initial Options" and "Action Arguments" subnodes. > > Doing this in emacs lisp has the advantage of starting emacs only > once, as opposed to once per file. Assuming you have a list of the > files you want to change, one file per line, each file with a full > path, this elisp will do what you want: After exchanging a couple messages with Michael, I came up with the idea of starting a single emacs server instance and using a client to process each file within the shell loop: emacs -f gnuserv-start & #emacs_pid=$! for file in *.vhdl; do gnuclient -batch $file -f vhdl-beautify-buffer -f save-buffer -f kill-buffer done gnuclient -f exit-emacs # || kill $emacs_pid gnuserv/gnuclient is available at http://meltin.net/hacks/emacs/ > (defun vhdl-batch-beautify (listfile-name) > "Invoke `vhdl-beautify-buffer' on a batch of files. > LISTFILE-NAME is a path to a file containing a list of vhdl-files to > be beautified, one filename per line. Each line should contain a full > path to the vhdl file." > (interactive "fEnter name of file list for vhdl-beautification: ") > (let ((file-list-buf (find-file listfile-name)) > (file-list '())) > (save-excursion > (set-buffer file-list-buf) > (beginning-of-buffer) > (while (not (eobp)) > (add-to-list > 'file-list > (buffer-substring (point) > (progn (end-of-line) (point)))) > (unless (eobp) (forward-char 1))) > (kill-buffer file-list-buf) I also think there are more natural Emacs interfaces than LISTFILE-NAME: (defun batch-vhdl-beautify () ; see batch-byte-compile "Invoke `vhdl-beautify-buffer' on the files remaining on the command line. Use this from the command line, with `-batch'; it won't work in an interactive Emacs. Each file is processed even if an error occurred previously. For example, invoke \"emacs -batch -f batch-vhdl-beautify ~/vhdl *.vhdl\"." (if (not noninteractive) (error "`batch-vhdl-beautify' is to be used only with -batch")) ...) (defun vhdl-beautify-files (&rest file-names) "Visit each file in FILE-NAMES and invoke `vhdl-beautify-buffer'." (interactive (file-expand-wildcards (read-file-name "Beautify files: " nil nil nil "*.vhdl"))) ...) > ;;; probably neater to use a cl loop construct here, > ;; but I've never learned how > (while file-list > (find-file (car file-list)) > (vhdl-mode) And since we're so concerned with performance here, we should avoid re-initializing the buffer's major mode unless we have to: (or (eq major-mode 'vhdl-mode) (vhdl-mode)) > (vhdl-beautify-buffer) > (save-buffer) > (kill-buffer (current-buffer)) > (setq file-list (cdr file-list)))))) -- Kevin Rodgers