Counting Check Marks

Here's my solution to the last EmacsGolf challenge. I used the apparently little-known how-many command. I normally use how-many in Elisp to count the occurrences of some regex. Here's an example from my old blog that leverages some code from the always useful EMACS-FU. It turns out that how-many is a command and thus callable interactively. That makes the solution straightforward.

Meta+xhmReturn Call how-many
cbMeta+/ cb → ✓
Return result returned in minibuffer

That does the job in 8 keystrokes.

The excellent flx-ido mapped hm to how-many on the first try despite the fact that I hadn't used how-many in several months (and never before interactively). I map 【Meta+/】 to hippie-expand, which takes care of expanding the abbreviation.

This entry was posted in General and tagged . Bookmark the permalink.
  • One thing escapes me: what is the difference between how-many and count-matches?

    • jcs

      They are the same thing. If you look at replace.el you will see that count-matches is aliased to how-many.

  • interesting. Never used how-many before. Also noticed that occur isn't the correction solution, when the char appears more than once in the same line. Thanks.