abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.31k stars 338 forks source link

Is counsel-ag command missing a parameter? #837

Open fpopineau opened 7 years ago

fpopineau commented 7 years ago

I'm new to ivy/swifer/counsel, but wanted to give it a try. I'm running Emacs-25.1 under Windows. I tried `counsel-ag' but got no results. Then I traced the command which counsel is running and I found something like this:

counsel--async-command: ag --nocolor --nogroup  -- "HANDLE"

But with no file/directory on the line. Is that expected? Because to get results, I had to apply this patch:

$ diff -u swiper/counsel.el ~/.emacs.d/elpa/counsel-20161219.731/
--- swiper/counsel.el   2016-12-22 18:16:33.339690000 +0100
+++ /c/Home/.emacs.d/elpa/counsel-20161219.731/counsel.el       2016-12-22 23:53:17.360922700 +0100
@@ -1685,7 +1688,7 @@
       (let* ((args-end (string-match " -- " extra-ag-args))
              (file (if args-end
                        (substring-no-properties extra-ag-args (+ args-end 3))
-                     ""))
+                     default-directory))
              (extra-ag-args (if args-end
                                 (substring-no-properties extra-ag-args 0 args-end)
                               extra-ag-args))
@@ -1693,6 +1696,7 @@
                              (concat extra-ag-args
                                      " -- "
                                      (shell-quote-argument regex)
+                                     " "
                                      file))))
         (if (file-remote-p default-directory)
             (split-string (shell-command-to-string ag-cmd) "\n" t)
abo-abo commented 7 years ago

Using the default (defcustom counsel-ag-base-command "ag --nocolor --nogroup %s") works fine on Linux. With that setting, the cmd called would be:

ag --nocolor --nogroup HANDLE

Also, can you open a PR with the patch? It's not easy to see what you changed.

fpopineau commented 7 years ago

What version of ag is that ? Mine from msys2/mingw64 is waiting on standard input with:

ag --nocolor --nogroup HANDLE

I need to specify a directory in order to make it look for something, hence my proposed addition of default-directory to the command arguments. Version reported is:

$ ag --version
ag version 0.31.0

Features:
  +jit +lzma +zlib

I will add the PR.

abo-abo commented 7 years ago

What version of ag is that ?

I have ag version 0.19.2 on Linux.

fpopineau commented 7 years ago

So I have checked the behaviour of ag under Linux and under msys2/mingw64. The result is that ag is affected like other msys2/mingw64 programs by some weirdness of console detection. Namely, under msys2/mingw64, the following command:

ag --nocolor --nogroup HANDLE

is waiting for input on stdin, whereas it reads files from the current directory under Linux. I may say the fact that the file/directory is optional on ag command line maybe handy when you type the command on the terminal, but it is also harmless to explicitly state this parameter. It also makes it clearer what directory is used for the search. In other words, my patch is harmless for Linux and fixes the behaviour for Windows.

abo-abo commented 7 years ago

Please open a PR with the patch.

Custodia commented 7 years ago

Changing the definition in Counsel.el did not fix counsel-ag but it did fix my problem with spacemacs/search-project-auto that I described in #852