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))