From 4f34635e042633a8e34603ae16da09ecba86b6cf Mon Sep 17 00:00:00 2001 From: "Itai Y. Efrat" Date: Mon, 13 Dec 2021 02:19:56 +0200 Subject: [PATCH 1/5] refactor!(vertico): crm keybindings behaviour BREAKING CHANGE: This commit changes the behaviour of the TAB and RET keys in a consult-completing read multiple session, in order to make them more intuitive. The behaviour is now: - TAB: (unchanged) always select or deselect the current candidate, and if the candidate is selected, move the index to the next one (this allows for pressing TAB repeatedly to select multiple subsequent candidates). - RET: If no candidates have been selected, select the current candidate and exit the completion session. If some have been selected, disregard the current candidate and exit. - S-TAB: (new) like TAB, but the keeps the input. --- .../completion/vertico/autoload/vertico.el | 36 ++++++++++++++----- modules/completion/vertico/config.el | 3 +- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/modules/completion/vertico/autoload/vertico.el b/modules/completion/vertico/autoload/vertico.el index ba7bbe668..93f9f840c 100644 --- a/modules/completion/vertico/autoload/vertico.el +++ b/modules/completion/vertico/autoload/vertico.el @@ -208,20 +208,40 @@ targets." ;;;###autoload (defun +vertico/crm-select () - "Enter candidate in `consult-completing-read-multiple'" + "Toggle selection of current candidate in `consult-completing-read-multiple'. +If the candidate has been selected, move the index up by one, to allow for quick +selection of multiple subsequent candidates." (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)))) + (let* ((selected-p (get-text-property 0 'consult--crm-selected (vertico--candidate))) + (goto-idx (+ vertico--index (if selected-p 0 1)))) + (run-at-time 0 nil (cmd! (vertico--goto goto-idx) (vertico--exhibit)))) + (vertico-exit)) + +;;;###autoload +(defun +vertico/crm-select-keep-input () + "Like `+vertico/crm-select', but keeps the current minibuffer input." + (interactive) + (let* ((input (substring-no-properties (car vertico--input))) + (selected-p (get-text-property 0 'consult--crm-selected (vertico--candidate))) + (goto-idx (+ vertico--index (if selected-p 0 1)))) + (run-at-time 0 nil (cmd! (insert input) (vertico--exhibit) (vertico--goto goto-idx) (vertico--exhibit)))) (vertico-exit)) ;;;###autoload (defun +vertico/crm-exit () - "Enter candidate in `consult-completing-read-multiple'" + "Exit `consult-completing-read-multiple' session in a dwim way. +If there are no selected candidates, select the current candidate and exit. +If there are selected candidates, disregard the current candidate and exit." (interactive) - (run-at-time 0 nil #'vertico-exit) - (vertico-exit)) + (if (consult--crm-selected) + (progn + (when (minibuffer-contents) + (delete-minibuffer-contents) + (vertico--exhibit)) + (vertico--goto -1) + (vertico-exit)) + (run-at-time 0 nil #'vertico-exit) + (vertico-exit))) ;;;###autoload (defun +vertico--consult--fd-builder (input) diff --git a/modules/completion/vertico/config.el b/modules/completion/vertico/config.el index 4d64e47d0..378c3a43e 100644 --- a/modules/completion/vertico/config.el +++ b/modules/completion/vertico/config.el @@ -146,7 +146,8 @@ orderless." :items ,(lambda () (mapcar #'buffer-name (org-buffer-list))))) (add-to-list 'consult-buffer-sources '+vertico--consult-org-source 'append)) (map! :map consult-crm-map - :desc "Select candidate" "TAB" #'+vertico/crm-select + :desc "Select candidate" [tab] #'+vertico/crm-select + :desc "Select candidate and keep input" [backtab] #'+vertico/crm-select-keep-input :desc "Enter candidates" "RET" #'+vertico/crm-exit)) From 1e2d5485a97f6b11619422cf84c90be68ebb93de Mon Sep 17 00:00:00 2001 From: "Itai Y. Efrat" Date: Thu, 6 Jan 2022 15:48:56 +0200 Subject: [PATCH 2/5] bump: :completion vertico iyefrat/all-the-icons-completion@a0f34d68cc12 -> iyefrat/all-the-icons-completion@9e7d456b0934 minad/consult@cc8eff9578f5 -> minad/consult@0940ca016531 minad/marginalia@2fb2787bc302 -> minad/marginalia@9229d88ae475 minad/vertico@eedcb8478692 -> minad/vertico@a8fe9a0b2e15 oantolin/embark@e08899ef2e7f -> oantolin/embark@c9b26c2e18f0 --- modules/completion/vertico/packages.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/completion/vertico/packages.el b/modules/completion/vertico/packages.el index 37b89b732..f1ae94744 100644 --- a/modules/completion/vertico/packages.el +++ b/modules/completion/vertico/packages.el @@ -4,21 +4,21 @@ (package! vertico :recipe (:host github :repo "minad/vertico" :files ("*.el" "extensions/*.el")) - :pin "eedcb847869226701acaf9a36dce0a51d1b60862") + :pin "a8fe9a0b2e156e022136169a3159b4dad78b2439") (package! orderless :pin "1ccf74ffdbb0dd34caa63022e92f947c09c49c86") -(package! consult :pin "cc8eff9578f5d089735e8b7dd7a08732890ed648") +(package! consult :pin "0940ca016531f3412003c231b476e5023a510ff9") (package! consult-dir :pin "08f543ae6acbfc1ffe579ba1d00a5414012d5c0b") (when (featurep! :checkers syntax) (package! consult-flycheck :pin "0ad7e8ff15683a4d64b79c29b3fcf847edfe244b")) -(package! embark :pin "e08899ef2e7fb9c1ed4b4b21e44cd368561f91f9") -(package! embark-consult :pin "e08899ef2e7fb9c1ed4b4b21e44cd368561f91f9") +(package! embark :pin "c9b26c2e18f01ae401df6a69b7a0c1a6bc44b90c") +(package! embark-consult :pin "c9b26c2e18f01ae401df6a69b7a0c1a6bc44b90c") -(package! marginalia :pin "2fb2787bc302a5533e09bc558c76eb914e98543b") +(package! marginalia :pin "9229d88ae4757f3439e81f51799758c009838cb4") (package! wgrep :pin "f9687c28bbc2e84f87a479b6ce04407bb97cfb23") (when (featurep! +icons) - (package! all-the-icons-completion :pin "a0f34d68cc12330ab3992a7521f9caa1de3b8470")) + (package! all-the-icons-completion :pin "9e7d456b0934ecb568b6f05a8445e3f4ce32261f")) From 09add70efdbf99e941401783bb901b518a8f6669 Mon Sep 17 00:00:00 2001 From: "Itai Y. Efrat" Date: Tue, 11 Jan 2022 15:48:19 +0200 Subject: [PATCH 3/5] feat(vertico): add embark-collect-snapshot binding The C-c C-s binding mirrors the export and writable export bindings. embark-export is used for type specific exports (such as buffers to an ibuffer buffer), not for verbatim exports. This is most noticeable if you want to export a variable list, which gets you to an apropos buffer. if you just want a list of things to keep around, embark-collect-snapshot is the tool for the job, but having it be only on C-; S makes it harder to reach and less visible. C-c C-s is a nice visible thing to have around. --- modules/completion/vertico/README.org | 19 ++++++++++--------- modules/completion/vertico/config.el | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/completion/vertico/README.org b/modules/completion/vertico/README.org index 31fa9f611..f472b982d 100644 --- a/modules/completion/vertico/README.org +++ b/modules/completion/vertico/README.org @@ -79,15 +79,16 @@ Doom-specific additions: When in an active Vertico completion session, the following doom added keybindings are available: -| Keybind | Description | -|-----------------------+----------------------------------------------------| -| =C-k= | (evil) Go to previous candidate | -| =C-j= | (evil) Go to next candidate | -| =C-M-k= | (evil) Go to previous group | -| =C-M-j= | (evil) Go to next group | -| =C-;= or = a= | Open an ~embark-act~ menu to chose a useful action | -| =C-c C-;= | export the current candidate list to a buffer | -| =C-SPC= | Preview the current candidate | +| Keybind | Description | +|-----------------------+-------------------------------------------------------------------------------| +| =C-k= | (evil) Go to previous candidate | +| =C-j= | (evil) Go to next candidate | +| =C-M-k= | (evil) Go to previous group | +| =C-M-j= | (evil) Go to next group | +| =C-;= or = a= | Open an ~embark-act~ menu to chose a useful action | +| =C-c C-;= | ~embark-export~ the current candidate list (export to a type-specific buffer) | +| =C-c C-s= | ~embark-collect-snapsnot~ the current candidate list (collect verbatim) | +| =C-SPC= | Preview the current candidate | ~embark-act~ will prompt you with a =which-key= menu with useful commands on the selected candidate or candidate list, depending on the completion category. Note diff --git a/modules/completion/vertico/config.el b/modules/completion/vertico/config.el index 378c3a43e..a3a0b0708 100644 --- a/modules/completion/vertico/config.el +++ b/modules/completion/vertico/config.el @@ -172,6 +172,7 @@ orderless." (:map minibuffer-local-map "C-;" #'embark-act "C-c C-;" #'embark-export + "C-c C-s" #'embark-collect-snapshot :desc "Export to writable buffer" "C-c C-e" #'+vertico/embark-export-write) (:leader :desc "Actions" "a" #'embark-act)) ; to be moved to :config default if accepted From 6d31e392cd4f1268c9924715bb7a86a11f33c3fa Mon Sep 17 00:00:00 2001 From: "Itai Y. Efrat" Date: Tue, 11 Jan 2022 22:19:41 +0200 Subject: [PATCH 4/5] nit(vertico): lint embark-file-map bindings --- modules/completion/vertico/config.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/completion/vertico/config.el b/modules/completion/vertico/config.el index a3a0b0708..217920219 100644 --- a/modules/completion/vertico/config.el +++ b/modules/completion/vertico/config.el @@ -205,11 +205,11 @@ orderless." ("u" doom/help-package-homepage)) (setf (alist-get 'package embark-keymap-alist) #'+vertico/embark-doom-package-map) (map! (:map embark-file-map - :desc "Open target with sudo" "s" #'doom/sudo-find-file + :desc "Open target with sudo" "s" #'doom/sudo-find-file (:when (featurep! :tools magit) :desc "Open magit-status of target" "g" #'+vertico/embark-magit-status) (:when (featurep! :ui workspaces) - :desc "Open in new workspace" "TAB" #'+vertico/embark-open-in-new-workspace)))) + :desc "Open in new workspace" "TAB" #'+vertico/embark-open-in-new-workspace)))) (use-package! marginalia From f42f9233502b0ca9682cd1ccad4a3ceb5dedb6c2 Mon Sep 17 00:00:00 2001 From: "Itai Y. Efrat" Date: Tue, 11 Jan 2022 23:46:10 +0200 Subject: [PATCH 5/5] feat(vertico): add SPC s e to manual preview list --- modules/completion/vertico/config.el | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/completion/vertico/config.el b/modules/completion/vertico/config.el index 217920219..81c2c73ac 100644 --- a/modules/completion/vertico/config.el +++ b/modules/completion/vertico/config.el @@ -131,6 +131,7 @@ orderless." +default/search-project-for-symbol-at-point +default/search-cwd +default/search-other-cwd +default/search-notes-for-symbol-at-point + +default/search-emacsd consult--source-file consult--source-project-file consult--source-bookmark :preview-key (kbd "C-SPC")) (consult-customize