Is there an equivalent find-grep-dired using ack or ag? With the ability to specify the directory where the search starts? The Dired output itself is not so important (in fact I prefer the ack-mode result output). The closest thing I found is a Projectile ag/ack integration where the prefix argument prompts for the directory, but I was looking for something more general.

  • Can you elaborate on what you mean by more general? The way this question is phrased now makes it unrelated to emacs.
    – Vamsi
    Oct 8 '14 at 16:57
  • 1
    Sorry for not being clear. Here is another try : the projectile ag/ack integration supports prefix argument, which when used prompts for the directory. So it works similar to the find-grep-dired. But that works only within a projectile project (projectile mode is on). I'm looking for ag/ack version of find-grep-dired that can be used outside of the projectile too.
    – emil
    Oct 8 '14 at 18:27

The ag package (available on MELPA) has the ability to run ag only within your specified folder or in project root. Check out its README on its github for more info.

Here are some of the answers from this stackexchange the elaborate on the use of ag in emacs:


Here is small function that does what I was looking for; perhaps useful to someone else too. The function prompts for the directory and invokes the ag search-term. When invoked with the prefix argument the search-term is interpreted as regular expression.

(defun find-ag (dir search-term)
  "Run an ag search with SEARCH-TERM in the directory.

With an optional prefix argument ARG SEARCH-TERM is interpreted as a
regular expression."
  (interactive "DFind-ag (directory): \nsFind-ag (ag expression): ")
  (if (fboundp 'ag-regexp)
      (let ((ag-command (if current-prefix-arg 'ag-regexp 'ag))
            ;; reset the prefix arg, otherwise it will affect the ag-command
            (current-prefix-arg nil))
        (funcall ag-command search-term dir))
    (error "Ag is not available")))

You can use helm-ff-do-grep invoked in helm-find-files to grep any directory you want. It has a demo in there; the grep in Helm is incremental: it returns results for every character you type, effectively provides live feedback. Or use helm-projectile that is capable of invoking grep in any directory of selected file or directory in a helm-projectile-find-file or helm-projectile-find-dir. See the helm-projectile guide here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.