Giter Club home page Giter Club logo

helm-ag's Introduction

melpa badge melpa stable badge

helm-ag.el

CI Build Status

Introduction

helm-ag.el provides interfaces of The Silver Searcher with helm.

Features

Screenshot

helm-ag

Requirements

Installation

helm-ag is available on MELPA and MELPA stable

You can install helm-ag with the following command.

M-x package-install [RET] helm-ag [RET]

Basic Usage

helm-ag

Input search word with ag command. You can change search directory with C-u prefix.

helm-ag-this-file

Same as helm-ag except to search only current file

helm-do-ag

Search with ag like helm-do-grep-ag , helm-grep-do-git-grep. You can specify extra command line option of ag with minus prefix(M-- or C--).

Screen cast of helm-do-ag

helm-do-ag-this-file

Same as helm-do-ag except to search only current file

helm-do-ag-this-file-or-occur

Smartly switch between helm-do-ag-this-file and helm-occur based on helm-ag-large-file-threshold.

helm-ag-project-root

Call helm-ag at project root. helm-ag seems directory as project root where there is .git or .hg or .svn.

helm-do-ag-project-root

Call helm-do-ag at project root.

helm-ag-buffers

Search buffers by helm-ag

helm-do-ag-buffers

Search buffers by helm-do-ag

helm-ag-pop-stack

Move to point before jump

helm-ag-clear-stack

Clear context stack

Enable helm-follow-mode by default

Please set helm-follow-mode-persistent to non-nil if you want to use helm-follow-mode by default. You must set it before loading helm-ag.el.

