[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Check for empty grep and suggest fuzzy grep instead
From: |
Nikolaj Schumacher |
Subject: |
Re: Check for empty grep and suggest fuzzy grep instead |
Date: |
Tue, 07 Apr 2009 15:53:11 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (darwin) |
Nordlöw <per.nordlow@gmail.com> wrote:
> How can I check the number of hits grep found (from within Emacs of
> course). I need this in order to auto-suggest a fuzzy grep instead
> somewhat like what happens when you search for a pattern that Google
> doesn't know about.
>From what you want to do, it sounds like you need a combination of "grep
-c" and compilation-finish-functions.
But from you question, it sounds like you want something like this:
(adapted from my package full-ack.el, which is an ack front-end)
(defun grep-count-matches ()
"Count the matches printed by `grep' in the current buffer."
;; Force fontification.
(font-lock-fontify-region (point-min) (point-max))
(let ((c 0)
(beg (point-min)))
(setq beg (next-single-char-property-change beg 'font-lock-face))
(while (< beg (point-max))
(when (eq (get-text-property beg 'font-lock-face) 'match)
(incf c))
(setq beg (next-single-char-property-change beg 'font-lock-face)))
c))
regards,
Nikolaj Schumacher