From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Anselm Helbig Newsgroups: gmane.emacs.help Subject: Re: Macros in dired - Is it possible? Date: Sat, 18 Jul 2009 23:08:42 +0200 Organization: Freie Universitaet Berlin Message-ID: <87tz19aecl.wl%anselm.helbig+news2009@googlemail.com> References: NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1247953300 28643 80.91.229.12 (18 Jul 2009 21:41:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 18 Jul 2009 21:41:40 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jul 18 23:41:33 2009 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 1MSHeu-0005ll-TM for geh-help-gnu-emacs@m.gmane.org; Sat, 18 Jul 2009 23:41:33 +0200 Original-Received: from localhost ([127.0.0.1]:34784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MSHeu-00046H-0u for geh-help-gnu-emacs@m.gmane.org; Sat, 18 Jul 2009 17:41:32 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 72 Original-X-Trace: news.uni-berlin.de DAxsvJKUruCpLxzK3K0GIAidzn9AzIXuO8sGgxtOpVcarcFBULaT+KH712 Cancel-Lock: sha1:80xG/OIfn2a9BpMxmJUeImFq6FA= In-Reply-To: Mail-Followup-To: anselm.helbig+news2009@googlemail.com Original-Xref: news.stanford.edu gnu.emacs.help:171026 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:66213 Archived-At: Hi! > [ *Question* ] > Is it possible to mark files in dired and then run a macro on all > the selected files? > > [ *Background* ] > The macro finds and deletes certain portions/paragraphs from text > files to cut them down in size so that I can read them easier and quicker. > > But I am getting tired of loading one file at a time into Emacs to > run the macro ( via ^u 0 MX macro1 ). I do this about 100x/day. So is there a > quicker/better way to run a macro en mass? > > [ *What I Have Tried, but Hasn't Worked* ] > As an example > 1. I load 10 text files into emacs, thus creating 10 separate > buffers. > 2. Then tried creating another macro that calls the first macro, > and also saves the edited and much smaller file, and then kills the buffer > 3.  So, for 10 files, I would call macro2 via [ ^u 10 Mx macro2 ] > 4. The problem, I am having is that the 2nd macro doesn't record > the save or the kill. So, I tried to edit the saved macro2 via [ > Mx edit-named-k TAB RET macro2 ]. I add the commands [ ^x ^s ] > and [ ^x k RET ], and do a [ c ^c ]. The changes are saved, but > when I try again, the 2nd macro calls macro1 to do its magic, but > the modifications aren't saved, nor is the buffer killed. So, > only one of the 10 files files has been modified. I didn't do any experiments myself, but I guess what happens is this: - You're executing your text-mangling macro in a buffer with a numeric prefix argument, a large number, larger than the number of times your macro actually needs to get called. - At the end of the buffer, your macro beeps (i.e., signals an error) and finishes. - When you record your second macro, the macro definition is aborted because your first macro beeps. This makes sense, sort of, since a beep signals an error. Therefore, the macro definition never comes to the point where you save and then kill your buffer - Even when you add these commands manually, they are never executed because the beep comes first. This is a bit unfortunate. I can't think of a solution that doesn't include some programming, replacing either one of the macros with a bit of elisp code. Replacing the outer macro could look like this (assuming that you named your keyboard macro `foo'): (defun dired-foo-marked-files () (interactive) (mapc (lambda (file) (find-file file) (goto-char (point-min)) (condition-case nil (dotimes (i 100) (execute-kbd-macro 'foo)) (error nil)) (save-buffer) (kill-buffer)) (dired-get-marked-files))) HTH, Anselm -- Anselm Helbig mailto:anselm.helbig+news2009@googlemail.com