(custom-set-variables
 '(helm-follow-mode-persistent t))

Persistent action

You can see file content temporarily by persistent action(C-j).

Search Tips of helm-ag

Passing command line options and pattern
Pattern: -Gmd$ search_pattern

Command line options is -Gmd$ and search pattern is search_pattern. helm-ag treats words which starts with - as command line option.

Pattern contains space(helm-do-ag)
Pattern: foo\ bar\ baz

Search pattern is foo\ bar\ baz. You need to escape spaces with backslash.

In helm-ag, you need not to escape spaces.

Pattern starts with -
Pattern: -- --count

Search pattern is --count. helm-ag treats words after -- as search pattern.

Search meta characters as literal

ag(ack, pt) takes Perl compatible PCRE so that you need to escape meta characters likes brackets, braces, asterisk, when you search them as literals.

Use short option

Don't use space between option and its value. For example -tcpp is ok, -t cpp is not ok.

Use long option

Please always use = separator for using long option. Don't use space as separator. For example --ignore=pattern is ok, --ignore pattern is not ok.

Customize

helm-ag-base-command(Default: ag --nocolor --nogroup)

Base command of ag. Windows users should set --vimgrep option for using helm-do-ag. See #293

helm-ag-command-option(Default: nil)

Command line option of base command.

helm-ag-insert-at-point(Default: nil)

Insert thing at point as default search pattern, if this value is non nil. You can set the parameter same as thing-at-point(Such as 'word, symbol etc).

helm-ag-fuzzy-match(Default: nil)

Enable fuzzy matching.

helm-ag-use-grep-ignore-list(Default: nil)

Use grep-find-ignored-files and grep-find-ignored-directories as ignore pattern. They are specified to `--ignore' options."

helm-ag-always-set-extra-option(Default: nil)

Always set extra command line option of ag in helm-do-ag if this value is non-nil.

helm-ag-edit-save(Default: t)

Save buffers you edit at editing completed.

helm-ag-use-emacs-lisp-regexp(Default: nil)

Use Emacs Lisp regexp instead of PCRE as pattern. NOTE: this is very simple conversion.

helm-ag-use-agignore(Default: nil)

Use .agignore file at project root if this variable is non nil.

helm-ag-use-temp-buffer(Default: nil)

Use temporary buffer and not open file for persistent action.

helm-ag-ignore-buffer-patterns(Default: nil)

Ignore buffer patterns of buffer search commands.

NOTE

helm removes file-line type feature from 1.6.9. So helm-ag-source-type is no longer available.

Keymap

helm-ag-map and helm-do-ag-map are inherited by helm-map.

Key Action
C-c o Open other window
C-l Search in parent directory
C-c C-e Switch to edit mode
C-x C-s Save ag results to buffer(Ask save buffer name if prefix key is specified)
C-c C-f Enable helm-follow-mode
C-c >, right Move to next file
C-c <, left Move to previous file
C-c ? Show help message

Edit mode keymap

Key Action
C-c C-c Commit changes
C-c C-k Abort
C-c C-d Mark delete line
C-c C-u Unmark

You can use next-error and previous-error for seeing file content which current line indicates.

Saved buffer keymap

Key Action
RET Jump to current line position
C-o Jump to current line position in other window
g Update result

Sample Configuration

(custom-set-variables
 '(helm-ag-base-command "ag --nocolor --nogroup --ignore-case")
 '(helm-ag-command-option "--all-text")
 '(helm-ag-insert-at-point 'symbol)
 '(helm-ag-ignore-buffer-patterns '("\\.txt\\'" "\\.mkd\\'")))

helm-ag.el with other searching tools

helm-ag.el can work other searching tools like platinum searcher or ack instead of the silver searcher. I think the searching tool which supports grep like output, helm-ag can work with it.

(custom-set-variables
 '(helm-ag-base-command "pt -e --nocolor --nogroup"))
(custom-set-variables
 '(helm-ag-base-command "ack --nocolor --nogroup"))
(custom-set-variables
 '(helm-ag-base-command "sift --no-color -n"))

Ripgrep uses exit-status 2 to indicate a partial success:

(custom-set-variables
 '(helm-ag-base-command "rg --no-heading --line-number --color never")
 `(helm-ag-success-exit-status '(0 2)))

NOTE: For pt and rg users

When using ag or ack, helm-do-ag convert pattern from foo bar to "(?=.*" foo ".*)(?=.*" bar ".*)" which pattern matches line which contains both foo and bar. But when using pt or rg, helm-do-ag does not convert the pattern because Golang regexp(pt is written in Golang) and rust's regex (rg is written in rust) does not support look-a-head pattern. So using pt or rg behaves differently from ag when you use such pattern.

Alternatives

ag.el provides M-x grep interface. Also it can work without helm.

helm-ag's People

Contributors

15cm avatar agriffis avatar aki2o avatar arejensen avatar avdv avatar blaenk avatar bmag avatar cibinmathew avatar dependabot[bot] avatar ganmacs avatar jcs090218 avatar jimeh avatar joehillen avatar junhuihuang avatar kiennq avatar lewer avatar markhepburn avatar mijoharas avatar mikulely avatar mrbliss avatar namburgesas avatar nivekuil avatar nkpart avatar pkryger avatar snpskimr avatar storax avatar syl20bnr avatar syohex avatar twlz0ne avatar vermiculus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

helm-ag's Issues

Add C-c ? binding to show helm-ag specific help.

It would be nice if helm-ag used the same convention of other helm commands of showing command-specific help when pressing C-c ?. I am not really sure what would be involved in getting this to work for helm-ag.

How make Helm-ag editable and saving?

Thanks for sharing this awesome addition to Helm. I really appreciate it.

However, I have a question. In Vim, you type :Ag example. Then you see the lines which contains the word 'example' in Quickfix window. Then with Quickfix Reflector, you change the values of each line, and save it back to multiple files. The Emacs-wgrep seems using the same technique as Quickfix Reflector.
An example in Vim:
agcontent

I haven't figured out how to the same with Helm Ag. Could this even be possible?

searching term with spaces produces a lot of results

Hi, This might be related to #78.

When searching with helm-do-ag a in the search term causes a lot of results shown that seem unrelated.

I'm using spacemacs so this might be an issue there but I did not find any configuration in spacemacs that would obviously cause this.

Example:
I search the spacemacs source tree for smooth scrolling. Everything works fine when typing smooth showing me 23 results. But as soon as I type smooth scroll I get around 5000 results.

Does it support .agignore

I know ag could use .agignore to ignore some pattern specified in the .agignore file.

I can use it in Projectile-ag, but helm-ag seems doesn't support it?

Am I miss something here?

thanks.

tramp integration

Is it possible for this to work with tramp, similar to helm-grep?

Easier way to specify command line options to ag

There are several ag command line options that I frequently toggle on or off. For example:

-G, --file-search-regex PATTERN:
     Only search filenames matching PATTERN.
-s --case-sensitive:
     Match case sensitively.
-w --word-regexp:
     Only match whole words.

Currently the easiest way I've found to set these is to do M-x customize-option helm-ag-command-option, edit the customization buffer, save, return to other buffer, etc.

But that is very tedious to set and unset these variables all the time.

Could there be an easier way? For me, the best would be for helm-do-ag to prompt for command options every time. And I could just press Return to accept the last used setting.

helm-do-ag-project-root doesn't work

Hi,

first of all thanks for providing this plug-in! Unfortunately, I'm encountering problems when trying to use helm-do-ag-project-root: it doesn't show anything even thoug helm-do-ag does work for the same inputs.

I'm using Emacs 24.4.1 on Windows 8.1 Pro x64 with the latest ag.exe installed by chocolatey. Anything I can do to help debug? (I'm totally new to Emacs btw... ;-)

Thanks and best regards!

[Feature] Support for grep

Do you think it is possible to support grep in helm-ag ?

Right now in spacemacs with use helm-ag for ag, pt and ack, we even use it instead of helm-projectile, this is great because we can enjoy the C-c C-e feature of helm-ag. Thanks to helm-ag we can unify search in files, in opened buffers, in current file and in current project.

The only thing we don't support with helm-ag is grep, it would be wonderful to be able to have this backend supported.

configurable start search directory

I use Projectile and having helm-ag honour the project directory for its search would be nice and useful for people.

Locally, I have adapted helm-ag accordingly by introducing a new function that is called when default-directory was previously used (see here) which checks if Projectile is active and what the current root is and otherwise returns default-directory. Which is basically for what I wanted to open a PR but after thinking about it more, I think this would be the wrong direction as it would naturally somewhat require adding more and more project tools if people ask for it... and besides, not everyone uses Projectile and the like but implements their own solution (kinda what I do too).

So, I am thinking giving the user a simple way to configure this programmatically would be the right thing to do, like:

  • introducing a helm-ag-start-search-directory variable which is buffer local and wrapping the directory-default (here) within a or together with it which preserves the current behaviour but introduces a nice configuration point

or

  • letting the user register a custom function that is called if defined which is expected to return the path (which is kinda what I already did but here without a default implementation that checks for Projectile or whatever)

Personally, I would go with KISS and YAGNI and choose the former-- at least until something more complex is really required.

What do you think? (and sorry for the wall of text :P)

Strange characters

I get some strange behaviour on helm-do-ag. A picture is worth one thousand words.

selection_001

ag and pt not working on a windows box

I recently unified the usage of ag, pt and ack under helm-ag in order to get the helm-ag-edit capability.
This does not seems to work on a windows box. I tracked the issue a bit and was able to take the output of helm-ag--construct-command verbatim and execute it on a cmd box and it works.

Do you have any insight about this issue, is it an output encoding issue ?

Show pattern match files relative to the search path

Hi,

I think it would be nice to have the files matched through helm-do-ag to have their paths relative to the search path provided.

For example, here I have emacs-helm-ag/test/test-util.el open, but I specify the search to be up one directory (in emacs-helm-ag/)

emacs-helm-ag emacs-25 0 50 73x19-7

When the results come up, the paths are relative to the currently open file, as opposed to the search path specified in the screenshot above

emacs-helm-ag emacs-25 0 50 73x19

I think it would be nice to show README.md instead of ../README.md

add features found in helm-do-grep: helm buffer for folder selection, filename extension

Hi, really enjoying helm-do-ag. I have a couple feature requests of things I find in helm-do-grep that I don't find in helm-do-ag:

  1. When performing a recursive search, typing C-u M-x helm-do-grep launches a helm buffer to select the directory, whereas C-u M-x helm-do-ag brings up the default emacs directory selection. I would like to have helm-do-ag bring up a helm buffer to select the directory.

emacs-helm-ag emacs-25 0 50 73x19-1-1

emacs-helm-ag emacs-25 0 50 73x19-1

  1. C-u M-x helm-do-grep asks for a filename extension filter whereas C-u M-x helm-do-ag doesn't ask for a filename extension filter.
    emacs-helm-ag emacs-25 0 50 73x19-4

Allow to skip entering arguments to ag

Most of the time, I don't want to enter additional arguments ag and just use the default arguments. Having to press enter for every ag search before I can get the result is inconvenient. Most of the time, I just want helm-ag to behave like helm-do-grep: get the result immediately after every character I entered.

If I want Ag: prompt, I should have another command. In sum, we should have two commands, one behaves like current helm-ag, one ignores Ag: input and allow live feedback on every character, similar to the default helm-do-grep bundled with Helm.

Because of this missing feature, I still use helm-do-grep most of the time for small directory.

Documentation: Option rename

Hello,

I just like to mention that the documantation on the front page is in some parts outdated.

At least the following option name has change:
from: helm-ag-thing-at-point
into: helm-ag-insert-at-point

Greets,
Matthias

Add pt support

Platinum Searcher is a new text search tool similar to ag, but is a bit faster. Reasons to support it:

  • It has a binary distribution for Windows. A single binary file, pt.exe. Making ag works on Windows is more complicated. Currently, my only viable option on Windows is grep.
  • Its syntax is similar to ag. In fact, I replace helm-ag--construct-do-ag-command with plain list of pt arguments and it works fine. Note that on Windows, instead of starting with -- for each option, it starts with a slash /. So, you should have (window-system) check to prepare correct option syntax.

An example of plain pt command:

pt --nogroup --nocolor <pattern> <directory>

On Windows:

pt /nogroup /nocolor <pattern> <directory>

You may hesitate because this package is named helm-ag :) . I think it is fine, given that helm-do-grep also has extended support for ack, so helm-ag provides extended support for pt is only beneficial.

helm-source-do-ag can't work

Hi there,

I found a bug of 'helm-source-do-ag':
Default var 'helm-ag-default-directory' and var 'helm-ag-last-default-directory' all are nil, helm-ag-find-file-action will set var 'helm-ag-last-default-directory' with nil, then helm action "Open File" can't work, because find-file don't know parent directory of find file.

And 'helm-do-ag' haven't this bug, because 'helm-do-ag' will set 'helm-ag-default-directory' with (or basedir default-directory)

So i have build below patch to fix bug of 'helm-ag-find-file-action' :

114c114,116
<                                 helm-ag-last-default-directory)))

