Coder Social home page Coder Social logo

helm-grepint's Introduction

Emacs Logo

helm-grepint.el

Generic helm interface to grep


License GPLv3 MELPA MELPA Stable

Description

This package solves the following problems for me:

  • A single function call interface to grep and therefore keybinding.
  • Selects the grep based on context: Inside a git-repository, runs git-grep, otherwise runs ag.
  • Uses helm to select candidates and jumps to the given line with RET.
  • A second interactive function helm-grepint-grep-root. This runs the grepping inside a root directory. By default this has been defined for the git-grep where it greps from the git root directory.
  • Inside a huge git repository one can create a file defined in the variable helm-grepint-default-config-ag-presearch-marker-file and it will set that directory as the root directory for grepping. It uses ag instead of git-grep as the grep.
  • The grepping is case-insensitive by default, but if an upper-case letter is given case-sensitive grepping is done.

The following enables the aforementioned:

    (require 'helm-grepint)
    (helm-grepint-set-default-config-latest)
    (global-set-key (kbd "C-c g") #'helm-grepint-grep)
    (global-set-key (kbd "C-c G") #'helm-grepint-grep-root)

Key bindings within helm

  • RET/F1 selects an item and closes the helm session.
  • F2 runs the grep command in a grep-mode buffer.
  • Right-arrow selects the item, but does not close the helm session. This is similar as helm-occur. Default helmkeybindings for this feature are also available (C-j and C-z).
  • M-c cycles case sensitiveness.

Customization

Look into the function helm-grepint-set-default-config to see how the default cases are configured. Also look into helm-grepint-add-grep-config for more details on what is required for a new grep to be defined.

Notable changes

Version 1.6.0

  • Add helm-grepint-regexp-quote-pre-input option enable quoting of regular expression characters in the pre-input string. It is disabled by default.

Version 1.5.0

  • Use templates in the :arguments of helm-grepint-add-grep-config. Use the templated approach for both git-grep and ag configurations.

Version 1.4.0

  • The F2 action runs the command and displays the results in grep-mode. Previously the grep-mode was only faked.

Version 1.3.0

  • Make minimum pattern length configurable with helm-grepint-min-pattern-length.
  • Use helm-mm-split-pattern to split the pattern. Supports now backslash escaped spaces.
  • Make pattern processing altogether configurable with grep-property :modify-pattern-function.
  • Remove highlighting with helm-grep-highlight-match to fix a bug.

Version 1.2.0

  • Obsoleted helm-grepint-get-grep-config in favor of helm-grepint-grep-config.
  • Make the ignore-case a separate argument in the grep configuration. This way it can be toggled on and off easily.
  • Add case-fold-search support (case-(in)sensitiveness). Add Helm keybinding M-c to control it.
  • Add smart case-sensitiveness checking.
  • Add a new configuration helm-grepint-set-default-config-v1.2.0 which makes the smart cases-sensitiveness as the default. The configuration is now the helm-grepint-set-default-config-latest.

Version 1.1.1

  • Add --ignore-case argument for git-grep to make it consistent with ag in the helm-grepint-set-default-config.

Version 1.1.0

  • Fix incompatibilities with recent helm versions.
  • Add helm-grepint-candidate-number-limit variable to control the number of candidates instead of hard-coding 500.
  • Create a new example configuration which adds the ag-presearch functionality. The example configurations are now versioned: helm-grepint-set-default-config-v1.0.0 and helm-grepint-set-default-config-v1.1.0.
  • Change the helm-grepint-set-default-config function to an alias of helm-grepint-set-default-config-v1.0.0. Add new alias helm-grepint-set-default-config-latest which points to helm-grepint-set-default-config-v1.1.0.

Version 1.0.0

  • Add action to create a grep-mode buffer from the helm-buffer.
  • Add universal-argument to manually ask the used grep configuration.

Version 0.5.5

  • Fix swooping into multiple files within a helm session. Previously it would change default-directory every swoop.
  • Add action to open the helm buffer in grep-mode. This enables the use of e.g. wgrep.
  • Add helm-grepint-grep-ask-root and set it as default for ag.

Function Documentation

(helm-grepint-add-grep-config NAME &rest CONFIGURATION)

Add configuration NAME with properties from CONFIGURATION.

The configuration can have the following items:

:command

  • A command string to run.

:arguments

  • Arguments provided for the command when it is run. This and :command is provided for the ‘helm-grepint-run-command’ function.

  • The argument string can contain the following strings that are replaced with given strings:

    ":ignore-case-argument" -> The value of :ignore-case-argument. ":search-pattern" -> The pattern from helm.

    If the above are not given, they are concatenated in the above order to the command line.

:enable-function

  • A function that returns non-nil if this grep can be used. If this is nil, the grep can be used always.

:root-directory-function

  • Function that returns a string of a directory that is regarded as the root directory when running ‘helm-grepint-grep-root’. If this is nil, ‘helm-grepint-grep-root’ behaves exactly as ‘helm-grepint-grep’.

:ignore-case-argument

  • The argument for the grep command that makes grepping ignore character case. Traditionally this is ‘--ignore-case’ for a number of different greps. This needs to be defined or the ‘helm-grepint-cycle-character-case’ function has no effect.

:modify-pattern-function

  • This modifies the ‘helm-pattern’ before giving it to the grep. If this is nil, the default the ‘helm-grepint-pattern-modify’ function is used.

(helm-grepint-grep-config NAME &optional NEW-CONFIG)

Get a grep configuration with NAME or set it to NEW-CONFIG.

(helm-grepint-grep-config-property NAME PROPERTY &rest NEW-VALUE)

Get a config NAME’s PROPERTY or set it to NEW-VALUE. The config NAME has been added with ‘helm-grepint-add-grep-config’. Returns the current value of the property or nil if either name or property was not found.

(helm-grepint-run-command &rest PLIST)

Run a grep command from PLIST.

The command line is constructed with the following PLIST items:

:command :arguments :extra-arguments.

The :arguments is split on whitespace, but :extra-arguments are used as is.

(helm-grepint-select-grep ASK-GREP)

Select the grep based on :enable-function from ‘helm-grepint-grep-configs’.

If ASK-GREP is non-nil, select the grep by asking with ‘completing-read’. The greps are compared in order of ‘helm-grepint-grep-list’. If the grep does not have :enable-function property, select it automatically.

(helm-grepint-grep-default-root)

Get the default root directory if :root-directory-function isn’t defined.

(helm-grepint-grep-ask-root)

Ask the root directory from user.

(helm-grepint-grep-parse-line LINE)

Parse a LINE of output from grep-compatible programs.

Returns a list of (file line contents) or nil if the line could not be parsed.

(helm-grepint-grep-action-jump CANDIDATE)

Jump to line in a file described by a grep -line CANDIDATE.

(helm-grepint-grep-action-mode CANDIDATE)

Run ‘grep-mode’ with the current pattern.

CANDIDATE is ignored.

(helm-grepint-pattern-modify STR)

Split the STR at whitespace and replace them with .*.

Supports backslash escaping for literal spaces. See ‘helm-mm-split-pattern’ for more details.

(helm-grepint-grep-process)

This is the candidates-process for ‘helm-grepint-helm-source’.

(helm-grepint-grep-filter-one-by-one CANDIDATE)

Propertize each CANDIDATE provided by ‘helm-grepint-helm-source’.

(helm-grepint-cycle-character-case)

Select the next one from the ‘helm-grepint-character-cases’ list.

(helm-grepint-grep &optional ARG)

Run grep in the current directory.

See the usage for ARG in ‘helm-grepint--grep’.

The grep function is determined by the contents of ‘helm-grepint-grep-configs’ and the order of ‘helm-grepint-grep-list’.

(helm-grepint-grep-root &optional ARG)

Function ‘helm-grepint-grep’ is run in a root directory.

See the usage for ARG in ‘helm-grepint--grep’.

(helm-grepint-set-default-config-v1\.0\.0)

Set the default grep configuration into ‘helm-grepint-grep-configs’ and ‘helm-grepint-grep-list’.

(helm-grepint-set-default-config-v1\.1\.0)

Set default grep configuration.

Run ‘helm-grepint-set-default-config-v1.0.0’ and then this function.

Adds configuration for running ag if file set in ‘helm-grepint-default-config-ag-presearch-marker-file’ is found in a git repository before the git root. The use case is running this in huge git repositories and wanting to limit the searching to a subdirectory.

(helm-grepint-set-default-config-v1\.2\.0)

Set default grep configuration.

Run ‘helm-grepint-set-default-config-v1.1.0’ and then this function.

Makes the ‘smart’ character-case as the default. Changes the order of cycling the character-cases. After the ‘smart’ comes case-sensitive.


Markdown README file generated by make-readme-markdown.el

helm-grepint's People

Contributors

kopoli avatar rrthomas avatar syohex avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

helm-grepint's Issues

Cannot cycle case sensitivity

When I press M-c during helm-grepint, nothing happens. (I looked at the source and see that helm-grepint-helm-map also binds <right>, and that seems to do nothing either.)

This appears to be because the :keymap keyword of helm is obsolete (according to the documentation), and the keymap should be attached to the source instead. Indeed, if I move the :keymap entry to helm-grepint-helm-source, then it works as expected.

Either default to non-regex search, or escape the pattern

If I type C-c G and the symbol at point is .label, then this is what is searched for. Only, because it is a regex search, anything matching .label as a regex is displayed. This is not what I expect!

I can see two obvious options here: either default to non-regex search (i.e. escape the search pattern under the hood); this would need some work, I guess, as by default helm-grepint expects to always do a regex search; or, when the pattern is supplied from the buffer, escape it (this might be slightly confusing to look at, but only in languages that use regex special characters in identifiers).

Equivalent of `helm-grep-save-results`?

Sorry if I've misunderstood something here about helm, as it's only recently I've been using it more than superficially.

I would like with helm-grepint to save results for eyeballing and later use in a persistent buffer. With the built-in grep support, the solution seems to be helm-grep-save-results. I don't see anything similar in helm-grepint; have I overlooked something?

Stable releases on MELPA stable?

I see that frequent date releases are made (great!); would it be possible also to have stable "version number" releases on MELPA stable?

Remove layers of history from documentation?

Independent of the per-version defaults configuration, I think it's confusing to have historically-layered documentation; that is what release notes are for. I guess I'd move the current change history from the sources to a separate ChangeLog or similar). I'd be happy to make a patch to remove references to different versions from the main documentation if you agree (except where they refer to the version-based configuration options).

[Comment updated to reflect my realising that README.md is a generated file!]

Bug matching some regexs

If I try to match a character class with a space in it, e.g. [ ], then I get matches in my files for the string nil. This suggests that an elisp nil is somewhere being made into a string! Indeed, that character class does not seem to work in general with helm-grepint, though in other cases it simply produces no matches, for example FOO[ ], where I know that the string FOO exists.

Other character classes seem to work fine, for example [A-Z].

Git backend case-sensitive by default?

Hi

I am wondering if it's by design that git-grep backend is case-sensitive?
I mean:
(helm-grepint-add-grep-config git-grep
:command "git"
:arguments "--no-pager grep --line-number --no-color" <--- lacks -i option

ag backend has --ignore-case.

It looks like like a mismatch.

Or maybe it is a good idea to implement/support "smart" case (ignore case unless some uppercase symbol found)?

In `helm-grepint-grep-action-mode`, refresh should be bound to grep, not compile

In helm-grepint I press F2 to get a grep-mode buffer, and this works nicely. However, if I try to refresh the buffer with g (recompile), it actually runs a compile command rather than the grep command as expected. As usual, sorry if I misunderstood something about the way this sort of thing works with helm/helm-grepint.

Minimum length of input?

If I type fewer than three characters, I get no matches. I can't with a quick look at the source find any setting or even code that controls this; is it rather a helm thing? I'd like to be able to get matches for shorter search strings! I'm using git grep in a git project, and git grep itself seems to have no problem finding shorter matches.

Thanks very much for this package; searching with helm like this is magic!

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.