completion/selectrum -> completion/vertico, part 2

- Rename module from `:completion selectrum` to `:completion vertico`
- Rename all files involved
- Do *not* yet rename all the functions, as that messes up git's rename
  detection.
This commit is contained in:
Itai Y. Efrat 2021-07-09 20:16:11 +03:00
parent f9e1c99b2b
commit 24eaa1317c
33 changed files with 79 additions and 90 deletions

View file

@ -0,0 +1,14 @@
;; completion/vertico/autoload/evil.el -*- lexical-binding: t; -*-
;;;###if (featurep! :editor evil)
;;;###autoload (autoload '+selectrum:project-search "completion/vertico/autoload/evil" nil t)
(evil-define-command +selectrum:project-search (query &optional all-files-p)
"Ex interface for `+selectrum/project-search'."
(interactive "<a><!>")
(+selectrum/project-search all-files-p query))
;;;###autoload (autoload '+selectrum:project-search-from-cwd "completion/vertico/autoload/evil" nil t)
(evil-define-command +selectrum:project-search-from-cwd (query &optional recurse-p)
"Ex interface for `+selectrum/project-search-from-cwd'."
(interactive "<a><!>")
(+selectrum/project-search-from-cwd (not recurse-p) query))

View file

@ -0,0 +1,135 @@
;;; completion/vertico/autoload/vertico.el -*- lexical-binding: t; -*-
;;;###autoload
(defadvice! +selectrum--company-capf--candidates-a (fn &rest args)
"Highlight company matches correctly, and try default completion styles before
orderless."
:around 'company-capf--candidates
(let ((orderless-match-faces [completions-common-part])
(completion-styles '(basic partial-completion orderless)))
(apply fn args)))
;;;###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
Sets what directory to base the search out of. Defaults to the current project's root.
: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)
(setq deactivate-mark t)
(let* ((project-root (or (doom-project-root) default-directory))
(directory (or in project-root))
(args (split-string
(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 " ")))
" "))
(prompt (or prompt
(format "rg [%s]: "
(cond ((equal directory default-directory)
"./")
((equal directory project-root)
(projectile-project-name))
((file-relative-name directory project-root))))))
(query (or query
(when (doom-region-active-p)
(replace-regexp-in-string
"[! |]" (lambda (substr)
(cond ((and (string= substr " ")
(not (featurep! +fuzzy)))
" ")
((string= substr "|")
"\\\\\\\\|")
((concat "\\\\" substr))))
(rxt-quote-pcre (doom-thing-at-point-or-region))))))
(ripgrep-command (mapconcat #'identity `("rg" ,@args "." "-e ARG OPTS" ) " ")))
(consult--grep prompt ripgrep-command directory query)))
;;;###autoload
(defun +selectrum/project-search (&optional arg initial-query directory)
"Peforms a live project search from the project root using ripgrep.
If ARG (universal argument), include all files, even hidden or compressed ones,
in the search."
(interactive "P")
(+selectrum-file-search :query initial-query :in directory :all-files arg))
;;;###autoload
(defun +selectrum/project-search-from-cwd (&optional arg initial-query)
"Performs a live project search from the current directory.
If ARG (universal argument), include all files, even hidden or compressed ones."
(interactive "P")
(+selectrum/project-search arg initial-query default-directory))
;;;###autoload
(defun +selectrum/search-symbol-at-point ()
(interactive)
(consult-line (thing-at-point 'symbol)))
;;;###autoload
(defun +selectrum/backward-updir ()
"Delete char before or go up directory for file cagetory vertico buffers."
(interactive)
(let ((metadata (completion-metadata (minibuffer-contents)
minibuffer-completion-table
minibuffer-completion-predicate)))
(if (and (eq (char-before) ?/)
(eq (completion-metadata-get metadata 'category) 'file))
(let ((new-path (minibuffer-contents)))
(delete-region (minibuffer-prompt-end) (point-max))
(insert (abbreviate-file-name
(file-name-directory
(directory-file-name
(expand-file-name new-path))))))
(call-interactively 'backward-delete-char))))
;;;###autoload
(defun +selectrum/embark-export-write ()
"Export the current vertico results to a writable buffer if possible.
Supports exporting consult-grep to wgrep, file to wdeired, and consult-location to occur-edit"
(interactive)
(require 'wgrep)
(pcase-let ((`(,type . ,candidates)
(run-hook-with-args-until-success 'embark-candidate-collectors)))
(pcase type
('consult-grep (let ((embark-after-export-hook #'wgrep-change-to-wgrep-mode))
(embark-export)))
('file (let ((embark-after-export-hook #'wdired-change-to-wdired-mode))
(embark-export)))
('consult-location (let ((embark-after-export-hook #'occur-edit-mode))
(embark-export)))
(x (user-error "embark category %S doesn't support writable export" x)))))
;;;###autoload
(defun +selectrum/embark-preview ()
"Previews candidate in vertico buffer, unless it's a consult command"
(interactive)
(unless (bound-and-true-p consult--preview-function)
(save-selected-window
(let ((embark-quit-after-action nil))
(embark-default-action)))))
;;;###autoload
(defun +selectrum/next-candidate-preview ()
"Move to next candidate and preivew it"
(interactive)
(vertico-next)
(+selectrum/embark-preview))
;;;###autoload
(defun +selectrum/previous-candidate-preview ()
"Move to previous candidate and preview it"
(interactive)
(vertico-previous)
(+selectrum/embark-preview))

View file

@ -0,0 +1,53 @@
;;; completion/vertico/autoload/workspaces.el -*- lexical-binding: t; -*-
;;;###if (featurep! :ui workspaces)
;;;###autoload
(defun +selectrum--workspace-nth-source (n)
"Generate a consult buffer source for buffers in the NTH workspace"
(cond ((numberp n)
`(:name ,(nth n (+workspace-list-names))
:hidden ,(not (string= (+workspace-current-name) (nth n (+workspace-list-names))))
:narrow ,(string-to-char (number-to-string (1+ n)))
:category buffer
:state ,#'consult--buffer-state
:items ,(lambda () (mapcar #'buffer-name (+workspace-buffer-list (nth n (+workspace-list)))))))
((eq n 'final)
`(:name ,(car (last (+workspace-list-names)))
:hidden t
:narrow ?0
:category buffer
:state ,#'consult--buffer-state
:items ,(lambda () (mapcar #'buffer-name (+workspace-buffer-list (car (last (+workspace-list))))))))
(t
(user-error "invalid workspace source %s" n))))
;;;###autoload
(defun +selectrum--workspace-generate-sources ()
"Generate list of consult buffer sources for all workspaces"
(mapcar #'+selectrum--workspace-nth-source '(0 1 2 3 4 5 6 7 8 final)))
(autoload 'consult--multi "consult")
;;;###autoload
(defun +selectrum/switch-workspace-buffer ()
"Switch to another buffer in the same workspace.
Use consult narrowing with another workspace number to open a buffer from that workspace
BUG but it opens it in the current workspace (ivy also does this, but who cares)"
(interactive)
(when-let (buffer (consult--multi (+selectrum--workspace-generate-sources)
:require-match
(confirm-nonexistent-file-or-buffer)
:prompt (format "Switch to buffer (%s): "
(+workspace-current-name)
:history 'consult--buffer-history
:sort nil)))
;; When the buffer does not belong to a source,
;; create a new buffer with the name.
(unless (cdr buffer)
(funcall consult--buffer-display (car buffer)))))
;;;###autoload
(defun +selectrum-embark-open-in-new-workspace (x)
"Open X (a file) in a new workspace."
(+workspace/new)
(find-file x))