Article View: gnu.emacs.bug
Article #940count-matches
From: Kevin Rodgers
Date: Fri, 08 Jan 1993 18:27
Date: Fri, 08 Jan 1993 18:27
38 lines
1969 bytes
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!
Technical Details
Message-ID:
<9301081827.AA02773@traffic>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!traffic.den.mmc.com!kevinShow Full Headers
Complete Article Headers
Newsgroups: gnu.emacs.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!traffic.den.mmc.com!kevin From: kevin@traffic.den.mmc.com (Kevin Rodgers) Subject: count-matches Message-ID: <9301081827.AA02773@traffic> Sender: gnulists@ai.mit.edu Reply-To: kevin@traffic.den.mmc.com Organization: GNUs Not Usenet Distribution: gnu Date: Fri, 8 Jan 1993 18:27:32 GMT Approved: bug-gnu-emacs@prep.ai.mit.edu Lines: 39