Xref: utzoo gnu.emacs.help:264 comp.emacs:9460 Path: utzoo!utgpu!watserv1!watmath!uunet!shelby!apple!usc!cs.utexas.edu!tut.cis.ohio-state.edu!coyote.draper.com!mal From: mal@coyote.draper.com (Mark Lamourine) Newsgroups: gnu.emacs.help,comp.emacs Subject: Aborting a search nicely Message-ID: <9011081526.AA01876@coyote.draper.com> Date: 8 Nov 90 15:26:51 GMT References: <815@inews.intel.com> Sender: daemon@tut.cis.ohio-state.edu Followup-To: gnu.emacs.help Organization: GNUs Not Usenet Lines: 36 Jonathan Sweedler writes: >I have the following psuedo-code: > (re-search-forward "String") > (some-commands-follow) > If "String" does not exist in my buffer then the search-forward command > bombs out. There must be a way to stop the search-forward from bombing > out and to do something if the string is not found. For instance, if > the string is found I want to execute certain commands and if it is > not found then I want to do something else. The following text was obtained by using f re-search-forward (that is: help function re-search-forward) re-search-forward: Search forward from point for regular expression REGEXP. Set point to the end of the occurrence found, and return t. An optional second argument bounds the search; it is a buffer position. The match found must not extend after that position. > 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. See also the functions match-beginning and match-end and replace-match. Therefore, what you want is something like (if (re-search-forward "String" (point-max) t) (some-commands-follow)) ------------------------------------------------------------------------------- Mark Lamourine internet: lamourine@draper.com "It's not my fault!", Han Solo -------------------------------------------------------------------------------