4

I'm trying to use ack-grep as a replacement for grep + find in Emacs on Windows, but ack-grep exits immediately (successfully) without printing any matches. I've tried just about every conceivable combination of command-line parameters to ack-grep, but nothing seems to work.

M-x grep-find

Enter "ack html" to search for files containing "html". Ack exits immediately, printing nothing:

-*- mode: grep; default-directory: "c:/" -*-
Grep started at Tue Feb 23 23:50:52

ack html

Grep finished (matches found) at Tue Feb 23 23:50:52

Executing the same command "ack html" in cmd.exe works fine (showing lots of various files containing the string "html".

Any ideas?

JesperE
  • 63,317
  • 21
  • 138
  • 197
  • "Executing the same command "ack grep" in cmd.exe" - do you mean "ack html" ? Do you not have to provide it any file names to search? (I am not quite sure how these things work on Windows, where you don't have proper pipes). On linux grep-find gives you a default command running find, and you customize that, including providing the string to search and optionally changing the find invocation as well – Justin Smith Feb 23 '10 at 23:53
  • Silly question, but is ack in the PATH? Could be emacs can't find ack to run it – Sam Post Feb 24 '10 at 05:27
  • What version of ack and what version of Emacs? – cjm Feb 24 '10 at 05:37
  • And it's called "ack". Debian just calls it "ack-grep" because they already had a different program called "ack". – cjm Feb 24 '10 at 05:44
  • "ack html" means "search for files under cwd containing the string 'html'". Edited post to clarify. – JesperE Feb 24 '10 at 10:22
  • "ack" is in the path; I tried putting a printout "I'm here!" in it, which is displayed fine, so "ack" is actually invoked. – JesperE Feb 24 '10 at 10:24

3 Answers3

8

When running ack under Emacs in Windows, I found it sometimes got confused about whether it was supposed to search files or read from STDIN. Here's the function I use to call ack (use M-x ack). You can put this in .emacs.

(defvar ack-command "ack --nogroup --nocolor ")
(defvar ack-history nil)
(defvar ack-host-defaults-alist nil)
(defun ack ()
  "Like grep, but using ack-command as the default"
  (interactive)
  ; Make sure grep has been initialized
  (if (>= emacs-major-version 22)
      (require 'grep)
    (require 'compile))
  ; Close STDIN to keep ack from going into filter mode
  (let ((null-device (format "< %s" null-device))
        (grep-command ack-command)
        (grep-history ack-history)
        (grep-host-defaults-alist ack-host-defaults-alist))
    (call-interactively 'grep)
    (setq ack-history             grep-history
          ack-host-defaults-alist grep-host-defaults-alist)))
cjm
  • 61,471
  • 9
  • 126
  • 175
  • Yay! Thanks, that was it. I actually tried passing "-f" to ack to see which files it tried to parse, but then it complained about "cannot use -f in filter mode". That should've been a hint, I guess. – JesperE Feb 24 '10 at 10:28
0

(setq grep-find-command "ack <nul -i ")

Denis Howe
  • 2,092
  • 1
  • 23
  • 25
0

I had a similar issue using the ack-and-a-half module, closing STDIN did the trick there too. There's an issue on github: https://github.com/jhelwig/ack-and-a-half/issues/23

Tom
  • 42,844
  • 35
  • 95
  • 101