Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ag doesn't search (ag 0.18.1) #26

Closed
jwalt opened this issue Nov 21, 2013 · 10 comments
Closed

ag doesn't search (ag 0.18.1) #26

jwalt opened this issue Nov 21, 2013 · 10 comments

Comments

@jwalt
Copy link

jwalt commented Nov 21, 2013

When running ag, the ag subprocess doesn't actually start searching. It seems to wait for input from stdin.

A small change in line 138 fixes this, just append "." to the end of the command:

(compilation-start
 (mapconcat 'shell-quote-argument
            (append '("ag") arguments (list string) '("."))
            " ")
@Wilfred
Copy link
Owner

Wilfred commented Nov 21, 2013

That's really weird. Could you paste the command that is run in the buffer? For example, if I do a search, I get the following:

-*- mode: ag; default-directory: "~/personal/ag.el/" -*-
Ag started at Thu Nov 21 11:46:55

ag --color --color-match 30\;43 --literal --smart-case --nogroup --column -- while
ag.el:256:12:          (while (re-search-forward "\033\\[30;43m\\(.*?\\)\033\\[[0-9]*m" end 1)
ag.el:262:12:          (while (re-search-forward "\033\\[[0-9;]*[mK]" end 1)

Ag finished at Thu Nov 21 11:46:55

(run with ag.el version 0.32, ag version 0.18.1)

So the command is ag --color --color-match 30\;43 --literal --smart-case --nogroup --column -- while, which also works when I run it manually from the shell.

Also, does this occur if you start from a clean configuration (using emacs -Q)? Have you customised ag-arguments?

@arongp
Copy link

arongp commented Nov 25, 2013

I also have this issue on my Windows 7 x64 machine. The ag process is running background but no results are shown in Emacs.

I can get search results by appending "." to the end of ag command, but the results are not highlighted and next-error command is not working in compilation buffer probably because of regexp mismatch.

I'm using ag.el 0.33 and ag version 0.18.1 on Windows 7 x64, and ag-arguments are not customized.

@Wilfred
Copy link
Owner

Wilfred commented Nov 25, 2013

Aha, Windows. Sounds like it might be an upstream bug, but I'm happy to append . to workaround in the meantime. Does the same behaviour happen if you run ag directly from a shell without the .?

Also, could you say what values you have for shell-file-name and shell-command-switch please?

Highlighting not working (assuming you've set ag-highlight-search) is odd, as is next-error not working. Hmm.

@arongp
Copy link

arongp commented Nov 26, 2013

ag on Windows cmd.exe works fine without having . at the end. It's only lisp code has this issue.
In my case, the shell-file-name is d:/emacs/bin/cmdproxy.exe and the shell-command-switch is -c.

And what I mean by highlighting is the underlines of the matched file names in compilation buffer. Sorry for this incorrect statement.

Here are some output from ag.el for search string: text

-*- mode: ag; default-directory: "~/.emacs.d/elpa/ag-20131103.1957/" -*-
Ag started at Tue Nov 26 09:53:53

"ag" "--nocolor" "--literal" "--smart-case" "--nogroup" "--column" "--" "text" "."
ag.el:24:   (:else (format "*ag text:%s dir:%s*" search-string directory))))

Ag finished at Tue Nov 26 09:53:53

You can see that we lost the line number, and thus this doesn't match the compilation mode pattern in ag.el ^\\([^:\n]+?\\):\\([1-9][0-9]*\\):\\([1-9][0-9]*\\):. I guess this is why next-error fails. And running ag directly from cmd.exe correctly prints the line number.

Also FYI,
I get Windows version of ag.exe from https://github.com/kjk/the_silver_searcher/, and of course, ag.el works fine on my Mac OS X 10.9.

Wilfred added a commit that referenced this issue Nov 26, 2013
@Wilfred
Copy link
Owner

Wilfred commented Nov 26, 2013

OK, I've not yet had an opportunity to examine this thoroughly, but I've made the change you suggested. Thanks for the pointer to the kjk repo, I'll give it a try.

@ryane
Copy link

ryane commented Nov 26, 2013

Hi, fyi, I am seeing the same issue as @arongp.

Windows 8.1 x64
ag.el: 0.34
ag version: 0.15pre
shell-file-name: "C:/emacs/emacs-24.3/bin/cmdproxy.exe"
shell-command-switch: -c

@swinkels
Copy link

After some investigation I found out that if you pass option --line-number to ag, the line number is displayed. This options prints the line number even if the input is a stream. I do not really know how ag and Emacs interact, but adding that option did the trick for me.

This is my updated version of ag-arguments:

g-arguments is a variable defined in `ag.el'.
Its value is ("--smart-case" "--nogroup" "--line-numbers" "--column" "--")

Original value was 
("--smart-case" "--nogroup" "--column" "--")

Rhetorical question: maybe this is related to leonid-shevtsov/SearchInProject_SublimeText#1 (comment) ?

@Wilfred
Copy link
Owner

Wilfred commented Jul 13, 2014

Thanks for the links, this certainly looks relevant to #52. However, this particular issue is about no results at all in the results buffer, as I understand it.

@webframp
Copy link

Just confirming this change worked for me, here's what I did:

(defconst *is-windows* (eq system-type 'windows-nt))

(when *is-windows*
  (setq-default ag-arguments (cons "--line-numbers" ag-arguments)))

@Wilfred
Copy link
Owner

Wilfred commented Aug 4, 2014

OK, I believe the issues raised in this ticket are now fixed.

@jwalt found that ag seems to require passing the current directory (i.e. appending . to the search command). We now do this.

@arongp was missing line numbers. This was fixed in #52.

Please let me know if ag.el isn't working as expected for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants