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

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

Re: Stop a macro from terminating on beep


From: harven
Subject: Re: Stop a macro from terminating on beep
Date: Thu, 02 Apr 2009 11:28:45 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin)

kazza765 <lowe.john@gmail.com> writes:

> Hi
>
> So, basically I'm trying to do what the title suggests. I have a macro that
> searches through a file, finds an instance of the text I'm looking for, and
> deletes the next three lines. I then have another macro that runs
> \C-u10000000\C-[xname-of-macro \C-x\C-s\C-x\C-c , so I want it to exit after
> tha macro is finished. This works fine in macros that don't cause a beep,
> and I can run them using emacs -f name-of-macro, but the system beep that
> occurs when this macro can't find any more matching patterns causes the
> macro to abort, and doesn't execute the save and quit commands. Is there any
> way around this? Or is there any better way to execute a search macro an
> unknown number of times and still have emacs exit afterwards?

I think you want condition-case.
The following command executes the current macro as many time as possible,
but goes to the end of buffer instead of beeping and aborting on the final 
error. Replace end-of-buffer by save-buffers-kill-emacs if you want to quit 
emacs instead of going to the end of the buffer.

(defun exec-macro-without-error ()
"exec current macro repeatedly until an error is encountered,
 but don't beep and report error. Instead go to the end of buffer."
 (interactive)
 (condition-case nil
    (kmacro-end-or-call-macro 0)
   (error (end-of-buffer))))

See  Handling Errors  in the elisp manual for details.



reply via email to

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