Generic helm interface to grep
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 runsag
. - 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 usesag
instead ofgit-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)
RET
/F1
selects an item and closes the helm session.F2
runs the grep command in agrep-mode
buffer.Right-arrow
selects the item, but does not close the helm session. This is similar ashelm-occur
. Default helmkeybindings for this feature are also available (C-j
andC-z
).M-c
cycles case sensitiveness.
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.
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 bothgit-grep
andag
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 ofhelm-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 thehelm-grepint-set-default-config-latest
.
Version 1.1.1
- Add
--ignore-case
argument forgit-grep
to make it consistent withag
in thehelm-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
andhelm-grepint-set-default-config-v1.1.0
. - Change the
helm-grepint-set-default-config
function to an alias ofhelm-grepint-set-default-config-v1.0.0
. Add new aliashelm-grepint-set-default-config-latest
which points tohelm-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.
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.
Get a grep configuration with NAME or set it to NEW-CONFIG.
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.
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.
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.
Get the default root directory if :root-directory-function isn’t defined.
Ask the root directory from user.
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.
Jump to line in a file described by a grep -line CANDIDATE.
Run ‘grep-mode’ with the current pattern.
CANDIDATE is ignored.
Split the STR at whitespace and replace them with .*.
Supports backslash escaping for literal spaces. See ‘helm-mm-split-pattern’ for more details.
This is the candidates-process for ‘helm-grepint-helm-source’.
Propertize each CANDIDATE provided by ‘helm-grepint-helm-source’.
Select the next one from the ‘helm-grepint-character-cases’ list.
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’.
Function ‘helm-grepint-grep’ is run in a root directory.
See the usage for ARG in ‘helm-grepint--grep’.
Set the default grep configuration into ‘helm-grepint-grep-configs’ and ‘helm-grepint-grep-list’.
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.
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.