From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Michael Slass Newsgroups: gmane.emacs.help Subject: Re: automate Emacs beautifyer ? Date: Tue, 24 Aug 2004 12:13:17 -0700 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <412B6422.1040601@yahoo.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1093374946 17634 80.91.224.253 (24 Aug 2004 19:15:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 24 Aug 2004 19:15:46 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Aug 24 21:15:38 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 1Bzgld-0006D2-00 for ; Tue, 24 Aug 2004 21:15:37 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bzgq9-0005hj-92 for geh-help-gnu-emacs@m.gmane.org; Tue, 24 Aug 2004 15:20:17 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail Original-NNTP-Posting-Date: Tue, 24 Aug 2004 14:13:18 -0500 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:KSEutVlMPSZHL5f4YRodmagkVxE= Original-Lines: 67 Original-NNTP-Posting-Host: 24.18.253.35 Original-X-Trace: sv3-A1Y41KjNFOF2SnoPHYRBEwaS+RXZMz4V8ojoEg5TiKkdD6H0SKr08tN0Z/UfEujAfq5aqw1KlFIaKpK!2+0Tnx8OxP6J2iQtVPy+g/J3wGNXpQR3GXN/Kmyp2OzTeC0nndDT49k1 Original-X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.13 Original-Xref: shelby.stanford.edu gnu.emacs.help:124912 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:20261 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:20261 Kevin Rodgers writes: >Bert Cuzeau wrote: > > Under Windows (or Unix), is there a way to automate Emacs doing > > only : > > - open file > > - VHDL - beautify - Buffer (C-c C-b) > > - save file > > - exit > > > > We have hundreds of files to "beautify" with VHDL-mode and it is a > > chore doing this by hand. > > > > Ideally, emacs with command line parameters would suit me great... > >Of course: > >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: (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) ;;; 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) (vhdl-beautify-buffer) (save-buffer) (kill-buffer (current-buffer)) (setq file-list (cdr file-list)))))) -- Mike Slass