[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: automate Emacs beautifyer ?
From: |
Michael Slass |
Subject: |
Re: automate Emacs beautifyer ? |
Date: |
Tue, 24 Aug 2004 12:13:17 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Kevin Rodgers <ihs_4664@yahoo.com> 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
Re: automate Emacs beautifyer ?, Kevin Rodgers, 2004/08/24
- Re: automate Emacs beautifyer ?,
Michael Slass <=
Re: automate Emacs beautifyer ?, Kevin Rodgers, 2004/08/26
Re: automate Emacs beautifyer ?, Kai Grossjohann, 2004/08/28