From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: automate Emacs beautifyer ?
Date: Thu, 26 Aug 2004 09:26:02 -0600 [thread overview]
Message-ID: <412E010A.4090005@yahoo.com> (raw)
In-Reply-To: m34qmsjqnm.fsf@eric.rossnet.com
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
next prev parent reply other threads:[~2004-08-26 15:26 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-24 7:53 automate Emacs beautifyer ? Bert Cuzeau
2004-08-24 8:22 ` Joost Kremers
2004-08-24 10:15 ` Miguel Frasson
2004-08-25 8:31 ` Oliver Scholz
2004-08-25 8:48 ` Miguel Frasson
2004-08-25 15:58 ` Kevin Rodgers
2004-08-29 9:48 ` Oliver Scholz
2004-09-02 2:10 ` date discrepancies Sebastian Luque
[not found] ` <mailman.1182.1094095164.1998.help-gnu-emacs@gnu.org>
2004-09-02 7:04 ` Pascal Bourguignon
2004-09-02 14:42 ` Sebastian Luque
2004-09-02 16:17 ` Sebastian Luque
2004-09-02 19:29 ` Stefan Monnier
2014-08-13 14:26 ` thymythos
2004-08-25 16:03 ` automate Emacs beautifyer ? David Kastrup
2004-08-25 20:30 ` LEE Sau Dan
2004-08-24 15:52 ` Kevin Rodgers
2004-08-24 19:13 ` Michael Slass
2004-08-24 23:27 ` Kevin Rodgers
2004-08-25 0:15 ` Michael Slass
2004-08-25 16:12 ` Kevin Rodgers
2004-08-26 15:26 ` Kevin Rodgers [this message]
2004-08-28 10:58 ` Kai Grossjohann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=412E010A.4090005@yahoo.com \
--to=ihs_4664@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.