From: Pascal Bourguignon <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: need help with editing multiple files in a directory
Date: Thu, 19 Jul 2007 18:24:43 +0200 [thread overview]
Message-ID: <871wf4icok.fsf@voyager.informatimago.com> (raw)
In-Reply-To: 1184860347.592401.221020@22g2000hsm.googlegroups.com
bittna@gmail.com writes:
> Hello,
> I have multiple files in a directory that need a line added at a
> certain point in the file. I wrote a lisp expression to do it, but I
> have to load the file, then run the command on the buffer, the save
> the file and I lose my place.
What do you mean by you lost your place?
> I used dired to do a find and replace
> on all of the files I needed, but how do I run my lisp expression on
> all of the files?
Doing it.
(defmacro run-lisp-expressions-on-files (files &body expressions)
`(dolist (file ,files)
(with-current-buffer (find-file file)
(unwind-protect (save-excursion ,@expressions)
(save-buffer)
(kill-buffer (current-buffer))))))
(run-lisp-expressions-on-files (list "file1" "file2" ...)
(goto-char (point-min))
(while (re-search-forward ...)
...))
> Also how do I loop through all the buffers using lisp and switch into
> each buffer and do something, then move to the next buffer?
Doing it! Well, you should define better what you want and what you
mean, of course, but assuming "using lisp" means having as major-mode
lisp-mode or emacs-lisp-mode:
(require 'cl)
(dolist (buffer (remove-if-not
(lambda (buffer)
(member (with-current-buffer buffer major-mode)
'(lisp-mode emacs-lisp-mode))) ; ...
buffer-list))
(with-current-buffer buffer
(do-something)))
--
__Pascal Bourguignon__ http://www.informatimago.com/
"Logiciels libres : nourris au code source sans farine animale."
next prev parent reply other threads:[~2007-07-19 16:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-19 15:52 need help with editing multiple files in a directory bittna
2007-07-19 16:24 ` Pascal Bourguignon [this message]
2007-07-19 20:55 ` Joel J. Adamson
2007-07-19 22:49 ` Colin S. Miller
2007-07-20 5:33 ` Mathias Dahl
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871wf4icok.fsf@voyager.informatimago.com \
--to=pjb@informatimago.com \
--cc=help-gnu-emacs@gnu.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).