🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.help
Article #189841

Re: Aborting a search nicely

#189841
From: Josh Mittleman
Date: Tue, 06 Nov 1990 16:04
31 lines
1814 bytes
roland@ai.mit.edu (Roland McGrath) suggests the following code as a
way to have certain actions taken when a search fails:

>   (if (re-search-forward "String" nil t)
>       ;; Search matched.
>       (...)
>      ;; Search failed.
>      ...)

This isn't quite how I'd do it, and there is another point to make.  

(if (re-search-forward "string" search-limit t)
   (do-this-on-match)
 (do-this-on-failure))

Search-limit is a point.  If you want the search to examine the entire
file, then search-limit should be (point-max). 

In this version, do-this-on-match will commence with the point at the
end of the match, but do-this-on-failure will commence with the point
where it was when the search began.  If you want do-this-on-failure to
commence at search-limit, then you would write:

(if (re-search-forward "string" search-limit 'AnythingOtherThanNilorT)
   (do-this-on-match)
 (do-this-on-failure))
-- 

------------------------------------------------------------------------------
Joshua Mittleman (mittle@ibm.com or joshua@paul.rutgers.edu)
J2-C28 T.J. Watson Research Institute, PO Box 704, Yorktown Heights, NY  10598
Technical Details
Message-ID: <Nov.6.11.04.35.1990.3289@yoko.rutgers.edu>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!shelby!apple!rutgers!aramis.rutgers.edu!paul.rutgers.edu!yoko.rutgers.edu!joshua
References: <815@inews.intel.com> <ROLAND.90Nov6014822@geech.ai.mit.edu>

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 08:04:36 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!shelby!apple!rutgers!aramis.rutgers.edu!paul.rutgers.edu!yoko.rutgers.edu!joshua
From: joshua@yoko.rutgers.edu (Josh Mittleman)
Newsgroups: gnu.emacs.help
Subject: Re: Aborting a search nicely
Message-ID: <Nov.6.11.04.35.1990.3289@yoko.rutgers.edu>
Date: 6 Nov 90 16:04:36 GMT
References: <815@inews.intel.com> <ROLAND.90Nov6014822@geech.ai.mit.edu>
Organization: Rutgers Univ., New Brunswick, N.J.
Lines: 31
Posted: Tue Nov  6 17:04:36 1990