Skip to content

Commit

Permalink
Add citar-vertico
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarcus committed May 10, 2022
1 parent db2b6d1 commit 46745a3
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions citar-vertico.el
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

0 comments on commit 46745a3

Please sign in to comment.