Skip to main content
note that occur displays the number of matching lines, not the number of matches (thanks xuhdev); mention how-many and show how it could be integrated (not very nicely) in isearch
Source Link

Here are some possibilities that aren't very slick, that have the advantage of working with a stock Emacs.

If you press M-s o (isearch-occur) during an incremental search, an OccurOccur buffer pops up with the current search expression. At the top of the *Occur* buffer is the match countnumber of matching lines.

This isn't very slick, but it hasThe command how-many displays the advantagenumber of workingoccurrences of a regexp (including repeated occurrences). Unfortunately it isn't integrated with incremental search. Here's a stock Emacsproof-of-concept isearch integration: press M-s # during isearch to show the number of matches.

(defun isearch-how-many (regexp) "Run `how-many' using the last search string as the regexp. Interactively, REGEXP is constructed as with `isearch-occur'." (interactive (list (cond ((functionp isearch-word) (funcall isearch-word isearch-string)) (isearch-word (word-search-regexp isearch-string)) (isearch-regexp isearch-string) (t (regexp-quote isearch-string))))) (how-many regexp nil nil (interactive-p))) (define-key isearch-mode-map [?\M-s ?#] 'isearch-how-many) 

If you press M-s o (isearch-occur) during an incremental search, an Occur buffer pops up with the current search expression. At the top of the *Occur* buffer is the match count.

This isn't very slick, but it has the advantage of working with a stock Emacs.

Here are some possibilities that aren't very slick, that have the advantage of working with a stock Emacs.

If you press M-s o (isearch-occur) during an incremental search, an Occur buffer pops up with the current search expression. At the top of the *Occur* buffer is the number of matching lines.

The command how-many displays the number of occurrences of a regexp (including repeated occurrences). Unfortunately it isn't integrated with incremental search. Here's a proof-of-concept isearch integration: press M-s # during isearch to show the number of matches.

(defun isearch-how-many (regexp) "Run `how-many' using the last search string as the regexp. Interactively, REGEXP is constructed as with `isearch-occur'." (interactive (list (cond ((functionp isearch-word) (funcall isearch-word isearch-string)) (isearch-word (word-search-regexp isearch-string)) (isearch-regexp isearch-string) (t (regexp-quote isearch-string))))) (how-many regexp nil nil (interactive-p))) (define-key isearch-mode-map [?\M-s ?#] 'isearch-how-many) 
Source Link

If you press M-s o (isearch-occur) during an incremental search, an Occur buffer pops up with the current search expression. At the top of the *Occur* buffer is the match count.

This isn't very slick, but it has the advantage of working with a stock Emacs.