all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Stop a macro from terminating on beep
@ 2009-04-01 22:51 kazza765
  0 siblings, 0 replies; 3+ messages in thread
From: kazza765 @ 2009-04-01 22:51 UTC (permalink / raw)
  To: Help-gnu-emacs


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?

Thankyou,
John
-- 
View this message in context: http://www.nabble.com/Stop-a-macro-from-terminating-on-beep-tp22834993p22834993.html
Sent from the Emacs - Help mailing list archive at Nabble.com.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Stop a macro from terminating on beep
       [not found] <mailman.4426.1238645012.31690.help-gnu-emacs@gnu.org>
@ 2009-04-02  6:43 ` Evans Winner
  2009-04-02  9:28 ` harven
  1 sibling, 0 replies; 3+ messages in thread
From: Evans Winner @ 2009-04-02  6:43 UTC (permalink / raw)
  To: help-gnu-emacs

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

    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?

This may not be helpful, because I am not sure I understand
what you are asking.  When you say ``macro'' I think you are
talking about an interactive search-and-replace text
function of some kind.  Is this a function you are writing?
If so, it might be helpful to note that some of the search
functions take arguments like a limit, or what to do on
error.  For instance:

,----[ C-h f search-forward RET ]
| search-forward is an interactive built-in function in `C source code'.
| 
| It is bound to <find>.
| 
| (search-forward STRING &optional BOUND NOERROR COUNT)
| 
| Search forward from point for STRING.
| Set point to the end of the occurrence found, and return point.
| An optional second argument bounds the search; it is a buffer position.
| The match found must not extend after that position.  A value of nil is
|   equivalent to (point-max).
| Optional third argument, if t, means if fail just return nil (no error).
|   If not nil and not t, move to limit of search and return nil.
| Optional fourth argument is repeat count--search for successive occurrences.
| 
| Search case-sensitivity is determined by the value of the variable
| `case-fold-search', which see.
| 
| See also the functions `match-beginning', `match-end' and `replace-match'.
`----

So something like--

,----
| (search-forward "nonexistent string" (point-max) t)
`----

--won't signal a "beep," as I understand it.  

Anyway if you're using lisp, you might post your code; as
for keyboard macros, I don't know much about them, if that's
what you're using, but someone might.  You could post more
specific details.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Stop a macro from terminating on beep
       [not found] <mailman.4426.1238645012.31690.help-gnu-emacs@gnu.org>
  2009-04-02  6:43 ` Stop a macro from terminating on beep Evans Winner
@ 2009-04-02  9:28 ` harven
  1 sibling, 0 replies; 3+ messages in thread
From: harven @ 2009-04-02  9:28 UTC (permalink / raw)
  To: help-gnu-emacs

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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-04-02  9:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.4426.1238645012.31690.help-gnu-emacs@gnu.org>
2009-04-02  6:43 ` Stop a macro from terminating on beep Evans Winner
2009-04-02  9:28 ` harven
2009-04-01 22:51 kazza765

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.