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

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

[elpa] externals/consult 813ff63e5f 1/2: consult--multi-annotate: Alignm


From: ELPA Syncer
Subject: [elpa] externals/consult 813ff63e5f 1/2: consult--multi-annotate: Alignment based on maximum candidate width (Fix #740)
Date: Mon, 6 Feb 2023 13:57:31 -0500 (EST)

branch: externals/consult
commit 813ff63e5f2a25e8ff2a9f032a22e3e8b1f02b0f
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    consult--multi-annotate: Alignment based on maximum candidate width (Fix 
#740)
    
    The visible candidates so far are taken into account.
---
 consult.el | 54 ++++++++++++++++++++++++++++--------------------------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/consult.el b/consult.el
index 0867fe818a..924df8e3c3 100644
--- a/consult.el
+++ b/consult.el
@@ -501,12 +501,8 @@ as the public API.")
 This function can be called by custom completion systems from
 outside the minibuffer.")
 
-(defconst consult--tofu-char #x200000
-  "Special character used to encode line prefixes for disambiguation.
-We use invalid characters outside the Unicode range.")
-
-(defconst consult--tofu-range #x100000
-  "Special character range.")
+(defvar-local consult--multi-cand-width-max 0
+  "Maximum candidate width used for annotation alignment.")
 
 (defvar-local consult--narrow nil
   "Current narrowing key.")
@@ -529,16 +525,23 @@ We use invalid characters outside the Unicode range.")
 (defvar consult--process-chunk (* 1024 1024)
   "Increase process output chunk size.")
 
-(defvar consult--async-log
-  " *consult-async*"
-  "Buffer for async logging output used by `consult--async-process'.")
-
 (defvar-local consult--focus-lines-overlays nil
   "Overlays used by `consult-focus-lines'.")
 
 (defvar-local consult--org-fold-regions nil
   "Stored regions for the org-fold API.")
 
+(defconst consult--tofu-char #x200000
+  "Special character used to encode line prefixes for disambiguation.
+We use invalid characters outside the Unicode range.")
+
+(defconst consult--tofu-range #x100000
+  "Special character range.")
+
+(defconst consult--async-log
+  " *consult-async*"
+  "Buffer for async logging output used by `consult--async-process'.")
+
 ;;;; Miscellaneous helper functions
 
 (defun consult--in-buffer (fun &optional buffer)
@@ -2564,14 +2567,18 @@ input method."
     (delq nil)
     (delete-dups)))
 
-(defun consult--multi-annotate (sources align cand)
-  "Annotate candidate CAND with `consult--multi' type, given SOURCES and 
ALIGN."
+(defun consult--multi-annotate (sources cand)
+  "Annotate candidate CAND from multi SOURCES."
+  (setq consult--multi-cand-width-max (max consult--multi-cand-width-max 
(consult--display-width cand)))
   (let* ((src (consult--multi-source sources cand))
-         (annotate (plist-get src :annotate))
-         (ann (if annotate
-                  (funcall annotate (cdr (get-text-property 0 'multi-category 
cand)))
+         (fun (plist-get src :annotate))
+         (ann (if fun
+                  (funcall fun (cdr (get-text-property 0 'multi-category 
cand)))
                 (plist-get src :name))))
-    (and ann (concat align ann))))
+    (when ann
+      (concat
+       #("   " 0 1 (display (space :align-to (+ left 
consult--multi-cand-width-max))))
+       ann))))
 
 (defun consult--multi-group (sources cand transform)
   "Return title of candidate CAND or TRANSFORM the candidate given SOURCES."
@@ -2621,25 +2628,23 @@ input method."
 
 (defun consult--multi-candidates (sources)
   "Return `consult--multi' candidates from SOURCES."
-  (let ((idx 0) (max-width 0) (candidates))
+  (let ((idx 0) candidates)
     (seq-doseq (src sources)
       (let* ((face (and (plist-member src :face) `(face ,(plist-get src 
:face))))
              (cat (plist-get src :category))
              (items (plist-get src :items))
              (items (if (functionp items) (funcall items) items)))
         (dolist (item items)
-          (let ((cand (consult--tofu-append item idx))
-                (width (consult--display-width item)))
+          (let ((cand (consult--tofu-append item idx)))
             ;; Preserve existing `multi-category' datum of the candidate.
             (if (get-text-property 0 'multi-category cand)
                 (when face (add-text-properties 0 (length item) face cand))
               ;; Attach `multi-category' datum and face.
               (add-text-properties 0 (length item)
                                    `(multi-category (,cat . ,item) ,@face) 
cand))
-            (when (> width max-width) (setq max-width width))
             (push cand candidates))))
       (cl-incf idx))
-    (cons (+ 3 max-width) (nreverse candidates))))
+    (nreverse candidates)))
 
 (defun consult--multi-enabled-sources (sources)
   "Return vector of enabled SOURCES."
@@ -2730,18 +2735,15 @@ Optional source fields:
   (let* ((sources (consult--multi-enabled-sources sources))
          (candidates (consult--with-increased-gc
                       (consult--multi-candidates sources)))
-         (align (propertize
-                 " " 'display
-                 `(space :align-to (+ left ,(car candidates)))))
          (selected
           (apply #'consult--read
-                 (cdr candidates)
+                 candidates
                  (append
                   options
                   (list
                    :category    'multi-category
                    :predicate   (apply-partially #'consult--multi-predicate 
sources)
-                   :annotate    (apply-partially #'consult--multi-annotate 
sources align)
+                   :annotate    (apply-partially #'consult--multi-annotate 
sources)
                    :group       (apply-partially #'consult--multi-group 
sources)
                    :lookup      (apply-partially #'consult--multi-lookup 
sources)
                    :preview-key (consult--multi-preview-key sources)



reply via email to

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