emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/vertico dc65ca9 2/2: Add extension vertico-mouse


From: ELPA Syncer
Subject: [elpa] externals/vertico dc65ca9 2/2: Add extension vertico-mouse
Date: Sat, 10 Jul 2021 10:57:16 -0400 (EDT)

branch: externals/vertico
commit dc65ca91b43c977045a962fcc3cb8a6bc38c9a07
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Add extension vertico-mouse
---
 README.org                  |  1 +
 extensions/vertico-mouse.el | 86 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+)

diff --git a/README.org b/README.org
index ed8773c..e3f05a5 100644
--- a/README.org
+++ b/README.org
@@ -157,6 +157,7 @@
   - 
[[https://github.com/minad/vertico/blob/main/extensions/vertico-directory.el][vertico-directory.el]]:
 Commands for Ido-like directory navigation
   - 
[[https://github.com/minad/vertico/blob/main/extensions/vertico-flat.el][vertico-flat.el]]:
 Enable =vertico-flat-mode= to enable a flat, horizontal display
   - 
[[https://github.com/minad/vertico/blob/main/extensions/vertico-indexed.el][vertico-indexed.el]]:
 Select indexed candidates with prefix arguments
+  - 
[[https://github.com/minad/vertico/blob/main/extensions/vertico-mouse.el][vertico-mouse.el]]:
 Mouse support for scrolling and candidate selection
   - 
[[https://github.com/minad/vertico/blob/main/extensions/vertico-quick.el][vertico-quick.el]]:
 Select using Avy-style quick keys
   - 
[[https://github.com/minad/vertico/blob/main/extensions/vertico-repeat.el][vertico-repeat.el]]:
 The command =vertico-repeat= repeats the last completion session
   - 
[[https://github.com/minad/vertico/blob/main/extensions/vertico-reverse.el][vertico-reverse.el]]:
 Enable =vertico-reverse-mode= to reverse the display
diff --git a/extensions/vertico-mouse.el b/extensions/vertico-mouse.el
new file mode 100644
index 0000000..5c1831f
--- /dev/null
+++ b/extensions/vertico-mouse.el
@@ -0,0 +1,86 @@
+;;; vertico-mouse.el --- Mouse support for Vertico -*- lexical-binding: t -*-
+
+;; Copyright (C) 2021  Free Software Foundation, Inc.
+
+;; Author: Daniel Mendler <mail@daniel-mendler.de>
+;; Maintainer: Daniel Mendler <mail@daniel-mendler.de>
+;; Created: 2021
+;; Version: 0.1
+;; Package-Requires: ((emacs "27.1"))
+;; Homepage: https://github.com/minad/vertico
+
+;; This file is part of GNU Emacs.
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package is a Vertico extension, which adds mouse support.
+
+;;; Code:
+
+(require 'vertico)
+
+(defface vertico-mouse
+  '((t :inherit highlight))
+  "Face used for mouse highlighting."
+  :group 'vertico
+  :group 'faces)
+
+(defun vertico--mouse-candidate-map (index)
+  "Return keymap for candidate with INDEX."
+  (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))
+
+(defun vertico-mouse--format-candidate (orig cand prefix suffix index start)
+  "Format candidate, see `vertico--format-candidate' for arguments."
+  (setq cand (funcall orig cand prefix suffix index start))
+  (when (equal suffix "")
+    (setq cand (concat (substring cand 0 -1)
+                       (propertize " " 'display '(space :align-to right))
+                       "\n"))
+    (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))
+                       cand)
+  cand)
+
+(defun vertico-mouse--setup ()
+  "Setup mouse scrolling."
+  (setq-local mwheel-scroll-up-function #'vertico-next
+              mwheel-scroll-down-function #'vertico-previous))
+
+;;;###autoload
+(define-minor-mode vertico-mouse-mode
+  "Mouse support for Vertico."
+  :global t
+  (cond
+   (vertico-mouse-mode
+    (advice-add #'vertico--format-candidate :around 
#'vertico-mouse--format-candidate)
+    (advice-add #'vertico--setup :after #'vertico-mouse--setup))
+   (t
+    (advice-remove #'vertico--format-candidate 
#'vertico-mouse--format-candidate)
+    (advice-remove #'vertico--setup #'vertico-reverse--setup))))
+
+(provide 'vertico-mouse)
+;;; vertico-mouse.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]