2

GitHub - jimporter/urgrep: Universal recursive grep for Emacs

 2 years ago
source link: https://github.com/jimporter/urgrep
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Urgrep - Universal Recursive Grep

Urgrep is an Emacs package to provide a universal frontend for any grep-like tool, as an alternative to the built-in M-x rgrep (and other similar packages). Currently, ripgrep, ag, ack, git grep, and grep/find are supported.

Why Urgrep?

One package, many tools

No matter which tool you prefer, you can use it with Urgrep. If a new tool comes along, you won't need to find a new Emacs package for it.

Rich minibuffer interface

Easily manipulate per-search options with Isearch-like key bindings within the Urgrep minibuffer prompt.

Seamless support for TRAMP

Each host can use a different set of tools depending on what the system has installed without any special configuration.

Using Urgrep

The primary entry point to Urgrep is the interactive function urgrep. This prompts you for a query to search for in, by default, the root directory of the current project (or the default-directory if there is no project). By prefixing with C-u, this will always start the search within the default-directory. With C-u C-u, Urgrep will allow you to enter the base directory. Within the search prompt, there are several Isearch-like key bindings to let you modify the search's behavior:

Key binding Action M-s r Toggle regexp search M-s c Toggle case sensitivity M-s f Set wildcards to filter files¹ M-s C Set number of lines of context² M-s B Set number of lines of leading context² M-s A Set number of lines of trailing context²
  1. Prompts with a recursive minibuffer
  2. With a numeric prefix argument, set immediately; otherwise, use a recursive minibuffer

In addition to the above, you can call urgrep-run-command, which works like urgrep but allows you to manually edit the command before executing it.

Configuring the tool to use

By default, Urgrep tries all search tools it's aware of to find the best option. To improve performance, you can restrict the set of tools to search for by setting urgrep-preferred-tools:

(setq urgrep-preferred-tools '(git-grep grep))

This also works with connection-local variables:

(connection-local-set-profile-variables 'urgrep-ripgrep
 '((urgrep-preferred-tools . (ripgrep))))

(connection-local-set-profiles
 '(:application tramp :machine "coco") 'urgrep-ripgrep)

Programmatic interface

In addition to interactive use, Urgrep is designed to allow for programmatic use, returning a command to execute with the specified query and options: urgrep-command. This takes a query as well as several optional keyword arguments. For more information, consult the docstring for urgrep-command.

Contributing

Feedback is welcome, but it's a bit early for code contributions. Thanks for the thought, though! (Hopefully this will change after not too long.)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK