Article View: gnu.emacs.bug
Article #99448How-many region
From: macrakis
Date: Wed, 12 Sep 1990 10:38
Date: Wed, 12 Sep 1990 10:38
29 lines
1712 bytes
1712 bytes
GNU Emacs 18.53.11 on NeXT 1.0.1
I suggest how-many-region. (Alternatively, how-many could take an
optional region, but this gets messy.) This is useful in small online
Lisp programs, and interactively sometimes (although narrowing would
also work).
Here's the code. The existing behavior (which I've preserved) doesn't
count zero-length matches. Why not?
(defun how-many (regexp)
"Print number of non-trivial matches for REGEXP following point."
(interactive "sHow many matches for (regexp): ")
(how-many-region (point) (point-max) regexp))
(defun how-many-region (begin end regexp)
"Print number of non-trivial matches for REGEXP in region.\
Non-interactive arguments are Begin End Regexp"
(interactive "r\nsHow many matches for (regexp): ")
(let ((count 0) opoint)
(save-excursion
(setq end (or end (point-max)))
(goto-char (or begin (point)))
(while (and (< (setq opoint (point)) end)
(re-search-forward regexp end t))
(if (= opoint (point))
(forward-char 1)
(setq count (1+ count))))
(message "%d occurrences" count))))
Technical Details
Message-ID:
<9009121138.AA17515@.dupuis.gr.osf.org.>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!fernwood!decwrl!sdd.hp.com!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ri.osf.fr!macrakisShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fb2f1,77fe2686ffa0c604,start X-Google-Attributes: gidfb2f1,public X-Google-ArrivalTime: 1990-09-12 03:38:55 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!fernwood!decwrl!sdd.hp.com!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ri.osf.fr!macrakis From: macrakis@ri.osf.fr Newsgroups: gnu.emacs.bug Subject: How-many region Message-ID: <9009121138.AA17515@.dupuis.gr.osf.org.> Date: 12 Sep 90 10:38:55 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 29 Posted: Wed Sep 12 11:38:55 1990