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

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

[elpa] externals/vertico 81539b8 2/2: vertico-count-format: Better count


From: ELPA Syncer
Subject: [elpa] externals/vertico 81539b8 2/2: vertico-count-format: Better count formatting using display alignment
Date: Fri, 9 Jul 2021 08:57:20 -0400 (EDT)

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

    vertico-count-format: Better count formatting using display alignment
---
 extensions/vertico-buffer.el |  8 +++++---
 vertico.el                   | 27 ++++++++++++++++++---------
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/extensions/vertico-buffer.el b/extensions/vertico-buffer.el
index 59b17c6..38b03c2 100644
--- a/extensions/vertico-buffer.el
+++ b/extensions/vertico-buffer.el
@@ -52,10 +52,12 @@
     (let ((str (buffer-string))
           (pt (point)))
       (if (= pt (point-max))
-          (concat str #(" " 0 1 (face (:inverse-video t))))
+          (setq str (concat str #(" " 0 1 (face (:inverse-video t)))))
         (setq pt (max (minibuffer-prompt-end) pt))
-        (put-text-property (1- pt) pt 'face '(:inverse-video t) str)
-        str))))
+        (put-text-property (1- pt) pt 'face '(:inverse-video t) str))
+      (when vertico-count-format
+        (setq str (concat (propertize (vertico--format-count) 'face 
'minibuffer-prompt) str)))
+      str)))
 
 (defun vertico-buffer--display (lines)
   "Display LINES in buffer."
diff --git a/vertico.el b/vertico.el
index 2156aef..69238da 100644
--- a/vertico.el
+++ b/vertico.el
@@ -42,9 +42,10 @@
   :group 'convenience
   :prefix "vertico-")
 
-(defcustom vertico-count-format (cons "%-6s " "%s/%s")
+(defcustom vertico-count-format
+  '(7 "%s/%s ")
   "Format string used for the candidate count."
-  :type '(choice (const nil) (cons string string)))
+  :type '(choice (const nil) (list integer string)))
 
 (defcustom vertico-group-format
   (concat
@@ -489,17 +490,25 @@ See `resize-mini-windows' for documentation."
                 (and (< dp 0) (eq vertico-resize t)))
         (window-resize nil dp nil nil 'pixelwise)))))
 
+(defun vertico--format-count ()
+  "Format the count string."
+  (when (stringp (car vertico-count-format))
+    (message "Deprecated `vertico-count-format' configuration.")
+    (setq vertico-count-format `(7 "%s/%s")))
+  (concat
+   (format (cadr vertico-count-format)
+           (cond ((>= vertico--index 0) (1+ vertico--index))
+                 ((vertico--allow-prompt-selection-p) "*")
+                 (t "!"))
+           vertico--total)
+   (propertize " " 'display
+               `(space :align-to (+ left ,(car vertico-count-format))))))
+
 (defun vertico--display-count ()
   "Update count overlay `vertico--count-ov'."
   (when vertico--count-ov
     (move-overlay vertico--count-ov (point-min) (point-min))
-    (overlay-put vertico--count-ov 'before-string
-                 (format (car vertico-count-format)
-                         (format (cdr vertico-count-format)
-                                 (cond ((>= vertico--index 0) (1+ 
vertico--index))
-                                       ((vertico--allow-prompt-selection-p) 
"*")
-                                       (t "!"))
-                                 vertico--total)))))
+    (overlay-put vertico--count-ov 'before-string (vertico--format-count))))
 
 (defun vertico--tidy-shadowed-file ()
   "Tidy shadowed file name, see `rfn-eshadow-overlay'."



reply via email to

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