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

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

[elpa] externals/vertico 4c0f343 1/2: Add vertico-scroll-margin


From: ELPA Syncer
Subject: [elpa] externals/vertico 4c0f343 1/2: Add vertico-scroll-margin
Date: Sat, 13 Nov 2021 08:57:37 -0500 (EST)

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

    Add vertico-scroll-margin
---
 README.org |  9 +++++++--
 vertico.el | 20 ++++++++++++++++++--
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/README.org b/README.org
index c34cb33..837bed8 100644
--- a/README.org
+++ b/README.org
@@ -19,8 +19,7 @@
   completion commands and completion tables. Vertico only provides the
   completion UI but aims to be flexible and extensible. Additional enhancements
   are available as [[#extensions][extensions]] or 
[[#complementary-packages][complementary packages]]. The code base is small
-  and maintainable (~vertico.el~ is only about 600 lines of code without white
-  space and comments).
+  and maintainable (~vertico.el~ is well below 1000 lines of code).
 
 * Features
 
@@ -73,6 +72,12 @@
       :init
       (vertico-mode)
 
+      ;; Different scroll margin
+      ;; (setq vertico-scroll-margin 0)
+
+      ;; Show more candidates
+      ;; (setq vertico-count 20)
+
       ;; Grow and shrink the Vertico minibuffer
       ;; (setq vertico-resize t)
 
diff --git a/vertico.el b/vertico.el
index 98d27d6..d401d3c 100644
--- a/vertico.el
+++ b/vertico.el
@@ -59,6 +59,11 @@
   "Maximal number of candidates to show."
   :type 'integer)
 
+(defcustom vertico-scroll-margin 2
+  "Number of lines at the top and bottom when scrolling.
+The value should lie between 0 and vertico-count/2."
+  :type 'integer)
+
 (defcustom vertico-resize resize-mini-windows
   "How to resize the Vertico minibuffer window.
 See `resize-mini-windows' for documentation."
@@ -140,6 +145,9 @@ See `resize-mini-windows' for documentation."
 (defvar-local vertico--index -1
   "Index of current candidate or negative for prompt selection.")
 
+(defvar-local vertico--scroll 0
+  "Scroll position.")
+
 (defvar-local vertico--input nil
   "Cons of last minibuffer contents and point or t.")
 
@@ -489,12 +497,20 @@ The function is configured by BY, BSIZE, BINDEX, BPRED 
and PRED."
     (add-face-text-property 0 (length cand) 'vertico-current 'append cand))
   cand)
 
+(defun vertico--update-scroll ()
+  "Update scroll position."
+  (let ((off (max (min vertico-scroll-margin (/ vertico-count 2)) 0))
+        (corr (if (= vertico-scroll-margin (/ vertico-count 2)) (1- (mod 
vertico-count 2)) 0)))
+    (setq vertico--scroll (min (max 0 (- vertico--total vertico-count))
+                             (max 0 (+ vertico--index off 1 (- vertico-count))
+                                  (min (- vertico--index off corr) 
vertico--scroll))))))
+
 (defun vertico--arrange-candidates ()
   "Arrange candidates."
+  (vertico--update-scroll)
   (let ((curr-line 0) (lines))
     ;; Compute group titles
-    (let* ((index (min (max 0 (- vertico--index (/ vertico-count 2) (1- (mod 
vertico-count 2))))
-                       (max 0 (- vertico--total vertico-count))))
+    (let* ((index vertico--scroll)
            (title)
            (group-fun (vertico--metadata-get 'group-function))
            (group-format (and group-fun vertico-group-format (concat 
vertico-group-format "\n")))



reply via email to

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