🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99449

How-many region

#99449
From: macrakis
Date: Wed, 12 Sep 1990 12:56
32 lines
1834 bytes
GNU Emacs 18.53.11 on NeXT 1.0.1

(Sorry, I hit C-c C-c too soon.)

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 t))

(defun how-many-region (begin end regexp &optional interactive)
  "Print number of non-trivial matches for REGEXP in region.
Non-interactive arguments are Begin End Regexp"
  (interactive "r\nsHow many matches for (regexp): \np")
  (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))))
      (if interactive (message "%d occurrences" count))
      count)))
Technical Details
Message-ID: <9009121355.AA17643@.dupuis.gr.osf.org.>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!wuarchive!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ri.osf.fr!macrakis

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,77fe2686ffa0c604
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-09-12 05:56:37 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!wuarchive!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: <9009121355.AA17643@.dupuis.gr.osf.org.>
Date: 12 Sep 90 12:56:37 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 32
Posted: Wed Sep 12 13:56:37 1990
X-Unparsable-Date: Wed, 12 Sep 90 14:55:31 GMT+0100