Article View: gnu.emacs.help
Article #189837Re: Aborting a search nicely
From: Roland McGrath
Date: Tue, 06 Nov 1990 09:48
Date: Tue, 06 Nov 1990 09:48
41 lines
2294 bytes
2294 bytes
In article <815@inews.intel.com> jsweedle@mipos2.intel.com (Jonathan Sweedler) writes:
I asked this question a while ago, but I didn't get any response. I'm
going to give it one more try and if I still don't hear anything, then I'll
assume it isn't possible.
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.
C-h f re-search-forward RET
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.
So, maybe:
(if (re-search-forward "String" nil t)
;; Search matched.
(...)
;; Search failed.
...)
--
Roland McGrath
Free Software Foundation, Inc.
roland@ai.mit.edu, uunet!ai.mit.edu!roland
Technical Details
Message-ID:
<ROLAND.90Nov6014822@geech.ai.mit.edu>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!shelby!apple!olivea!mintaka!geech.ai.mit.edu!rolandReferences:
<815@inews.intel.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103b8b,6f8b507ca4d29177 X-Google-Attributes: gid103b8b,public X-Google-ArrivalTime: 1990-11-06 01:48:22 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!shelby!apple!olivea!mintaka!geech.ai.mit.edu!roland From: roland@ai.mit.edu (Roland McGrath) Newsgroups: gnu.emacs.help Subject: Re: Aborting a search nicely Message-ID: <ROLAND.90Nov6014822@geech.ai.mit.edu> Date: 6 Nov 90 09:48:22 GMT References: <815@inews.intel.com> Sender: daemon@mintaka.lcs.mit.edu (Lucifer Maleficius) Organization: Hackers Anonymous International, Ltd., Inc. (Applications welcome) Lines: 41 Posted: Tue Nov 6 10:48:22 1990 In-Reply-To: jsweedle@mipos2.intel.com's message of 5 Nov 90 23:52:46 GMT