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