2017-11-04 22:11:55 +01:00
|
|
|
;; completion/ivy/autoload/evil.el -*- lexical-binding: t; -*-
|
|
|
|
;;;###if (featurep! :feature evil)
|
2017-02-19 18:41:37 -05:00
|
|
|
|
|
|
|
;;;###autoload (autoload '+ivy:swiper "completion/ivy/autoload/evil" nil t)
|
|
|
|
(evil-define-command +ivy:swiper (&optional search)
|
|
|
|
"Invoke `swiper' with SEARCH, otherwise with the symbol at point."
|
|
|
|
(interactive "<a>")
|
2017-05-10 05:21:53 +02:00
|
|
|
(swiper search))
|
2017-05-10 06:13:14 +02:00
|
|
|
|
|
|
|
;;;###autoload (autoload '+ivy:todo "completion/ivy/autoload/evil" nil t)
|
|
|
|
(evil-define-command +ivy:todo (&optional bang)
|
|
|
|
"An ex wrapper around `+ivy/tasks'."
|
|
|
|
(interactive "<!>")
|
|
|
|
(+ivy/tasks bang))
|
2017-05-12 11:50:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
;; --- file searching ---------------------
|
|
|
|
|
|
|
|
(defvar +ivy--file-last-search nil)
|
|
|
|
(defvar +ivy--file-search-recursion-p t)
|
|
|
|
(defvar +ivy--file-search-all-files-p nil)
|
|
|
|
|
2017-06-08 11:47:56 +02:00
|
|
|
(defun +ivy--file-search (engine beg end query &optional directory)
|
2017-07-08 13:54:44 +02:00
|
|
|
(let* ((project-root (doom-project-root))
|
|
|
|
(directory (or directory project-root))
|
2017-05-12 11:50:05 +02:00
|
|
|
(recursion-p +ivy--file-search-recursion-p)
|
|
|
|
(all-files-p +ivy--file-search-all-files-p)
|
2017-11-04 22:35:41 +01:00
|
|
|
(engine (or engine
|
|
|
|
(and (executable-find "rg") 'rg)
|
|
|
|
(and (executable-find "ag") 'ag)))
|
2017-05-12 11:50:05 +02:00
|
|
|
(query
|
|
|
|
(or query
|
2017-10-04 18:07:26 +02:00
|
|
|
(if (evil-visual-state-p)
|
|
|
|
(and beg end
|
|
|
|
(> (abs (- end beg)) 1)
|
|
|
|
(rxt-quote-pcre (buffer-substring-no-properties beg end)))
|
|
|
|
+ivy--file-last-search)
|
2017-05-12 11:50:05 +02:00
|
|
|
+ivy--file-last-search))
|
|
|
|
(prompt
|
|
|
|
(format "%s%%s %s"
|
|
|
|
(symbol-name engine)
|
|
|
|
(cond ((equal directory default-directory)
|
|
|
|
"./")
|
|
|
|
((equal directory project-root)
|
|
|
|
(projectile-project-name))
|
|
|
|
(t
|
2018-01-04 16:12:35 -05:00
|
|
|
(file-relative-name directory project-root)))))
|
|
|
|
(default-directory directory))
|
2017-05-12 11:50:05 +02:00
|
|
|
(setq +ivy--file-last-search query)
|
2018-01-28 22:24:16 -05:00
|
|
|
(require 'counsel)
|
2017-07-08 13:54:44 +02:00
|
|
|
(pcase engine
|
|
|
|
('ag
|
|
|
|
(let ((args (concat
|
|
|
|
(if all-files-p " -a")
|
|
|
|
(unless recursion-p " -n"))))
|
|
|
|
(counsel-ag query directory args (format prompt args))))
|
|
|
|
('rg
|
|
|
|
;; smart-case instead of case-insensitive flag
|
|
|
|
(let ((counsel-rg-base-command
|
|
|
|
(replace-regexp-in-string " -i " " -S " counsel-rg-base-command))
|
|
|
|
(args (concat
|
|
|
|
(if all-files-p " -uu")
|
2017-12-08 22:49:58 -05:00
|
|
|
(unless recursion-p " --maxdepth 1"))))
|
2017-07-08 13:54:44 +02:00
|
|
|
(counsel-rg query directory args (format prompt args))))
|
|
|
|
('pt) ;; TODO pt search engine (necessary?)
|
|
|
|
(_ (error "No search engine specified")))))
|
2017-05-12 11:50:05 +02:00
|
|
|
|
|
|
|
;;;###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
|
2017-05-27 14:47:59 +02:00
|
|
|
regexp. If omitted, the current selection is used. If no selection is active,
|
|
|
|
the last known search is used.
|
2017-05-12 11:50:05 +02:00
|
|
|
|
|
|
|
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 'ag beg end query directory)))
|
|
|
|
|
|
|
|
;;;###autoload (autoload '+ivy:rg "completion/ivy/autoload/evil" nil t)
|
|
|
|
(evil-define-operator +ivy:rg (beg end query &optional all-files-p directory)
|
|
|
|
"Perform a project file search using ripgrep. QUERY is a regexp. If omitted,
|
2017-05-27 14:47:59 +02:00
|
|
|
the current selection is used. If no selection is active, the last known search
|
|
|
|
is used.
|
2017-05-12 11:50:05 +02:00
|
|
|
|
2017-05-27 14:47:59 +02:00
|
|
|
If ALL-FILES-P, don't respect .gitignore files and search everything.
|
|
|
|
|
|
|
|
NOTE: ripgrep doesn't support multiline searches (yet)."
|
2017-05-12 11:50:05 +02:00
|
|
|
(interactive "<r><a><!>")
|
|
|
|
(let ((+ivy--file-search-all-files-p all-files-p))
|
|
|
|
(+ivy--file-search 'rg beg end query directory)))
|
|
|
|
|
|
|
|
|
|
|
|
;;;###autoload (autoload '+ivy:ag-cwd "completion/ivy/autoload/evil" nil t)
|
2017-05-27 14:47:59 +02:00
|
|
|
(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
|
|
|
|
into sub-directories."
|
2017-05-12 11:50:05 +02:00
|
|
|
(interactive "<r><a><!>")
|
2017-05-27 14:47:59 +02:00
|
|
|
(let ((+ivy--file-search-recursion-p (not bang)))
|
2017-05-12 11:50:05 +02:00
|
|
|
(+ivy:ag beg end query t default-directory)))
|
|
|
|
|
|
|
|
;;;###autoload (autoload '+ivy:rg-cwd "completion/ivy/autoload/evil" nil t)
|
2017-05-27 14:47:59 +02:00
|
|
|
(evil-define-operator +ivy:rg-cwd (beg end query &optional bang)
|
|
|
|
"The same as :rg, but only searches the current directory. If BANG, don't
|
|
|
|
recurse into sub-directories.
|
|
|
|
|
|
|
|
NOTE: ripgrep doesn't support multiline searches (yet)."
|
2017-05-12 11:50:05 +02:00
|
|
|
(interactive "<r><a><!>")
|
2017-05-27 14:47:59 +02:00
|
|
|
(let ((+ivy--file-search-recursion-p (not bang)))
|
2017-05-12 11:50:05 +02:00
|
|
|
(+ivy:rg beg end query t default-directory)))
|