-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
;;; citar-vertico.el --- Keybinding remapping for vertico -*- lexical-binding: t; -*- | ||
;; | ||
;; Copyright (C) 2022 Bruce D'Arcus | ||
;; | ||
;; | ||
;; This file is not part of GNU Emacs. | ||
;; | ||
;;; Commentary: | ||
;; | ||
;; Remaps keybindings for using 'citar--multiple-select' with vertico. | ||
;; | ||
;;; Code: | ||
|
||
(require 'vertico) | ||
|
||
(defvar vertico--input) | ||
(defvar vertico--history-hash) | ||
(defvar vertico--lock-candidate) | ||
(declare-function vertico--exhibit "ext:vertico") | ||
(declare-function vertico--candidate "ext:vertico") | ||
|
||
(defun citar-vertico--candidate () | ||
"Return current candidate for Consult preview." | ||
(and vertico--input (vertico--candidate 'highlight))) | ||
|
||
(defun citar-vertico--refresh (&optional reset) | ||
"Refresh completion UI, keep current candidate unless RESET is non-nil." | ||
(when vertico--input | ||
(setq vertico--input t) | ||
(when reset | ||
(setq vertico--history-hash nil | ||
vertico--lock-candidate nil)) | ||
(vertico--exhibit))) | ||
|
||
(defun citar-vertico--crm-select () | ||
"Select/deselect candidate." | ||
(interactive) | ||
(when (let ((cand (vertico--candidate))) | ||
(and (vertico--match-p cand) (not (equal cand "")))) | ||
(vertico-exit))) | ||
|
||
(defun citar-vertico--crm-exit () | ||
"Select/deselect candidate and exit." | ||
(interactive) | ||
(when (let ((cand (vertico--candidate))) | ||
(and (vertico--match-p cand) (not (equal cand "")))) | ||
(run-at-time 0 nil #'exit-minibuffer)) | ||
(vertico-exit)) | ||
|
||
(defvar citar-vertico--crm-map | ||
(let ((map (make-sparse-keymap))) | ||
(define-key map [remap vertico-insert] #'citar-vertico--crm-select) | ||
(define-key map [remap exit-minibuffer] #'citar-vertico--crm-exit) | ||
map)) | ||
|
||
(defun consult-vertico--crm-setup () | ||
"Setup crm for Vertico." | ||
(when vertico--input | ||
(use-local-map (make-composed-keymap (list consult-vertico--crm-map) (current-local-map))))) | ||
|
||
(add-hook 'citar--completion-candidate-hook #'citar-vertico--candidate) | ||
(add-hook 'citar--completion-refresh-hook #'citar-vertico--refresh) | ||
(add-hook 'citar--crm-setup-hook #'citar-vertico--crm-setup) | ||
|
||
(provide 'citar-vertico) | ||
;;; citar-vertico.el ends here |