2021-02-16 16:46:35 -06:00
|
|
|
;;; completion/selectrum/autoload/selectrum.el -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defadvice! +selectrum--company-capf--candidates-a (fn &rest args)
|
|
|
|
"Function to help company to highlight all candidates with just
|
|
|
|
one face."
|
|
|
|
:around 'company-capf--candidates
|
|
|
|
(let ((orderless-match-faces [completions-common-part]))
|
|
|
|
(apply fn args)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defadvice! +selectrum--+default/yank-pop-a (&rest _)
|
|
|
|
"Interactively select what text to insert from the kill ring."
|
|
|
|
:override '+default/yank-pop
|
|
|
|
(interactive "P")
|
|
|
|
(call-interactively
|
|
|
|
(cond ((fboundp 'counsel-yank-pop) #'counsel-yank-pop)
|
|
|
|
((fboundp 'consult-yank-pop) #'consult-yank-pop)
|
|
|
|
((fboundp 'helm-show-kill-ring) #'helm-show-kill-ring)
|
|
|
|
((error "No kill-ring search backend available. Enable ivy or helm!")))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defadvice! +selectrum--+default/search-project-a (&optional arg)
|
|
|
|
"Conduct a text search in the current project root.
|
|
|
|
If prefix ARG is set, include ignored/hidden files."
|
|
|
|
:override '+default/search-project
|
|
|
|
(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)))
|
|
|
|
(call-interactively
|
|
|
|
(cond ((featurep! :completion ivy) #'+ivy/project-search)
|
|
|
|
((featurep! :completion helm) #'+helm/project-search)
|
|
|
|
((fboundp 'consult--grep) #'+selectrum/project-search)
|
|
|
|
(#'projectile-ripgrep)))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defadvice! +selectrum--+default/search-cwd-a (&optional arg)
|
|
|
|
"Conduct a text search in files under the current folder.
|
|
|
|
If prefix ARG is set, prompt for a directory to search from."
|
|
|
|
:override '+default/search-cwd
|
|
|
|
(interactive "P")
|
|
|
|
(let ((default-directory
|
|
|
|
(if arg
|
|
|
|
(read-directory-name "Search directory: ")
|
|
|
|
default-directory)))
|
|
|
|
(call-interactively
|
|
|
|
(cond ((featurep! :completion ivy) #'+ivy/project-search-from-cwd)
|
|
|
|
((featurep! :completion helm) #'+helm/project-search-from-cwd)
|
|
|
|
((fboundp 'consult--grep) #'+selectrum/project-search-from-cwd)
|
|
|
|
(#'rgrep)))))
|
|
|
|
|
2021-01-16 20:21:50 +08:00
|
|
|
;;;###autoload
|
|
|
|
(cl-defun +selectrum-file-search (&key query in all-files (recursive t) prompt args)
|
|
|
|
"Conduct a file search using ripgrep.
|
|
|
|
:query STRING
|
|
|
|
Determines the initial input to search for.
|
|
|
|
:in PATH
|
2021-02-16 16:46:35 -06:00
|
|
|
Sets what directory to base the search out of. Defaults to the current
|
|
|
|
project's root.
|
2021-01-16 20:21:50 +08:00
|
|
|
:recursive BOOL
|
|
|
|
Whether 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)
|
2021-02-16 16:46:35 -06:00
|
|
|
(let* ((this-command 'consult-ripgrep)
|
2021-01-16 20:21:50 +08:00
|
|
|
(project-root (or (doom-project-root) default-directory))
|
|
|
|
(directory (or in project-root))
|
2021-02-16 16:46:35 -06:00
|
|
|
(ripgrep-command (seq-remove 'null
|
|
|
|
(append (butlast consult-ripgrep-command)
|
|
|
|
(list
|
|
|
|
(when all-files "-uu")
|
|
|
|
(unless recursive " --maxdepth 1")
|
|
|
|
"--hidden"
|
|
|
|
"-g!.git")
|
|
|
|
args
|
|
|
|
'("-e"))))
|
2021-01-16 20:21:50 +08:00
|
|
|
(prompt (or prompt
|
2021-02-16 16:46:35 -06:00
|
|
|
(format "%s [%s]: "
|
|
|
|
(mapconcat #'identity ripgrep-command " ")
|
|
|
|
(cond ((equal directory default-directory) "./")
|
|
|
|
((equal directory project-root) (projectile-project-name))
|
2021-01-16 20:21:50 +08:00
|
|
|
((file-relative-name directory project-root))))))
|
|
|
|
(query (or query
|
|
|
|
(when (doom-region-active-p)
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"[! |]" (lambda (substr)
|
2021-02-16 16:46:35 -06:00
|
|
|
(cond ((string= substr " ") " ")
|
|
|
|
((string= substr "|") "\\\\\\\\|")
|
2021-01-16 20:21:50 +08:00
|
|
|
((concat "\\\\" substr))))
|
2021-02-16 16:46:35 -06:00
|
|
|
(rxt-quote-pcre (doom-thing-at-point-or-region))))
|
|
|
|
" ")))
|
|
|
|
;; (setq deactivate-mark t)
|
2021-01-16 20:21:50 +08:00
|
|
|
(consult--grep prompt ripgrep-command directory query)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +selectrum/project-search (&optional arg initial-query directory)
|
2021-02-16 16:46:35 -06:00
|
|
|
"Performs a live project search from the project root using ripgrep.
|
2021-01-16 20:21:50 +08:00
|
|
|
If ARG (universal argument), include all files, even hidden or compressed ones,
|
|
|
|
in the search."
|
|
|
|
(interactive "P")
|
2021-02-16 16:46:35 -06:00
|
|
|
(+selectrum-file-search
|
|
|
|
: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))
|
2021-01-16 20:21:50 +08:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +selectrum/project-search-from-cwd (&optional arg initial-query)
|
2021-02-16 16:46:35 -06:00
|
|
|
"Performs a project search recursively from the current directory.
|
2021-01-16 20:21:50 +08:00
|
|
|
If ARG (universal argument), include all files, even hidden or compressed ones."
|
|
|
|
(interactive "P")
|
|
|
|
(+selectrum/project-search arg initial-query default-directory))
|