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

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

[elpa] externals/vertico b11040e1e9 2/4: Use completion-lazy-hilit


From: ELPA Syncer
Subject: [elpa] externals/vertico b11040e1e9 2/4: Use completion-lazy-hilit
Date: Tue, 7 Nov 2023 15:58:58 -0500 (EST)

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

    Use completion-lazy-hilit
---
 extensions/vertico-flat.el |  2 +-
 extensions/vertico-grid.el | 37 ++++++++++++-------------
 vertico.el                 | 68 ++++++++++++++++++++++------------------------
 3 files changed, 52 insertions(+), 55 deletions(-)

diff --git a/extensions/vertico-flat.el b/extensions/vertico-flat.el
index a9c2eec682..4a2ce7a43c 100644
--- a/extensions/vertico-flat.el
+++ b/extensions/vertico-flat.el
@@ -110,7 +110,7 @@
     (while (and candidates (not (eq wrapped (car candidates)))
                 (> width 0) (> count 0))
       (let ((cand (pop candidates)) (prefix "") (suffix ""))
-        (setq cand (funcall vertico--highlight cand))
+        (setq cand (funcall vertico--highlight (substring cand)))
         (pcase (and vertico-flat-annotate (vertico--affixate (list cand)))
           (`((,c ,p ,s)) (setq cand c prefix p suffix s)))
         (when (string-search "\n" cand)
diff --git a/extensions/vertico-grid.el b/extensions/vertico-grid.el
index 42fd3a95b7..dc752941e0 100644
--- a/extensions/vertico-grid.el
+++ b/extensions/vertico-grid.el
@@ -131,25 +131,24 @@ When scrolling beyond this limit, candidates may be 
truncated."
          (start (* count (floor (max 0 vertico--index) count)))
          (width (- (/ (vertico--window-width) vertico-grid--columns) sep))
          (cands
-          (thread-last
-            (seq-subseq vertico--candidates start
-                        (min (+ start count) vertico--total))
-            (mapcar vertico--highlight)
-            (funcall (if (> vertico-grid-annotate 0) #'vertico--affixate 
#'identity))
-            (seq-map-indexed
-             (lambda (cand index)
-               (let (prefix suffix)
-                 (when (consp cand)
-                   (setq prefix (cadr cand) suffix (caddr cand) cand (car 
cand)))
-                 (when (string-search "\n" cand)
-                   (setq cand (vertico--truncate-multiline cand width)))
-                 (truncate-string-to-width
-                  (string-trim
-                   (replace-regexp-in-string
-                    "[ \t]+"
-                    (lambda (x) (apply #'propertize " " (text-properties-at 0 
x)))
-                    (vertico--format-candidate cand prefix suffix (+ index 
start) start)))
-                  width))))))
+          (seq-map-indexed
+           (lambda (cand index)
+             (let (prefix suffix)
+               (when (consp cand)
+                 (setq prefix (cadr cand) suffix (caddr cand) cand (car cand)))
+               (when (string-search "\n" cand)
+                 (setq cand (vertico--truncate-multiline cand width)))
+               (truncate-string-to-width
+                (string-trim
+                 (replace-regexp-in-string
+                  "[ \t]+"
+                  (lambda (x) (apply #'propertize " " (text-properties-at 0 
x)))
+                  (vertico--format-candidate cand prefix suffix (+ index 
start) start)))
+                width)))
+           (funcall (if (> vertico-grid-annotate 0) #'vertico--affixate 
#'identity)
+                    (cl-loop for i from 0 below count
+                             for c in (nthcdr start vertico--candidates)
+                             collect (funcall vertico--highlight (substring 
c))))))
          (width (make-vector vertico-grid--columns 0)))
     (dotimes (col vertico-grid--columns)
       (dotimes (row vertico-count)
diff --git a/vertico.el b/vertico.el
index 8f19f32fdb..71b2243a6d 100644
--- a/vertico.el
+++ b/vertico.el
@@ -271,38 +271,36 @@ The function is configured by BY, BSIZE, BINDEX, BPRED 
and PRED."
 
 (defun vertico--filter-completions (&rest args)
   "Compute all completions for ARGS with deferred highlighting."
-  (cl-letf* ((orig-pcm (symbol-function #'completion-pcm--hilit-commonality))
-             (orig-flex (symbol-function #'completion-flex-all-completions))
-             ((symbol-function #'completion-flex-all-completions)
-              (lambda (&rest args)
-                ;; Unfortunately for flex we have to undo the deferred 
highlighting, since flex uses
-                ;; the completion-score for sorting, which is applied during 
highlighting.
-                (cl-letf (((symbol-function 
#'completion-pcm--hilit-commonality) orig-pcm))
-                  (apply orig-flex args))))
-             ;; Defer the following highlighting functions
-             (hl #'identity)
+  (defvar completion-lazy-hilit)
+  (defvar completion-lazy-hilit-fn)
+  (cl-letf* ((completion-lazy-hilit t)
+             (completion-lazy-hilit-fn nil)
              ((symbol-function #'completion-hilit-commonality)
               (lambda (cands prefix &optional base)
-                (setq hl (lambda (x) (car (completion-hilit-commonality (list 
x) prefix base))))
-                (and cands (nconc cands base))))
-             ((symbol-function #'completion-pcm--hilit-commonality)
-              (lambda (pattern cands)
-                (setq hl (lambda (x)
-                           ;; `completion-pcm--hilit-commonality' sometimes 
throws an internal error
-                           ;; for example when entering "/sudo:://u".
-                           (condition-case nil
-                               (car (completion-pcm--hilit-commonality pattern 
(list x)))
-                             (t x))))
-                cands)))
-    ;; Only advise orderless after it has been loaded to avoid load order 
issues
-    (if (and (fboundp 'orderless-highlight-matches) (fboundp 
'orderless-pattern-compiler))
-        (cl-letf (((symbol-function 'orderless-highlight-matches)
-                   (lambda (pattern cands)
-                     (let ((rxs (orderless-pattern-compiler pattern)))
-                       (setq hl (lambda (x) (car (orderless-highlight-matches 
rxs (list x))))))
-                     cands)))
-          (cons (apply #'completion-all-completions args) hl))
-      (cons (apply #'completion-all-completions args) hl))))
+                (setq completion-lazy-hilit-fn
+                      (lambda (x) (car (completion-hilit-commonality (list x) 
prefix base))))
+                (and cands (nconc cands base)))))
+    (if (eval-when-compile (>= emacs-major-version 30))
+        (cons (apply #'completion-all-completions args) 
completion-lazy-hilit-fn)
+      (cl-letf* ((orig-pcm (symbol-function 
#'completion-pcm--hilit-commonality))
+                 (orig-flex (symbol-function 
#'completion-flex-all-completions))
+                 ((symbol-function #'completion-flex-all-completions)
+                  (lambda (&rest args)
+                    ;; Unfortunately for flex we have to undo the deferred 
highlighting, since flex uses
+                    ;; the completion-score for sorting, which is applied 
during highlighting.
+                    (cl-letf (((symbol-function 
#'completion-pcm--hilit-commonality) orig-pcm))
+                      (apply orig-flex args))))
+                 ((symbol-function #'completion-pcm--hilit-commonality)
+                  (lambda (pattern cands)
+                    (setq completion-lazy-hilit-fn
+                          (lambda (x)
+                            ;; `completion-pcm--hilit-commonality' sometimes 
throws an internal error
+                            ;; for example when entering "/sudo:://u".
+                            (condition-case nil
+                                (car (completion-pcm--hilit-commonality 
pattern (list x)))
+                              (t x))))
+                    cands)))
+        (cons (apply #'completion-all-completions args) 
completion-lazy-hilit-fn)))))
 
 (defun vertico--metadata-get (prop)
   "Return PROP from completion metadata."
@@ -356,7 +354,7 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and 
PRED."
       (vertico--metadata . ,vertico--metadata)
       (vertico--candidates . ,all)
       (vertico--total . ,(length all))
-      (vertico--highlight . ,hl)
+      (vertico--highlight . ,(or hl #'identity))
       (vertico--allow-prompt . ,(or def-missing (eq vertico-preselect 'prompt)
                                     (memq minibuffer--require-match
                                           '(nil confirm 
confirm-after-completion))))
@@ -575,10 +573,10 @@ The function is configured by BY, BSIZE, BINDEX, BPRED 
and PRED."
     (let* (title (index vertico--scroll)
            (group-fun (and vertico-group-format (vertico--metadata-get 
'group-function)))
            (candidates
-            (thread-last (seq-subseq vertico--candidates index
-                                     (min (+ index vertico-count) 
vertico--total))
-              (mapcar vertico--highlight)
-              (vertico--affixate))))
+            (vertico--affixate
+             (cl-loop for i from 0 below vertico-count
+                      for c in (nthcdr index vertico--candidates)
+                      collect (funcall vertico--highlight (substring c))))))
       (pcase-dolist ((and cand `(,str . ,_)) candidates)
         (when-let (new-title (and group-fun (funcall group-fun str nil)))
           (unless (equal title new-title)



reply via email to

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