Add ripgrep support

* Add rg to helm completion layer
* Add rg to ivy layer
* Prepend rg to dotspacemacs-search-tools
* Add rg to documentation
This commit is contained in:
Aron Griffis 2016-10-19 20:29:06 -04:00 committed by bmag
parent c82239a45f
commit 385c12743a
6 changed files with 81 additions and 19 deletions

View File

@ -326,9 +326,9 @@ to aggressively delete empty lines and long sequences of whitespace, `trailing'
to delete only the whitespace at end of lines, `changed' to delete only to delete only the whitespace at end of lines, `changed' to delete only
whitespace for changed lines or `nil' to disable cleanup.") whitespace for changed lines or `nil' to disable cleanup.")
(defvar dotspacemacs-search-tools '("ag" "pt" "ack" "grep") (defvar dotspacemacs-search-tools '("rg" "ag" "pt" "ack" "grep")
"List of search tool executable names. Spacemacs uses the first installed "List of search tool executable names. Spacemacs uses the first installed
tool of the list. Supported tools are `ag', `pt', `ack' and `grep'.") tool of the list. Supported tools are `rg', `ag', `pt', `ack' and `grep'.")
(defvar dotspacemacs-default-package-repository 'melpa-stable (defvar dotspacemacs-default-package-repository 'melpa-stable
"The default package repository used if no explicit repository has been "The default package repository used if no explicit repository has been

View File

@ -2289,10 +2289,11 @@ You can toggle auto-save in a buffer by calling the command =auto-save-mode=.
** Searching ** Searching
*** With an external tool *** With an external tool
Spacemacs can be interfaced with different search utilities like: Spacemacs can be interfaced with different search utilities like:
- ack - [[https://github.com/BurntSushi/ripgrep][rg]]
- grep
- [[https://github.com/ggreer/the_silver_searcher][ag]] - [[https://github.com/ggreer/the_silver_searcher][ag]]
- [[https://github.com/monochromegane/the_platinum_searcher][pt]] - [[https://github.com/monochromegane/the_platinum_searcher][pt]]
- [[http://beyondgrep.com/][ack]]
- grep
The search commands in Spacemacs are organized under the ~SPC s~ prefix with the The search commands in Spacemacs are organized under the ~SPC s~ prefix with the
next key is the tool to use and the last key is the scope. For instance ~SPC s a next key is the tool to use and the last key is the scope. For instance ~SPC s a
@ -2304,9 +2305,9 @@ a B~ will search with symbol under point (if there is no active region).
If the tool key is omitted then a default tool will be automatically selected If the tool key is omitted then a default tool will be automatically selected
for the search. This tool corresponds to the first tool found on the system of for the search. This tool corresponds to the first tool found on the system of
the list =dotspacemacs-search-tools=, the default order is =ag=, =pt=, =ack= the list =dotspacemacs-search-tools=, the default order is =rg=, =ag=, =pt=,
then =grep=. For instance ~SPC s b~ will search in the opened buffers using =pt= =ack= then =grep=. For instance ~SPC s b~ will search in the opened buffers
if =ag= has not been found on the system. using =pt= if =rg= and =ag= have not been found on the system.
The tool keys are: The tool keys are:
@ -2315,6 +2316,7 @@ The tool keys are:
| ag | a | | ag | a |
| grep | g | | grep | g |
| ack | k | | ack | k |
| rg | r |
| pt | t | | pt | t |
The available scopes and corresponding keys are: The available scopes and corresponding keys are:
@ -2330,7 +2332,7 @@ of the sequence, for instance ~SPC s a a~ will search in the current
file with =ag=. file with =ag=.
*Notes*: *Notes*:
- =ag= and =pt= are optimized to be used in a source control repository but - =rg=, =ag= and =pt= are optimized to be used in a source control repository but
they can be used in an arbitrary directory as well. they can be used in an arbitrary directory as well.
- It is also possible to search in several directories at once by marking - It is also possible to search in several directories at once by marking
them in the helm buffer. them in the helm buffer.
@ -2362,6 +2364,8 @@ bindings (~SPC e n~ and ~SPC e p~) as well as the error transient state (~SPC e~
| ~SPC s a A~ | =ag= with default input | | ~SPC s a A~ | =ag= with default input |
| ~SPC s g g~ | =grep= | | ~SPC s g g~ | =grep= |
| ~SPC s g G~ | =grep= with default input | | ~SPC s g G~ | =grep= with default input |
| ~SPC s r r~ | =rg= |
| ~SPC s r R~ | =rg= with default input |
**** Searching in all open buffers visiting files **** Searching in all open buffers visiting files
@ -2375,6 +2379,8 @@ bindings (~SPC e n~ and ~SPC e p~) as well as the error transient state (~SPC e~
| ~SPC s g B~ | =grep= with default text | | ~SPC s g B~ | =grep= with default text |
| ~SPC s k b~ | =ack= | | ~SPC s k b~ | =ack= |
| ~SPC s k B~ | =ack= with default text | | ~SPC s k B~ | =ack= with default text |
| ~SPC s r b~ | =rg= |
| ~SPC s r B~ | =rg= with default text |
| ~SPC s t b~ | =pt= | | ~SPC s t b~ | =pt= |
| ~SPC s t B~ | =pt= with default text | | ~SPC s t B~ | =pt= with default text |
@ -2390,6 +2396,8 @@ bindings (~SPC e n~ and ~SPC e p~) as well as the error transient state (~SPC e~
| ~SPC s g F~ | =grep= with default text | | ~SPC s g F~ | =grep= with default text |
| ~SPC s k f~ | =ack= | | ~SPC s k f~ | =ack= |
| ~SPC s k F~ | =ack= with default text | | ~SPC s k F~ | =ack= with default text |
| ~SPC s r f~ | =rg= |
| ~SPC s r F~ | =rg= with default text |
| ~SPC s t f~ | =pt= | | ~SPC s t f~ | =pt= |
| ~SPC s t F~ | =pt= with default text | | ~SPC s t F~ | =pt= with default text |
@ -2406,6 +2414,8 @@ bindings (~SPC e n~ and ~SPC e p~) as well as the error transient state (~SPC e~
| ~SPC s k P~ | =ack= with default text | | ~SPC s k P~ | =ack= with default text |
| ~SPC s t p~ | =pt= | | ~SPC s t p~ | =pt= |
| ~SPC s t P~ | =pt= with default text | | ~SPC s t P~ | =pt= with default text |
| ~SPC s r p~ | =rg= |
| ~SPC s r P~ | =rg= with default text |
*Hint*: It is also possible to search in a project without needing to open a *Hint*: It is also possible to search in a project without needing to open a
file beforehand. To do so use ~SPC p p~ and then ~C-s~ on a given project to file beforehand. To do so use ~SPC p p~ and then ~C-s~ on a given project to
@ -2789,8 +2799,8 @@ an ~occurrence~.
e p ESC ESC~ e p ESC ESC~
*** Replacing text in several files *** Replacing text in several files
If you have =ag=, =pt= or =ack= installed, replacing an occurrence of text in If you have =rg=, =ag=, =pt= or =ack= installed, replacing an occurrence of text
several files can be performed via [[https://github.com/syohex/emacs-helm-ag][helm-ag]]. in several files can be performed via [[https://github.com/syohex/emacs-helm-ag][helm-ag]].
Say you want to replace all =foo= occurrences by =bar= in your current Say you want to replace all =foo= occurrences by =bar= in your current
project: project:
@ -2800,8 +2810,8 @@ project:
- edit the occurrences then leave the =iedit state= - edit the occurrences then leave the =iedit state=
- press ~C-c C-c~ - press ~C-c C-c~
*Note*: In Spacemacs, =helm-ag= despite its name works with =ack= and =pt= as *Note*: In Spacemacs, =helm-ag= despite its name works with =rg=, =pt= and =ack=
well (but not with =grep=). as well (but not with =grep=).
*** Renaming files in a directory *** Renaming files in a directory
It is possible to batch rename files in a directory using =wdired= from an It is possible to batch rename files in a directory using =wdired= from an
@ -3006,6 +3016,7 @@ To search in a project see [[Searching in a project][project searching]].
| ~SPC s g p~ | run =grep= | | ~SPC s g p~ | run =grep= |
| ~SPC s k p~ | run =ack= | | ~SPC s k p~ | run =ack= |
| ~SPC s t p~ | run =pt= | | ~SPC s t p~ | run =pt= |
| ~SPC s r p~ | run =rg= |
*Note for Windows Users*: To enable fast indexing the GNU ~find~ or *Note for Windows Users*: To enable fast indexing the GNU ~find~ or
Cygwin ~find~ must be in your ~PATH~. Cygwin ~find~ must be in your ~PATH~.

View File

@ -242,6 +242,17 @@ Search for a search tool in the order provided by `dotspacemacs-search-tools'."
(interactive) (interactive)
(spacemacs//helm-do-ag-region-or-symbol 'spacemacs/helm-files-do-pt)) (spacemacs//helm-do-ag-region-or-symbol 'spacemacs/helm-files-do-pt))
(defun spacemacs/helm-files-do-rg (&optional dir)
"Search in files with `rg'."
(interactive)
(let ((helm-ag-base-command "rg --smart-case --no-heading --vimgrep"))
(helm-do-ag dir)))
(defun spacemacs/helm-files-do-rg-region-or-symbol ()
"Search in files with `rg' using a default input."
(interactive)
(spacemacs//helm-do-ag-region-or-symbol 'spacemacs/helm-files-do-rg))
(defun spacemacs/helm-files-smart-do-search (&optional default-inputp) (defun spacemacs/helm-files-smart-do-search (&optional default-inputp)
"Search in opened buffers using `dotspacemacs-search-tools'. "Search in opened buffers using `dotspacemacs-search-tools'.
Search for a search tool in the order provided by `dotspacemacs-search-tools' Search for a search tool in the order provided by `dotspacemacs-search-tools'
@ -294,6 +305,17 @@ Search for a search tool in the order provided by `dotspacemacs-search-tools'."
(interactive) (interactive)
(spacemacs//helm-do-ag-region-or-symbol 'spacemacs/helm-buffers-do-pt)) (spacemacs//helm-do-ag-region-or-symbol 'spacemacs/helm-buffers-do-pt))
(defun spacemacs/helm-buffers-do-rg (&optional _)
"Search in opened buffers with `rg'."
(interactive)
(let ((helm-ag-base-command "rg --smart-case --no-heading --vimgrep"))
(helm-do-ag-buffers)))
(defun spacemacs/helm-buffers-do-rg-region-or-symbol ()
"Search in opened buffers with `rg' using a default input."
(interactive)
(spacemacs//helm-do-ag-region-or-symbol 'spacemacs/helm-buffers-do-rg))
(defun spacemacs/helm-buffers-smart-do-search (&optional default-inputp) (defun spacemacs/helm-buffers-smart-do-search (&optional default-inputp)
"Search in opened buffers using `dotspacemacs-search-tools'. "Search in opened buffers using `dotspacemacs-search-tools'.
Search for a search tool in the order provided by `dotspacemacs-search-tools' Search for a search tool in the order provided by `dotspacemacs-search-tools'
@ -364,6 +386,23 @@ Search for a search tool in the order provided by `dotspacemacs-search-tools'."
'spacemacs/helm-files-do-pt dir) 'spacemacs/helm-files-do-pt dir)
(message "error: Not in a project.")))) (message "error: Not in a project."))))
(defun spacemacs/helm-project-do-rg ()
"Search in current project with `rg'."
(interactive)
(let ((dir (projectile-project-root)))
(if dir
(spacemacs/helm-files-do-rg dir)
(message "error: Not in a project."))))
(defun spacemacs/helm-project-do-rg-region-or-symbol ()
"Search in current project with `rg' using a default input."
(interactive)
(let ((dir (projectile-project-root)))
(if dir
(spacemacs//helm-do-ag-region-or-symbol
'spacemacs/helm-files-do-rg dir)
(message "error: Not in a project."))))
(defun spacemacs/helm-project-smart-do-search (&optional default-inputp) (defun spacemacs/helm-project-smart-do-search (&optional default-inputp)
"Search in current project using `dotspacemacs-search-tools'. "Search in current project using `dotspacemacs-search-tools'.
Search for a search tool in the order provided by `dotspacemacs-search-tools' Search for a search tool in the order provided by `dotspacemacs-search-tools'
@ -384,7 +423,7 @@ Search for a search tool in the order provided by `dotspacemacs-search-tools'."
(spacemacs/helm-project-smart-do-search t)) (spacemacs/helm-project-smart-do-search t))
;; This overrides the default C-s action in helm-projectile-switch-project ;; This overrides the default C-s action in helm-projectile-switch-project
;; to search using ag/pt/whatever instead of just grep ;; to search using rg/ag/pt/whatever instead of just grep
(with-eval-after-load 'helm-projectile (with-eval-after-load 'helm-projectile
(defun spacemacs/helm-project-smart-do-search-in-dir (dir) (defun spacemacs/helm-project-smart-do-search-in-dir (dir)
(interactive) (interactive)
@ -412,6 +451,8 @@ Search for a search tool in the order provided by `dotspacemacs-search-tools'."
"saB" 'spacemacs/helm-buffers-do-ag-region-or-symbol "saB" 'spacemacs/helm-buffers-do-ag-region-or-symbol
"skb" 'spacemacs/helm-buffers-do-ack "skb" 'spacemacs/helm-buffers-do-ack
"skB" 'spacemacs/helm-buffers-do-ack-region-or-symbol "skB" 'spacemacs/helm-buffers-do-ack-region-or-symbol
"srb" 'spacemacs/helm-buffers-do-rg
"srB" 'spacemacs/helm-buffers-do-rg-region-or-symbol
"stb" 'spacemacs/helm-buffers-do-pt "stb" 'spacemacs/helm-buffers-do-pt
"stB" 'spacemacs/helm-buffers-do-pt-region-or-symbol "stB" 'spacemacs/helm-buffers-do-pt-region-or-symbol
;; current file scope ;; current file scope
@ -426,6 +467,8 @@ Search for a search tool in the order provided by `dotspacemacs-search-tools'."
"saF" 'spacemacs/helm-files-do-ag-region-or-symbol "saF" 'spacemacs/helm-files-do-ag-region-or-symbol
"skf" 'spacemacs/helm-files-do-ack "skf" 'spacemacs/helm-files-do-ack
"skF" 'spacemacs/helm-files-do-ack-region-or-symbol "skF" 'spacemacs/helm-files-do-ack-region-or-symbol
"srf" 'spacemacs/helm-files-do-rg
"srF" 'spacemacs/helm-files-do-rg-region-or-symbol
"stf" 'spacemacs/helm-files-do-pt "stf" 'spacemacs/helm-files-do-pt
"stF" 'spacemacs/helm-files-do-pt-region-or-symbol "stF" 'spacemacs/helm-files-do-pt-region-or-symbol
;; current project scope ;; current project scope
@ -437,6 +480,8 @@ Search for a search tool in the order provided by `dotspacemacs-search-tools'."
"saP" 'spacemacs/helm-project-do-ag-region-or-symbol "saP" 'spacemacs/helm-project-do-ag-region-or-symbol
"skp" 'spacemacs/helm-project-do-ack "skp" 'spacemacs/helm-project-do-ack
"skP" 'spacemacs/helm-project-do-ack-region-or-symbol "skP" 'spacemacs/helm-project-do-ack-region-or-symbol
"srp" 'spacemacs/helm-project-do-rg
"srP" 'spacemacs/helm-project-do-rg-region-or-symbol
"stp" 'spacemacs/helm-project-do-pt "stp" 'spacemacs/helm-project-do-pt
"stP" 'spacemacs/helm-project-do-pt-region-or-symbol)) "stP" 'spacemacs/helm-project-do-pt-region-or-symbol))
:config :config

View File

@ -13,7 +13,8 @@
;; Variables ;; Variables
(defvar spacemacs--counsel-commands (defvar spacemacs--counsel-commands
'(("ag" . "ag --nocolor --nogroup %s %S .") '(("rg" . "rg --smart-case --no-heading --vimgrep %s %S .")
("ag" . "ag --nocolor --nogroup %s %S .")
("pt" . "pt -e --nocolor --nogroup %s %S .") ("pt" . "pt -e --nocolor --nogroup %s %S .")
("ack" . "ack --nocolor --nogroup %s %S .") ("ack" . "ack --nocolor --nogroup %s %S .")
("grep" . "grep -nrP %s %S .")) ("grep" . "grep -nrP %s %S ."))

View File

@ -165,6 +165,7 @@ that directory."
;; Define search functions for each tool ;; Define search functions for each tool
(cl-loop (cl-loop
for (tools tool-name) in '((dotspacemacs-search-tools "auto") for (tools tool-name) in '((dotspacemacs-search-tools "auto")
((list "rg") "rg")
((list "ag") "ag") ((list "ag") "ag")
((list "pt") "pt") ((list "pt") "pt")
((list "ack") "ack") ((list "ack") "ack")

View File

@ -77,10 +77,6 @@
"saF" 'spacemacs/search-ag-region-or-symbol "saF" 'spacemacs/search-ag-region-or-symbol
"sap" 'spacemacs/search-project-ag "sap" 'spacemacs/search-project-ag
"saP" 'spacemacs/search-project-ag-region-or-symbol "saP" 'spacemacs/search-project-ag-region-or-symbol
"stf" 'spacemacs/search-pt
"stF" 'spacemacs/search-pt-region-or-symbol
"stp" 'spacemacs/search-project-pt
"stP" 'spacemacs/search-project-pt-region-or-symbol
"sgf" 'spacemacs/search-grep "sgf" 'spacemacs/search-grep
"sgF" 'spacemacs/search-grep-region-or-symbol "sgF" 'spacemacs/search-grep-region-or-symbol
"sgp" 'counsel-git-grep "sgp" 'counsel-git-grep
@ -88,7 +84,15 @@
"skf" 'spacemacs/search-ack "skf" 'spacemacs/search-ack
"skF" 'spacemacs/search-ack-region-or-symbol "skF" 'spacemacs/search-ack-region-or-symbol
"skp" 'spacemacs/search-project-ack "skp" 'spacemacs/search-project-ack
"skP" 'spacemacs/search-project-ack-region-or-symbol) "skP" 'spacemacs/search-project-ack-region-or-symbol
"srf" 'spacemacs/search-rg
"srF" 'spacemacs/search-rg-region-or-symbol
"srp" 'spacemacs/search-project-rg
"srP" 'spacemacs/search-project-rg-region-or-symbol
"stf" 'spacemacs/search-pt
"stF" 'spacemacs/search-pt-region-or-symbol
"stp" 'spacemacs/search-project-pt
"stP" 'spacemacs/search-project-pt-region-or-symbol)
;; set additional ivy actions ;; set additional ivy actions
(ivy-set-actions (ivy-set-actions