help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: need help with editing multiple files in a directory


From: Pascal Bourguignon
Subject: Re: need help with editing multiple files in a directory
Date: Thu, 19 Jul 2007 18:24:43 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.94 (gnu/linux)

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."


reply via email to

[Prev in Thread] Current Thread [Next in Thread]