🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Kevin Rodgers Fri, 08 Jan 1993 18:27
count-matches
#940
Author: Kevin Rodgers
Date: Fri, 08 Jan 1993 18:27
38 lines
1969 bytes
Re: Emacs 18.58

1. count-matches (aka how-many), which is defined in replace.el, isn't
   documented in the elisp manual (1.03).

2. count-matches should preserve the match data by saving and restoring
   it before returning.

3. It would be more useful if count-matches returned an integer rather
   than printing a message; how-many (which should probably be renamed
   how-many-matches) could be used to print the message containing the
   count returned by count-matches.

4. Just as string-match is provided as an analog to re-search-forward,
   count-string-matches and how-many-string-matches should be provided
   as well (and documented in the elisp manual):

(defun count-string-matches (regexp string &optional start)
  "Return the number of matches for REGEXP in STRING.  If optional
argument START is non-nil, count matches from that index in STRING."
  (let ((match-data (match-data))
	(count 0))
    (unwind-protect
	(while (string-match regexp string start)
	  (setq count (1+ count)
		start (match-end 0)))
      (store-match-data match-data))
    count))

(defun how-many-string-matches (regexp string &optional start)
  "Print the number of matches for REGEXP in STRING.  If optional
argument START is non-nil, count matches from that index in STRING."
  (message "%d occurrences" (count-string-matches regexp string start)))
--
Kevin Rodgers				kevin@traffic.den.mmc.com
Martin Marietta MS A16401		(303) 790-3971
116 Inverness Dr. East
Englewood CO 80112 USA			GO BUFFS!
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads