From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Pascal Bourguignon Newsgroups: gmane.emacs.help Subject: Re: need help with editing multiple files in a directory Date: Thu, 19 Jul 2007 18:24:43 +0200 Organization: Informatimago Message-ID: <871wf4icok.fsf@voyager.informatimago.com> References: <1184860347.592401.221020@22g2000hsm.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1184863299 6686 80.91.229.12 (19 Jul 2007 16:41:39 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 19 Jul 2007 16:41:39 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jul 19 18:41:38 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IBZ4F-0005Ef-BK for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Jul 2007 18:41:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IBZ4E-0005sA-Ed for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Jul 2007 12:41:30 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!newsserver.news.garr.it!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 54 Original-X-Trace: individual.net wIZeLMbWzJgjyLfFsuF42QV3yZwLF3YhcJDuuchQyRJrLPR3aI Cancel-Lock: sha1:ODfzym2lIJBtee7Nv7kt65IdryE= sha1:7MoFTH46l86gxg3Rwa0tc/DwTgs= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.94 (gnu/linux) Original-Xref: shelby.stanford.edu gnu.emacs.help:150230 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:45811 Archived-At: 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."