]> git.eshelyaron.com Git - emacs.git/commitdiff
(completion-hilit-commonality): Support `completion-lazy-hilit`
authorDaniel Mendler <mail@daniel-mendler.de>
Thu, 4 Apr 2024 05:19:58 +0000 (07:19 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 10 Apr 2024 20:29:24 +0000 (22:29 +0200)
* lisp/minibuffer.el (completion-hilit-commonality): Support lazy
completion candidate highlighting via `completion-lazy-hilit`.

(cherry picked from commit f30801a20338cdc7716c3eff1443f1be603aa94e)

lisp/minibuffer.el

index e3128b80bba90ef138c0cb691c058c7952a2deff..0f484a3f8cc5749a29ae4fefd2432e92d17d2e45 100644 (file)
@@ -2650,34 +2650,38 @@ This adds the face `completions-common-part' to the first
 It returns a list with font-lock properties applied to each element,
 and with BASE-SIZE appended as the last element."
   (when completions
-    (let ((com-str-len (- prefix-len (or base-size 0))))
-      (nconc
-       (mapcar
-        (lambda (elem)
-          (let ((str
-                 ;; Don't modify the string itself, but a copy, since the
-                 ;; string may be read-only or used for other purposes.
-                 ;; Furthermore, since `completions' may come from
-                 ;; display-completion-list, `elem' may be a list.
-                 (if (consp elem)
-                     (car (setq elem (cons (copy-sequence (car elem))
-                                           (cdr elem))))
-                   (setq elem (copy-sequence elem)))))
-            (font-lock-prepend-text-property
-             0
-             ;; If completion-boundaries returns incorrect
-             ;; values, all-completions may return strings
-             ;; that don't contain the prefix.
-             (min com-str-len (length str))
-             'face 'completions-common-part str)
-            (if (> (length str) com-str-len)
-                (font-lock-prepend-text-property com-str-len (1+ com-str-len)
-                                                 'face
-                                                 'completions-first-difference
-                                                 str)))
-          elem)
-        completions)
-       base-size))))
+    (let* ((com-str-len (- prefix-len (or base-size 0)))
+           (hilit-fn
+            (lambda (str)
+              (font-lock-prepend-text-property
+               0
+               ;; If completion-boundaries returns incorrect values,
+               ;; all-completions may return strings that don't contain
+               ;; the prefix.
+               (min com-str-len (length str))
+               'face 'completions-common-part str)
+              (when (> (length str) com-str-len)
+                (font-lock-prepend-text-property
+                 com-str-len (1+ com-str-len)
+                 'face 'completions-first-difference str))
+              str)))
+      (if completion-lazy-hilit
+          (setq completion-lazy-hilit-fn hilit-fn)
+        (setq completions
+              (mapcar
+               (lambda (elem)
+                 ;; Don't modify the string itself, but a copy, since
+                 ;; the string may be read-only or used for other
+                 ;; purposes.  Furthermore, since `completions' may come
+                 ;; from display-completion-list, `elem' may be a list.
+                 (funcall hilit-fn
+                          (if (consp elem)
+                              (car (setq elem (cons (copy-sequence (car elem))
+                                                    (cdr elem))))
+                            (setq elem (copy-sequence elem))))
+                 elem)
+               completions)))
+      (nconc completions base-size))))
 
 (defun completions-predicate-description (pred)
   (and (functionp pred)