home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / gnu / emacs / sources / 851 next >
Encoding:
Text File  |  1992-12-11  |  1.6 KB  |  39 lines

  1. Path: sparky!uunet!stanford.edu!agate!spool.mu.edu!sdd.hp.com!think.com!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!aun.uninett.no!nuug!ifi.uio.no!nntp.uio.no!hbf
  2. From: hbf@durin.uio.no (Hallvard B Furuseth)
  3. Newsgroups: gnu.emacs.sources
  4. Subject: Re: more functions needed (sorry)
  5. Message-ID: <HBF.92Dec11203729@durin.uio.no>
  6. Date: 11 Dec 92 19:37:29 GMT
  7. References: <SNOW.92Dec11075738@castor.hahnemann.edu>
  8.     <DODD.92Dec11074209@mycenae.cchem.berkeley.edu>
  9. Sender: news@ulrik.uio.no (Mr News)
  10. Organization: University of Oslo, Norway
  11. Lines: 24
  12. In-Reply-To: dodd@mycenae.cchem.berkeley.edu's message of 11 Dec 92 07:42:09
  13. Nntp-Posting-Host: durin.uio.no
  14.  
  15. In article <DODD.92Dec11074209@mycenae.cchem.berkeley.edu> dodd@mycenae.cchem.berkeley.edu (Lawrence R. Dodd) writes:
  16.  
  17. > `looking-back' is not standard but probably can be constructed using
  18. > `looking-at' although it seems interesting that it isn't in the standard
  19. > distribution.  Can anyone out there explain this?
  20.  
  21. Probably because our heroes do not want to encourage backwards regexp
  22. processing.  Emacs' regexp implementation works better forwards.  For
  23. example, notice that (re-search-backward "x+") only finds the last x in
  24. `xxx'.  Also, I suspect backwards is slower.
  25.  
  26.  
  27. Anyway, here is a quick and dirty version:
  28.  
  29. (defun looking-back (regexp &optional span)
  30.   "t if text before point matches regular expression PAT.
  31. For simplicity, only the preceding SPAN chars (default 2000) are searched."
  32.   (save-excursion
  33.     (eq (point)
  34.     (and (re-search-backward regexp (- (point) (or span 2000)) t)
  35.          (match-end 0)))))
  36. --
  37.  
  38. Hallvard
  39.