[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: automate Emacs beautifyer ?
From: |
Kevin Rodgers |
Subject: |
Re: automate Emacs beautifyer ? |
Date: |
Thu, 26 Aug 2004 09:26:02 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2 |
Michael Slass wrote:
> Kevin Rodgers <ihs_4664@yahoo.com> 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
Re: automate Emacs beautifyer ?, Kevin Rodgers, 2004/08/24
Re: automate Emacs beautifyer ?,
Kevin Rodgers <=
Re: automate Emacs beautifyer ?, Kai Grossjohann, 2004/08/28