fix(selectrum): Use jcf +selectrum-file-search
Co-authored-by: jcf <github@invetica.co.uk>
This commit is contained in:
parent
b4e1b2130c
commit
baa5b8f307
1 changed files with 25 additions and 32 deletions
|
@ -62,63 +62,56 @@ If prefix ARG is set, prompt for a directory to search from."
|
||||||
:query STRING
|
:query STRING
|
||||||
Determines the initial input to search for.
|
Determines the initial input to search for.
|
||||||
:in PATH
|
:in PATH
|
||||||
Sets what directory to base the search out of. Defaults to the current
|
Sets what directory to base the search out of. Defaults to the current project's root.
|
||||||
project's root.
|
|
||||||
:recursive BOOL
|
:recursive BOOL
|
||||||
Whether or not to search files recursively from the base directory."
|
Whether or not to search files recursively from the base directory."
|
||||||
(declare (indent defun))
|
(declare (indent defun))
|
||||||
(unless (executable-find "rg")
|
(unless (executable-find "rg")
|
||||||
(user-error "Couldn't find ripgrep in your PATH"))
|
(user-error "Couldn't find ripgrep in your PATH"))
|
||||||
(require 'consult)
|
(require 'consult)
|
||||||
(let* ((this-command 'consult-ripgrep)
|
(setq deactivate-mark t)
|
||||||
|
(let* ((this-command 'consult--grep)
|
||||||
(project-root (or (doom-project-root) default-directory))
|
(project-root (or (doom-project-root) default-directory))
|
||||||
(directory (or in project-root))
|
(directory (or in project-root))
|
||||||
(ripgrep-command (seq-remove 'null
|
|
||||||
(append (butlast consult-ripgrep-command)
|
|
||||||
(list
|
|
||||||
(when all-files "-uu")
|
|
||||||
(unless recursive " --maxdepth 1")
|
|
||||||
"--hidden"
|
|
||||||
"-g!.git")
|
|
||||||
args
|
|
||||||
'("-e"))))
|
|
||||||
(prompt (or prompt
|
(prompt (or prompt
|
||||||
(format "%s [%s]: "
|
(format "rg [%s]: "
|
||||||
(mapconcat #'identity ripgrep-command " ")
|
(cond ((equal directory default-directory)
|
||||||
(cond ((equal directory default-directory) "./")
|
"./")
|
||||||
((equal directory project-root) (projectile-project-name))
|
((equal directory project-root)
|
||||||
|
(projectile-project-name))
|
||||||
((file-relative-name directory project-root))))))
|
((file-relative-name directory project-root))))))
|
||||||
(query (or query
|
(query (or query
|
||||||
(when (doom-region-active-p)
|
(when (doom-region-active-p)
|
||||||
(replace-regexp-in-string
|
(replace-regexp-in-string
|
||||||
"[! |]" (lambda (substr)
|
"[! |]" (lambda (substr)
|
||||||
(cond ((string= substr " ") " ")
|
(cond ((and (string= substr " ")
|
||||||
((string= substr "|") "\\\\\\\\|")
|
(not (featurep! +fuzzy)))
|
||||||
|
" ")
|
||||||
|
((string= substr "|")
|
||||||
|
"\\\\\\\\|")
|
||||||
((concat "\\\\" substr))))
|
((concat "\\\\" substr))))
|
||||||
(rxt-quote-pcre (doom-thing-at-point-or-region))))
|
(rxt-quote-pcre (doom-thing-at-point-or-region))))))
|
||||||
" ")))
|
(ripgrep-command (format "rg %s . -e"
|
||||||
;; (setq deactivate-mark t)
|
(string-trim
|
||||||
|
(concat (if all-files "-uu")
|
||||||
|
(unless recursive "--maxdepth 1")
|
||||||
|
"--null --line-buffered --color=always --max-columns=500 --no-heading --line-number"
|
||||||
|
" --hidden -g!.git "
|
||||||
|
(mapconcat #'shell-quote-argument args " ")))
|
||||||
|
args)))
|
||||||
(consult--grep prompt ripgrep-command directory query)))
|
(consult--grep prompt ripgrep-command directory query)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +selectrum/project-search (&optional arg initial-query directory)
|
(defun +selectrum/project-search (&optional arg initial-query directory)
|
||||||
"Performs a live project search from the project root using ripgrep.
|
"Peforms a live project search from the project root using ripgrep.
|
||||||
If ARG (universal argument), include all files, even hidden or compressed ones,
|
If ARG (universal argument), include all files, even hidden or compressed ones,
|
||||||
in the search."
|
in the search."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(+selectrum-file-search
|
(+selectrum-file-search :query initial-query :in directory :all-files arg))
|
||||||
:prompt (format "Find text on project files \[%s\]"
|
|
||||||
(if (or (and (not directory) (doom-project-root))
|
|
||||||
(and directory (equal directory (doom-project-root))))
|
|
||||||
(projectile-project-name)
|
|
||||||
(file-relative-name (or directory (doom-project-root) default-directory))))
|
|
||||||
:query initial-query
|
|
||||||
:in directory
|
|
||||||
:all-files arg))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +selectrum/project-search-from-cwd (&optional arg initial-query)
|
(defun +selectrum/project-search-from-cwd (&optional arg initial-query)
|
||||||
"Performs a project search recursively from the current directory.
|
"Performs a live project search from the current directory.
|
||||||
If ARG (universal argument), include all files, even hidden or compressed ones."
|
If ARG (universal argument), include all files, even hidden or compressed ones."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(+selectrum/project-search arg initial-query default-directory))
|
(+selectrum/project-search arg initial-query default-directory))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue