[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vertico dbd7202 1/3: Reduce vertico-mouse allocations
From: |
ELPA Syncer |
Subject: |
[elpa] externals/vertico dbd7202 1/3: Reduce vertico-mouse allocations |
Date: |
Tue, 26 Oct 2021 11:57:29 -0400 (EDT) |
branch: externals/vertico
commit dbd7202c16e396e2afc5a26b55b2e17a35f3a28d
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Reduce vertico-mouse allocations
---
extensions/vertico-mouse.el | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/extensions/vertico-mouse.el b/extensions/vertico-mouse.el
index dfc722e..221ebc4 100644
--- a/extensions/vertico-mouse.el
+++ b/extensions/vertico-mouse.el
@@ -37,18 +37,27 @@
"Face used for mouse highlighting."
:group 'vertico-faces)
-(defun vertico--mouse-candidate-map (index)
- "Return keymap for candidate with INDEX."
+(defvar vertico-mouse-map
(let ((map (make-sparse-keymap)))
- (define-key map [mouse-1] (lambda ()
- (interactive)
- (let ((vertico--index index))
- (vertico-exit))))
- (define-key map [mouse-3] (lambda ()
- (interactive)
- (let ((vertico--index index))
- (vertico-insert))))
- map))
+ (define-key map [mouse-1] #'vertico-mouse-exit)
+ (define-key map [mouse-3] #'vertico-mouse-insert)
+ map)
+ "Mouse keymap bound to candidates.")
+(fset 'vertico-mouse-map vertico-mouse-map)
+
+(defun vertico-mouse-exit (event)
+ "Exit after mouse EVENT."
+ (interactive "e")
+ (when-let* ((obj (posn-string (event-start event)))
+ (vertico--index (get-text-property (cdr obj)
'vertico--mouse-index (car obj))))
+ (vertico-exit)))
+
+(defun vertico-mouse-insert (event)
+ "Insert after mouse EVENT."
+ (interactive "e")
+ (when-let* ((obj (posn-string (event-start event)))
+ (vertico--index (get-text-property (cdr obj)
'vertico--mouse-index (car obj))))
+ (vertico-insert)))
(defun vertico-mouse--format-candidate (orig cand prefix suffix index start)
"Format candidate, see `vertico--format-candidate' for arguments."
@@ -60,7 +69,7 @@
(when (= index vertico--index)
(add-face-text-property 0 (length cand) 'vertico-current 'append cand)))
(add-text-properties 0 (1- (length cand))
- `(mouse-face vertico-mouse keymap
,(vertico--mouse-candidate-map index))
+ `(mouse-face vertico-mouse keymap vertico-mouse-map
vertico--mouse-index ,index)
cand)
cand)