Merge pull request #5299 from iyefrat/vertico-improvements

Vertico improvements: theming, bugfixes, new bindings, adaptations to upstream changes
This commit is contained in:
Henrik Lissner 2021-07-31 04:34:41 -04:00 committed by GitHub
commit e65e2ea9e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 89 additions and 24 deletions

View file

@ -18,6 +18,7 @@
- [[#general][General]] - [[#general][General]]
- [[#jump-to-files-buffers-or-projects][Jump to files, buffers or projects]] - [[#jump-to-files-buffers-or-projects][Jump to files, buffers or projects]]
- [[#search][Search]] - [[#search][Search]]
- [[#consult-modifications][Consult modifications]]
- [[#marginalia][Marginalia]] - [[#marginalia][Marginalia]]
- [[#orderless-filtering][Orderless filtering]] - [[#orderless-filtering][Orderless filtering]]
- [[#configuration][Configuration]] - [[#configuration][Configuration]]
@ -182,6 +183,14 @@ or the last workspace by typing =0 SPC=.
| =SPC s P= | Search another project | | =SPC s P= | Search another project |
| =SPC s s= | Search the current buffer (incrementally) | | =SPC s s= | Search the current buffer (incrementally) |
** Consult modifications
This module modifies the default keybindings used in
~consult-completing-read-multiple~:
| Keybind | Description |
|---------+-------------------------------------------------------------|
| =TAB= | Select or deselect current candidate |
| =RET= | Enters selected candidates (also toggles current candidate) |
** Marginalia ** Marginalia
| Keybind | Description | | Keybind | Description |
|---------+---------------------------------| |---------+---------------------------------|

View file

@ -4,15 +4,25 @@
;;;###autoload ;;;###autoload
(defvar orderless-match-faces) (defvar orderless-match-faces)
;; To prevent "Defining as dynamic an already lexical var" from +vertico/embark-preview
;;;###autoload
(defvar embark-quit-after-action)
;;;###autoload ;;;###autoload
(defadvice! +vertico--company-capf--candidates-a (fn &rest args) (defadvice! +vertico--company-capf--candidates-a (fn &rest args)
"Highlight company matches correctly, and try default completion styles before "Highlight company matches correctly, and try default completion styles before
orderless." orderless."
:around 'company-capf--candidates :around #'company-capf--candidates
(let ((orderless-match-faces [completions-common-part]) (let ((orderless-match-faces [completions-common-part])
(completion-styles +vertico-company-completion-styles)) (completion-styles +vertico-company-completion-styles))
(apply fn args))) (apply fn args)))
;;;###autoload
(defadvice! +vertico--consult-recent-file-a (&rest _args)
"`consult-recent-file' needs to have `recentf-mode' on to work correctly"
:before #'consult-recent-file
(recentf-mode +1))
;;;###autoload ;;;###autoload
(cl-defun +vertico-file-search (&key query in all-files (recursive t) prompt args) (cl-defun +vertico-file-search (&key query in all-files (recursive t) prompt args)
"Conduct a file search using ripgrep. "Conduct a file search using ripgrep.
@ -140,7 +150,7 @@ Supports exporting consult-grep to wgrep, file to wdeired, and consult-location
(unless (bound-and-true-p consult--preview-function) (unless (bound-and-true-p consult--preview-function)
(save-selected-window (save-selected-window
(let ((embark-quit-after-action nil)) (let ((embark-quit-after-action nil))
(embark-default-action))))) (embark-dwim)))))
;;;###autoload ;;;###autoload
(defun +vertico/next-candidate-preview (&optional n) (defun +vertico/next-candidate-preview (&optional n)
@ -162,6 +172,7 @@ Supports exporting consult-grep to wgrep, file to wdeired, and consult-location
"Jump to file under DIR (recursive). "Jump to file under DIR (recursive).
If INITIAL is non-nil, use as initial input." If INITIAL is non-nil, use as initial input."
(interactive) (interactive)
(require 'consult)
(let* ((default-directory (or dir default-directory)) (let* ((default-directory (or dir default-directory))
(prompt-dir (consult--directory-prompt "Find" default-directory)) (prompt-dir (consult--directory-prompt "Find" default-directory))
(cmd (split-string-and-unquote consult-find-command " ")) (cmd (split-string-and-unquote consult-find-command " "))
@ -175,7 +186,7 @@ If INITIAL is non-nil, use as initial input."
:require-match t :require-match t
:initial (if initial (shell-quote-argument initial)) :initial (if initial (shell-quote-argument initial))
:add-history (thing-at-point 'filename) :add-history (thing-at-point 'filename)
:category '+vertico :category 'file
:history '(:input +vertico/find-file-in--history))))) :history '(:input +vertico/find-file-in--history)))))
;;;###autoload ;;;###autoload
@ -218,3 +229,39 @@ If INITIAL is non-nil, use as initial input."
(setq buffers nil) (setq buffers nil)
(with-current-buffer (switch-to-buffer (marker-buffer mark)) (with-current-buffer (switch-to-buffer (marker-buffer mark))
(goto-char (marker-position mark))))) (goto-char (marker-position mark)))))
;;;###autoload
(defun +vertico/embark-which-key-indicator ()
"An embark indicator that displays keymaps using which-key.
The which-key help message will show the type and value of the
current target followed by an ellipsis if there are further
targets."
(lambda (&optional keymap targets prefix)
(if (null keymap)
(kill-buffer which-key--buffer)
(which-key--show-keymap
(if (eq (caar targets) 'embark-become)
"Become"
(format "Act on %s '%s'%s"
(caar targets)
(embark--truncate-target (cdar targets))
(if (cdr targets) "" "")))
(if prefix (lookup-key keymap prefix) keymap)
nil nil t))))
;;;###autoload
(defun +vertico/crm-select ()
"Enter candidate in `consult-completing-read-multiple'"
(interactive)
(let ((idx vertico--index))
(unless (get-text-property 0 'consult--crm-selected (nth vertico--index vertico--candidates))
(setq idx (1+ idx)))
(run-at-time 0 nil (cmd! (vertico--goto idx) (vertico--exhibit))))
(vertico-exit))
;;;###autoload
(defun +vertico/crm-exit ()
"Enter candidate in `consult-completing-read-multiple'"
(interactive)
(run-at-time 0 nil #'vertico-exit)
(vertico-exit))

View file

@ -73,7 +73,7 @@ overrides `completion-styles' during company completion sessions.")
[remap locate] #'consult-locate [remap locate] #'consult-locate
[remap load-theme] #'consult-theme [remap load-theme] #'consult-theme
[remap man] #'consult-man [remap man] #'consult-man
[remap recentf-open-files] (cmd! (recentf-mode +1) (consult-recent-file)) [remap recentf-open-files] #'consult-recent-file
[remap switch-to-buffer] #'consult-buffer [remap switch-to-buffer] #'consult-buffer
[remap switch-to-buffer-other-window] #'consult-buffer-other-window [remap switch-to-buffer-other-window] #'consult-buffer-other-window
[remap switch-to-buffer-other-frame] #'consult-buffer-other-frame [remap switch-to-buffer-other-frame] #'consult-buffer-other-frame
@ -118,7 +118,10 @@ overrides `completion-styles' during company completion sessions.")
:category buffer :category buffer
:state ,#'consult--buffer-state :state ,#'consult--buffer-state
:items ,(lambda () (mapcar #'buffer-name (org-buffer-list))))) :items ,(lambda () (mapcar #'buffer-name (org-buffer-list)))))
(add-to-list 'consult-buffer-sources '+vertico--consult-org-source 'append))) (add-to-list 'consult-buffer-sources '+vertico--consult-org-source 'append))
(map! :map consult-crm-map
:desc "Select candidate" "TAB" #'+vertico/crm-select
:desc "Enter candidates" "RET" #'+vertico/crm-exit))
(use-package! consult-flycheck (use-package! consult-flycheck
@ -140,11 +143,7 @@ overrides `completion-styles' during company completion sessions.")
:config :config
(set-popup-rule! "^\\*Embark Export Grep" :size 0.35 :ttl 0 :quit nil) (set-popup-rule! "^\\*Embark Export Grep" :size 0.35 :ttl 0 :quit nil)
(setq embark-action-indicator (setq embark-indicator #'+vertico/embark-which-key-indicator)
(lambda (map _target)
(which-key--show-keymap "Embark" map nil nil 'no-paging)
#'which-key--hide-popup-ignore-command)
embark-become-indicator embark-action-indicator)
;; add the package! target finder before the file target finder, ;; add the package! target finder before the file target finder,
;; so we don't get a false positive match. ;; so we don't get a false positive match.
(let ((pos (or (cl-position (let ((pos (or (cl-position
@ -174,11 +173,19 @@ overrides `completion-styles' during company completion sessions.")
:config :config
(when (featurep! +icons) (when (featurep! +icons)
(add-hook 'marginalia-mode-hook #'all-the-icons-completion-marginalia-setup)) (add-hook 'marginalia-mode-hook #'all-the-icons-completion-marginalia-setup))
(advice-add #'marginalia--project-root :override #'doom-project-root)
(pushnew! marginalia-command-categories (pushnew! marginalia-command-categories
'(+default/find-file-under-here. file)
'(doom/find-file-in-emacsd . project-file)
'(doom/find-file-in-other-project . project-file)
'(doom/find-file-in-private-config . file)
'(doom/describe-active-minor-mode . minor-mode)
'(flycheck-error-list-set-filter . builtin)
'(persp-switch-to-buffer . buffer) '(persp-switch-to-buffer . buffer)
'(projectile-find-file . project-file) '(projectile-find-file . project-file)
'(doom/describe-active-minor-mode . minor-mode) '(projectile-recentf . project-file)
'(flycheck-error-list-set-filter . builtin))) '(projectile-switch-to-buffer . buffer)
'(projectile-switch-project . project-file)))
(use-package! embark-consult (use-package! embark-consult

View file

@ -4,22 +4,22 @@
(package! vertico (package! vertico
:recipe (:host github :repo "minad/vertico" :recipe (:host github :repo "minad/vertico"
:files ("*.el" "extensions/*.el")) :files ("*.el" "extensions/*.el"))
:pin "4a9029714e847832d3ecb3ae74a7049306924f2e") :pin "9de6709cddc09740d23d24fb425fa3c174d0e956")
(package! orderless :pin "1e84120a28525ccb47b602fc19b7afbeffbbe502") (package! orderless :pin "1e84120a28525ccb47b602fc19b7afbeffbbe502")
(package! consult :pin "28f9ba8bdfdb13257862a658715b6ceb96f4951e") (package! consult :pin "69bbd213dc8a98abe94a4f5b1920e3d689d31caa")
(when (featurep! :checkers syntax) (when (featurep! :checkers syntax)
(package! consult-flycheck :pin "92b259e6a8ebe6439f67d3d7ffa44b7e64b76478")) (package! consult-flycheck :pin "92b259e6a8ebe6439f67d3d7ffa44b7e64b76478"))
(package! embark :pin "be03ce9ce1630b32e29cc50118d058c05696cb35") (package! embark :pin "1a7e6b556142216fa5f9b897bd5eca73968f3c49")
(package! embark-consult :pin "be03ce9ce1630b32e29cc50118d058c05696cb35") (package! embark-consult :pin "1a7e6b556142216fa5f9b897bd5eca73968f3c49")
(package! marginalia :pin "a3a8edbf25db4b1e167f1fdff6f60a065d0bf9cb") (package! marginalia :pin "11235445365c6ab119acabe91828e9182097ece7")
(package! wgrep :pin "f9687c28bbc2e84f87a479b6ce04407bb97cfb23") (package! wgrep :pin "f9687c28bbc2e84f87a479b6ce04407bb97cfb23")
(when (featurep! +icons) (when (featurep! +icons)
(package! all-the-icons-completion (package! all-the-icons-completion
:recipe (:host github :repo "iyefrat/all-the-icons-completion") :recipe (:host github :repo "iyefrat/all-the-icons-completion")
:pin "24cdb3b42c6ca0a8926ad6958c76d7928fc559ce")) :pin "d1d4b2f0dfbfa94d33fe50e8089c06601adfe674"))

View file

@ -56,7 +56,7 @@
:desc "Jump to symbol in any workspace" "J" #'helm-lsp-global-workspace-symbol) :desc "Jump to symbol in any workspace" "J" #'helm-lsp-global-workspace-symbol)
(:when (featurep! :completion vertico) (:when (featurep! :completion vertico)
:desc "Jump to symbol in current workspace" "j" #'consult-lsp-symbols :desc "Jump to symbol in current workspace" "j" #'consult-lsp-symbols
:desc "Jump to symbol in any workspace" "J" (cmd! #'consult-lsp-symbols '(4))) :desc "Jump to symbol in any workspace" "J" (cmd!! #'consult-lsp-symbols 'all-workspaces))
(:when (featurep! :ui treemacs +lsp) (:when (featurep! :ui treemacs +lsp)
:desc "Errors list" "X" #'lsp-treemacs-errors-list :desc "Errors list" "X" #'lsp-treemacs-errors-list
:desc "Incoming call hierarchy" "y" #'lsp-treemacs-call-hierarchy :desc "Incoming call hierarchy" "y" #'lsp-treemacs-call-hierarchy
@ -118,7 +118,8 @@
((featurep! :completion ivy) #'swiper) ((featurep! :completion ivy) #'swiper)
((featurep! :completion helm) #'swiper)) ((featurep! :completion helm) #'swiper))
:desc "Search all open buffers" "B" :desc "Search all open buffers" "B"
(cond ((featurep! :completion ivy) #'swiper-all) (cond ((featurep! :completion vertico) (cmd!! #'consult-line-multi 'all-buffers))
((featurep! :completion ivy) #'swiper-all)
((featurep! :completion helm) #'swiper-all)) ((featurep! :completion helm) #'swiper-all))
:desc "Search current directory" "d" #'+default/search-cwd :desc "Search current directory" "d" #'+default/search-cwd
:desc "Search other directory" "D" #'+default/search-other-cwd :desc "Search other directory" "D" #'+default/search-other-cwd

View file

@ -386,7 +386,7 @@
:desc "Jump to symbol in any workspace" "J" #'helm-lsp-global-workspace-symbol) :desc "Jump to symbol in any workspace" "J" #'helm-lsp-global-workspace-symbol)
(:when (featurep! :completion vertico) (:when (featurep! :completion vertico)
:desc "Jump to symbol in current workspace" "j" #'consult-lsp-symbols :desc "Jump to symbol in current workspace" "j" #'consult-lsp-symbols
:desc "Jump to symbol in any workspace" "J" (cmd! #'consult-lsp-symbols '(4))) :desc "Jump to symbol in any workspace" "J" (cmd!! #'consult-lsp-symbols 'all-workspaces))
(:when (featurep! :ui treemacs +lsp) (:when (featurep! :ui treemacs +lsp)
:desc "Errors list" "X" #'lsp-treemacs-errors-list :desc "Errors list" "X" #'lsp-treemacs-errors-list
:desc "Incoming call hierarchy" "y" #'lsp-treemacs-call-hierarchy :desc "Incoming call hierarchy" "y" #'lsp-treemacs-call-hierarchy
@ -708,7 +708,8 @@
((featurep! :completion ivy) #'swiper) ((featurep! :completion ivy) #'swiper)
((featurep! :completion helm) #'swiper)) ((featurep! :completion helm) #'swiper))
:desc "Search all open buffers" "B" :desc "Search all open buffers" "B"
(cond ((featurep! :completion ivy) #'swiper-all) (cond ((featurep! :completion vertico) (cmd!! #'consult-line-multi 'all-buffers))
((featurep! :completion ivy) #'swiper-all)
((featurep! :completion helm) #'swiper-all)) ((featurep! :completion helm) #'swiper-all))
:desc "Search current directory" "d" #'+default/search-cwd :desc "Search current directory" "d" #'+default/search-cwd
:desc "Search other directory" "D" #'+default/search-other-cwd :desc "Search other directory" "D" #'+default/search-other-cwd

View file

@ -10,4 +10,4 @@
(when (featurep! :completion helm) (when (featurep! :completion helm)
(package! helm-lsp :pin "c2c6974dadfac459b1a69a1217441283874cea92")) (package! helm-lsp :pin "c2c6974dadfac459b1a69a1217441283874cea92"))
(when (featurep! :completion vertico) (when (featurep! :completion vertico)
(package! consult-lsp :pin "c882749e91e4de3bae17d825ac9950cc074b1595"))) (package! consult-lsp :pin "e8a50f2c94f40c86934ca2eaff007f9c00586272")))

View file

@ -1,5 +1,5 @@
;; -*- no-byte-compile: t; -*- ;; -*- no-byte-compile: t; -*-
;;; ui/doom/packages.el ;;; ui/doom/packages.el
(package! doom-themes :pin "5221b0600d9da16e0e3af332ff1fe2ef624f0af4") (package! doom-themes :pin "9e2680b9188ebd58c490598684bb7545ba01950d")
(package! solaire-mode :pin "030964f7c62696c8cfb29125df6e7649d2bf9aeb") (package! solaire-mode :pin "030964f7c62696c8cfb29125df6e7649d2bf9aeb")