---
>                                 helm-ag-last-default-directory
>                                 default-directory
>                                 )))

Below is new version after patch:

(defun helm-ag-find-file-action (candidate find-func)
  (let* ((elems (split-string candidate ":"))
         (search-this-file (helm-attr 'search-this-file))
         (filename (or search-this-file (cl-first elems)))
         (line (string-to-number (if search-this-file
                                     (cl-first elems)
                                   (cl-second elems))))
         (default-directory (or helm-ag-default-directory
                                helm-ag-last-default-directory
                                default-directory     ; add 'default-directory' to avoid helm-ag-last-default-directory with nil
                                )))
    (setq helm-ag-last-default-directory default-directory)
    (funcall find-func filename)
    (goto-char (point-min))
    (forward-line (1- line))))

can't select directory unless I use C-u

Starting with 1529c42 I'm not able to specify a search directory anymore when performing M-x helm-do-ag. It does ask for a directory if I do C-u M-x helm-do-ag though

In my opinion it should still ask for a directory every time (even without C-u). Perhaps it could default to the git root, or the last used directory. Asking for a directory each time is useful for large projects, and also more intuitive for new users.

save helm-ag buffer to edit search results

In helm-do-grep, search results can be saved into hgrep buffer (helm-grep-mode).
In this buffer, a user can edit the search results via wgrep-helm.
I guess helm-ag can also support the same feature.
Moreover, it would be nice if candidates in helm-ag buffer are colored and highlighted, like grep, helm-occur, helm-ack, etc.

helm-ag does not work when spaces in search term

When I do M-x helm-ag, and then enter something like "search term" (without the quotes), I get the message "Failed: 'term'". How can I fix this? Is there a correct way to enter spaces in the search term?

`helm-do-ag` not setting base directory correctly?

steps:
run emacs -Q and eval:

(package-initialize)
(require 'helm)
(require 'helm-ag)

Assume I have the following files:

~/helm-test/a/one.txt
~/helm-test/b/two.txt (contains text "hello")

Using helm-ag, I can:

  1. visit ~/helm-test/a/one.txt
  2. C-u M-x helm-ag RET ~/helm-test/ RET hello
  3. Finds b/two.txt and I can jump to it.

However, using helm-do-ag, this doesn't work.

  1. visit ~/helm-test/a/one.txt
  2. C-u M-x helm-do-ag RET ~/helm-test RET RET hello
  3. It correctly finds the file, but when I go to jump to it, it takes me to the non-existent file at ~/b/two.txt, not ~/helm-test/b/two.txt.

This problem means that the helm search provided from helm-projectile.el never works for me. If I swap helm-do-ag with helm-ag it works fine.

AG replacement for helm-find-files-grep

This is the helm-projectile action when C-s is pressed on a project in the projects list (C-c p p). It can be replaced trivially with the an ag version with the following code:

(defun helm-find-files-ag (candidate)
  "Default action to grep files from `helm-find-files'.  Replaces helm-find-files-grep."
  (let ((default-directory candidate))
    (helm-projectile-ag)))
(defalias 'helm-find-files-grep 'helm-find-files-ag)

Select candidate does not work

Hi,

I am using latest helm-ag from MELPA.
When I issue M-x helm-ag and type a pattern, the helm-ag buffer correctly shows the matching results.
However, when I select a candidate with RET the corresponding file is not opened.
It works fine with helm-do-ag.

Not working on remote host over ssh

Hello here. Plugin working perfectly on local host, but still searching on local host even when projcetile root set to remote ssh. How to get it working over ssh?

Harmonize strings such as buffer name, actions, errors

I know this can't be more trivial but I'm fussy. I am looking for consistency between helm-ag and helm-projectile.

As of now, strings (see title) are not harmonized as in: "the silver searcher" should be title'ized and "the buffer is already killed" should be capitalized. Also, action strings are title'ized ("Open File Other Window" should be "Open file in other window").

I obviously could edit my copy myself, but I prefer it to be done once and for all. I can provide a list of all strings related if necessary, hope someone can find the time to adjust that.

Thanks : j

[feature] helm-ag in all opened buffer

This is a feature request for spacemacs, we have currently SPC sto search in a directory, SPC p s to search in a project. I would like to add SPC b s to search in all opened buffers.

Truncate long lines

When there is a match in a minified js or css file it ruins helm buffer.
ag itself has an option for this --print-long-lines Print matches on very long lines (Default: >2k characters) but it doesn't accept any parameter.

Feature request: Project support

Hello,

it would be nice to have project support inside helm-ag like it is done in ag.el ( ag-project ).
Directory selection before every search is a little bit cumbersome.

Greets,
Matthias

Current working directory no longer used by default?

I've been using this for a while, and while it used to used the working directory of the current file, now it no longer seems to be respecting the directory of the file.

Did something change recently with regard to this setting? Do I need to update a setting somewhere?

Feature request: Enable space characters to interactively narrow selection

It would be great if I could further narrow the initial ag search results in the helm buffer by just typing in a space and strings to match. The idea is that the ag search gets me all options, and then the buffer search lets me narrow things based on the file path, name, and matched line in the file.

Having the first string be the regex for ag, and the subsequent space-separated strings operate on the buffer would make searching and file navigating in large code basis really rapid.

Such a change (or optional behaviour) would make helm-ag behave more like M-x helm-find-file or Projectiles M-x projectile-find-file or M-x helm-M-x.

I originally posed this feature request as a question on the Emacs stackexchange site in relation to Projectile's use of helm-ag: http://emacs.stackexchange.com/questions/7964/helm-projectile-ag-how-can-i-refine-the-grep-results-further

Can't find helm-ag on MELPA

When I browse the package list via list-packages, helm-ag doesn't show up. Other MELPA packages do, however. (My package-archives also includes ELPA, the GNU repo and Marmalade.)

helm-ag shows up when I search for it on the MELPA website, but I thought I would mention it in case something was amiss.

ag/emacs regex interpretation

I am trying to search for a string with parentheses in them. Because '(' is a special character in ag's regexes, I have to escape it. However, emacs regexes work the other way round, '(' isn't a correct emacs regex, and thus, helm-ag--do-ag-propertize breaks when using (re-search-forward helm-input bound t) on line 269.

Since converting between emacs and pcre regexes is a huge task, I would propose adding --literal to the standard command line switches for ag.

helm-ag doesn't work with -g option

use helm-ag$ -gnvm*.c to search all c file contain nvm, return no output

use helm-ag$ -gnvm to search all file contain nvm, return nil nil nil nil nil nil nil

but these commands work in terminal:
ag -gnvm*c
ag -gnvm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.