emacsorphanage / helm-ag

The silver searcher with helm interface
492 stars 77 forks source link

helm-ag errors on pattern starting with dash #369

Closed dalanicolai closed 4 years ago

dalanicolai commented 4 years ago

Actual behavior

When searching for a pattern starting with a dash using helm-do-ag, helm-ag returns the following message:

helm-get-candidates: Candidates function ‘#[0 \301 \210\302\300!\207 [/home/dalanicolai/ helm-ag--do-ag-set-command helm-ag--do-ag-candidate-process] 2]’ should run a process

I am not sure how you think about this behavior, but personally I would prefer if helm-ag auto escapes the dash (at least when automatically "grabbing" the pattern from a buffer)

Expected behavior

Expect to search for the pattern (i.e auto escape the dash). Suggested fix: replace in the function helm-ag--do-ag-candidate-process the line

(cmd-args (helm-ag--construct-do-ag-command helm-pattern)))

with

(cmd-args (helm-ag--construct-do-ag-command (if (string-match "^-" helm-pattern)
                                                         (concat "\\" helm-pattern)
                                                       helm-pattern)))

Steps to reproduce

type some string starting with a dash in a buffer, position the point on the string and invoke helm-do-ag

syohex commented 4 years ago

Please input -- before pattern if you want to search word which starts with -. e.g. -- --foo-bar. helm-ag supports additional command line options, so helm-ag does not escape pattern which starts with -. For example we can input -G\.md pattern (-G\.md means searching only markdown files). helm-ag cannot provide this feature with your suggestion.

dalanicolai commented 4 years ago

Ah yes, I was aware of this but forgot to check it. Anyway the idea was that such patterns (starting with dash) are only escaped when they are grabbed from a buffer automatically (like when selecting it first). But indeed this "fix" here breaks the additional command line options functionality when typing in helm directly. Okay... it was just a suggestion, the not escaping when grabbing 'dashed patterns' from the buffer is not a huge issue of course. Thanks for the quick reply, and nice explanation

jcs090218 commented 4 years ago

@dalanicolai It seems this conversation ends? Shall I close it? Thanks! :)

dalanicolai commented 4 years ago

@jcs090218 Fine with me :)

jcs090218 commented 4 years ago

Thanks for opening this issue and your suggestion! Sorry that we could not take it! 😖