completion/ivy: add grep/git-grep integration to evil+ivy (:grep/:grepc[wd])

This commit is contained in:
Henrik Lissner 2018-02-19 03:11:28 -05:00
parent 6f1b96bc9a
commit 20d97ffbaa
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 31 additions and 0 deletions

View file

@ -49,6 +49,16 @@
(setq +ivy--file-last-search query)
(require 'counsel)
(pcase engine
('grep
(let ((args (if recursion-p " -r"))
(counsel-projectile-grep-initial-input query))
(if all-files-p
(cl-letf (((symbol-function #'projectile-ignored-directories-rel)
(symbol-function #'ignore))
((symbol-function #'projectile-ignored-files-rel)
(symbol-function #'ignore)))
(counsel-projectile-grep args))
(counsel-projectile-grep args))))
('ag
(let ((args (concat
(if all-files-p " -a")
@ -65,6 +75,17 @@
('pt) ;; TODO pt search engine (necessary?)
(_ (error "No search engine specified")))))
;;;###autoload (autoload '+ivy:grep "completion/ivy/autoload/evil" nil t)
(evil-define-operator +ivy:grep (beg end query &optional all-files-p directory)
"Perform a project file search using grep (or git-grep in git repos). QUERY is
a grep regexp. If omitted, the current selection is used. If no selection is
active, the last known search is used.
If ALL-FILES-P, don't respect .gitignore files and search everything."
(interactive "<r><a><!>")
(let ((+ivy--file-search-all-files-p all-files-p))
(+ivy--file-search 'grep beg end query directory)))
;;;###autoload (autoload '+ivy:ag "completion/ivy/autoload/evil" nil t)
(evil-define-operator +ivy:ag (beg end query &optional all-files-p directory)
"Perform a project file search using the silver search. QUERY is a pcre
@ -90,6 +111,14 @@ NOTE: ripgrep doesn't support multiline searches (yet)."
(+ivy--file-search 'rg beg end query directory)))
;;;###autoload (autoload '+ivy:ag-cwd "completion/ivy/autoload/evil" nil t)
(evil-define-operator +ivy:grep-cwd (beg end query &optional bang)
"The same as :git, but searches the current directory. If BANG, don't recurse
into sub-directories."
(interactive "<r><a><!>")
(let ((+ivy--file-search-recursion-p (not bang)))
(+ivy:grep beg end query t default-directory)))
;;;###autoload (autoload '+ivy:ag-cwd "completion/ivy/autoload/evil" nil t)
(evil-define-operator +ivy:ag-cwd (beg end query &optional bang)
"The same as :ag, but searches the current directory. If BANG, don't recurse

View file

@ -78,6 +78,8 @@
(ex! "agc[wd]" #'+ivy:ag-cwd)
(ex! "rg" #'+ivy:rg)
(ex! "rgc[wd]" #'+ivy:rg-cwd)
(ex! "grep" #'+ivy:grep)
(ex! "grepc[wd]" #'+ivy:grep-cwd)
(ex! "sw[iper]" #'+ivy:swiper)
(ex! "todo" #'+ivy:todo))
((featurep! :completion helm)