Skip to content
Snippets Groups Projects
Commit 0e1a093c authored by Liu Miao's avatar Liu Miao
Browse files

add search functions

parent 8d382b98
No related branches found
No related tags found
No related merge requests found
......@@ -72,36 +72,6 @@
:bind (:map vertico-map
("DEL" . vertico-directory-delete-char))
:config
(cl-defun vetico/search-files (&key query path all-files (recursive t) prompt args)
"Conduct a file search using ripgrep.
:query STRING
The initial input to search for.
:path PATH
Set the base directory to search out of. Default to the current project's root.
:recursive BOOL
Wheather or not to search files recursively from the base directory."
(declare (indent defun))
(unless (executable-find "rg")
(user-error "Couldn't find ripgrep in your PATH"))
(require 'consult)
())
(defun vertico/search-project (&optional arg)
"Conduct a text search in the current project root.
If prefix ARG is set, include ignored/hidden files."
(interactive "P")
(let* ((projectile-project-root nil)
(disabled-command-function nil)
(current-prefix-arg (unless (eq arg 'other) arg))
(default-directory
(if (eq arg 'other)
(if-let (projects (projectile-relevant-known-projects))
(completing-read "Search project: " projects nil t)
(user-error "There are no known projects"))
default-directory)))
()))
;; Bind directory delete
(add-hook 'minibuffer-setup-hook #'vertico-repeat-save))
(use-package consult
......@@ -137,6 +107,39 @@ If prefix ARG is set, include ignored/hidden files."
consult-bookmark consult-recent-file
consult--source-recent-file consult--source-project-recent-file))
(defun completion/search--dir (&optional dir initial)
"Search directory.
DIR for the search directory.
INITIAL for the initial input."
(require 'consult)
(let ()
(cond ((executable-find "rg")
(consult-ripgrep dir initial))
((executable-find "grep")
(consult-grep dir initial))
(t (user-error "Couldn't find ripgrep or grep in PATH")))))
(defun completion/search-project ()
"Search current project."
(interactive)
(completion/search--dir nil nil))
(defun completion/search-project-at ()
"Search current project at point."
(interactive)
(completion/search--dir nil (thing-at-point 'symbol)))
(defun completion/search-current-dir ()
"Search current directory."
(interactive)
(completion/search--dir default-directory nil))
(defun completion/search-current-dir-at ()
"Search current directory at point."
(interactive)
(completion/search--dir default-directory (thing-at-point 'symbol)))
(use-package corfu
:ensure t
;; Optional customizations
......
......@@ -116,8 +116,11 @@
"pp" 'projectile-switch-project
;; Searching
"si" #'imenu
"sp" #'consult-ripgrep
"sp" #'completion/search-project
"sP" #'completion/search-project-at
"ss" #'consult-line
"sd" #'completion/search-current-dir
"sD" #'completion/search-current-dir-at
;; Flycheck
"en" 'flycheck-next-error
"ep" 'flycheck-previous-error
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment