home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / emacs / help / 4818 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.7 KB  |  49 lines

  1. Newsgroups: gnu.emacs.help
  2. Path: sparky!uunet!stanford.edu!CSD-NewsHost.Stanford.EDU!times!wmesard
  3. From: wmesard@cs.stanford.edu (Wayne Mesard)
  4. Subject: Re: Locate long lines
  5. In-Reply-To: k202047@galilei.DKRZ-Hamburg.DE's message of Mon, 16 Nov 92 14:24:02 GMT
  6. Message-ID: <WMESARD.92Nov16125319@Waimea.Stanford.EDU>
  7. Sender: news@CSD-NewsHost.Stanford.EDU
  8. Organization: Distributed Systems Group, Stanford University
  9. References: <1992Nov16.142402.29422@news.DKRZ-Hamburg.DE>
  10. Date: 16 Nov 92 12:53:19
  11. Lines: 36
  12.  
  13. k202047@galilei.DKRZ-Hamburg.DE (H.Thiemann) writes:
  14. > How do I locate a line longer than n Characters?
  15.  
  16. Hmmm, I thought Emacs' regular expressions had a {m,n} directive like
  17. SunOS' grep(1).  Guess not.  That would have made the following solution
  18. a bit less ugly.  But it does what you want.
  19.  
  20. The basic idea is to build a regular expression that says "a line N
  21. characters or more" and then use it to search.  All the other junk I
  22. threw in there is just to make it look intimidating :-)
  23.  
  24. -=-=-=-=-=-=-=-=-=-=-=-=-
  25.  
  26.   (defun length-search-forward (len)
  27.     "Search forward for a line of LEN characters.  LEN is prompted for unless
  28.   a prefix argument was specified, in which case that is used.  If it is
  29.   negative, then the line must be exactly -LEN characters long.  Otherwise,
  30.   any line LEN or more characters matches."
  31.     (interactive "NFind line of length: ")
  32.     (let ((abslen (if (< len 0) (- len) len)))
  33.       (condition-case nil
  34.       (progn
  35.         (re-search-forward 
  36.          (concat "^"
  37.              (make-string abslen ?.)
  38.              (if (< len 0) "$")
  39.              ))
  40.         (beginning-of-line))
  41.     (error (error "Line of %d%s characters not found" abslen 
  42.               (if (< len 0) "" " or more"))
  43.            ))
  44.       ))
  45.  
  46. --
  47. Wayne();
  48. WMesard@cs.Stanford.edu
  49.