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

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

[elpa] externals/vertico 35edcd7 2/5: Add vertico-indexed extension


From: ELPA Syncer
Subject: [elpa] externals/vertico 35edcd7 2/5: Add vertico-indexed extension
Date: Fri, 9 Jul 2021 23:57:19 -0400 (EDT)

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

    Add vertico-indexed extension
---
 README.org                    |  1 +
 extensions/vertico-indexed.el | 73 +++++++++++++++++++++++++++++++++++++++++++
 extensions/vertico-quick.el   |  4 +--
 3 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/README.org b/README.org
index 8fe0bf3..ed8773c 100644
--- a/README.org
+++ b/README.org
@@ -156,6 +156,7 @@
   - 
[[https://github.com/minad/vertico/blob/main/extensions/vertico-buffer.el][vertico-buffer.el]]:
 Enable =vertico-buffer-mode= to display Vertico in a separate buffer
   - 
[[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-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-indexed.el b/extensions/vertico-indexed.el
new file mode 100644
index 0000000..cbd8298
--- /dev/null
+++ b/extensions/vertico-indexed.el
@@ -0,0 +1,73 @@
+;;; vertico-indexed.el --- Select indexed candidates -*- 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 prefixes candidates with
+;; indices and allows selection using prefix arguments.
+
+;;; Code:
+
+(require 'vertico)
+
+(defface vertico-indexed
+  '((t :height 0.75 :inherit font-lock-comment-face))
+  "Face used for the candidate index prefix."
+  :group 'vertico
+  :group 'faces)
+
+(defvar-local vertico-indexed--start 0)
+
+(defun vertico-indexed--format-candidate (orig cand prefix suffix index start)
+  "Format candidate, see `vertico--format-candidate' for arguments."
+  (setq-local vertico-indexed--start start)
+  (funcall orig cand
+           (concat (propertize (format "%-2s " (- index start))
+                               'face 'vertico-indexed)
+                   prefix)
+           suffix index start))
+
+(defun vertico-indexed--goto ()
+  "Goto candidate given by `current-prefix-arg'."
+  (when current-prefix-arg
+    (vertico--goto (+ vertico-indexed--start (prefix-numeric-value 
current-prefix-arg)))))
+
+;;;###autoload
+(define-minor-mode vertico-indexed-mode
+  "Prefix candidates with indices."
+  :global t
+  (cond
+   (vertico-indexed-mode
+    (advice-add #'vertico--format-candidate :around 
#'vertico-indexed--format-candidate)
+    (advice-add #'vertico-insert :before #'vertico-indexed--goto)
+    (advice-add #'vertico-exit :before #'vertico-indexed--goto))
+   (t
+    (advice-remove #'vertico--format-candidate 
#'vertico-indexed--format-candidate)
+    (advice-remove #'vertico-insert #'vertico-indexed--goto)
+    (advice-remove #'vertico-exit #'vertico-indexed--goto))))
+
+(provide 'vertico-indexed)
+;;; vertico-indexed.el ends here
diff --git a/extensions/vertico-quick.el b/extensions/vertico-quick.el
index a1ec63c..2d9e7a5 100644
--- a/extensions/vertico-quick.el
+++ b/extensions/vertico-quick.el
@@ -36,13 +36,13 @@
 
 (defface vertico-quick1
   '((t :weight bold :background "#d5baff" :foreground "black"))
-  "First quick key."
+  "Face used for the first quick key."
   :group 'vertico
   :group 'faces)
 
 (defface vertico-quick2
   '((t :weight bold :background "#8ae4f2" :foreground "black"))
-  "Second quick key."
+  "Face used for the second quick key."
   :group 'vertico
   :group 'faces)
 



reply via email to

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