]> git.eshelyaron.com Git - emacs.git/commitdiff
Cease removing consecutive duplicate completion candidates
authorEshel Yaron <me@eshelyaron.com>
Tue, 19 Mar 2024 12:44:05 +0000 (13:44 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 19 Mar 2024 12:44:05 +0000 (13:44 +0100)
lisp/minibuffer.el

index 204fb2758c750b20f8e63e4b0241dcd4d4889200..59f991b97f4327d27e98fcee82e1961568c81ec4 100644 (file)
@@ -2472,45 +2472,42 @@ function as described in the documentation of `completion-metadata'."
                                               colwidth _columns)
   (let ((column 0)
         (first t)
-       (last-title nil)
-        (last-string nil))
+       (last-title nil))
     (dolist (str strings)
-      (unless (equal last-string str) ; Remove (consecutive) duplicates.
-       (setq last-string str)
-        (when group-fun
-          (let ((title (funcall group-fun (if (consp str) (car str) str) nil)))
-            (unless (equal title last-title)
-              (setq last-title title)
-              (when title
-                (insert (if first "" "\n") (format completions-group-format title) "\n")
-                (setq column 0
-                      first t)))))
-       (unless first
-          ;; FIXME: `string-width' doesn't pay attention to
-          ;; `display' properties.
-         (if (< wwidth (+ column (max colwidth
-                                       (if (consp str)
-                                           (apply #'+ (mapcar #'string-width str))
-                                         (string-width str)))))
-             ;; No space for `str' at point, move to next line.
-             (progn (insert "\n") (setq column 0))
-           (insert " \t")
-           ;; Leave the space unpropertized so that in the case we're
-           ;; already past the goal column, there is still
-           ;; a space displayed.
-           (set-text-properties (1- (point)) (point)
-                                ;; We can set tab-width using
-                                ;; completion-tab-width, but
-                                ;; the caller can prefer using
-                                ;; \t to align prefixes.
-                                `(display (space :align-to ,column)))
-           nil))
-        (setq first nil)
-        (completion--insert str group-fun)
-       ;; Next column to align to.
-       (setq column (+ column
-                       ;; Round up to a whole number of columns.
-                       (* colwidth (ceiling length colwidth))))))))
+      (when group-fun
+        (let ((title (funcall group-fun (if (consp str) (car str) str) nil)))
+          (unless (equal title last-title)
+            (setq last-title title)
+            (when title
+              (insert (if first "" "\n") (format completions-group-format title) "\n")
+              (setq column 0
+                    first t)))))
+      (unless first
+        ;; FIXME: `string-width' doesn't pay attention to
+        ;; `display' properties.
+       (if (< wwidth (+ column (max colwidth
+                                     (if (consp str)
+                                         (apply #'+ (mapcar #'string-width str))
+                                       (string-width str)))))
+           ;; No space for `str' at point, move to next line.
+           (progn (insert "\n") (setq column 0))
+         (insert " \t")
+         ;; Leave the space unpropertized so that in the case we're
+         ;; already past the goal column, there is still
+         ;; a space displayed.
+         (set-text-properties (1- (point)) (point)
+                              ;; We can set tab-width using
+                              ;; completion-tab-width, but
+                              ;; the caller can prefer using
+                              ;; \t to align prefixes.
+                              `(display (space :align-to ,column)))
+         nil))
+      (setq first nil)
+      (completion--insert str group-fun)
+      ;; Next column to align to.
+      (setq column (+ column
+                     ;; Round up to a whole number of columns.
+                     (* colwidth (ceiling length colwidth)))))))
 
 (defun completion--insert-vertical (strings group-fun
                                             _length _wwidth
@@ -2519,8 +2516,7 @@ function as described in the documentation of `completion-metadata'."
     (let ((group nil)
           (column 0)
          (row 0)
-          (rows)
-          (last-string nil))
+          (rows))
       (if group-fun
           (let* ((str (car strings))
                  (title (funcall group-fun (if (consp str) (car str) str) nil)))
@@ -2543,40 +2539,36 @@ function as described in the documentation of `completion-metadata'."
             (goto-char (point-max))
             (insert (format completions-group-format title) "\n"))))
       (dolist (str group)
-        (unless (equal last-string str) ; Remove (consecutive) duplicates.
-         (setq last-string str)
-         (when (> row rows)
-            (forward-line (- -1 rows))
-           (setq row 0 column (+ column colwidth)))
-         (when (> column 0)
-           (end-of-line)
-           (while (> (current-column) column)
-             (if (eobp)
-                 (insert "\n")
-               (forward-line 1)
-               (end-of-line)))
-           (insert " \t")
-           (set-text-properties (1- (point)) (point)
-                                `(display (space :align-to ,column))))
-          (completion--insert str group-fun)
-         (if (> column 0)
-             (forward-line)
-           (insert "\n"))
-         (setq row (1+ row)))))))
+       (when (> row rows)
+          (forward-line (- -1 rows))
+         (setq row 0 column (+ column colwidth)))
+       (when (> column 0)
+         (end-of-line)
+         (while (> (current-column) column)
+           (if (eobp)
+               (insert "\n")
+             (forward-line 1)
+             (end-of-line)))
+         (insert " \t")
+         (set-text-properties (1- (point)) (point)
+                              `(display (space :align-to ,column))))
+        (completion--insert str group-fun)
+       (if (> column 0)
+           (forward-line)
+         (insert "\n"))
+       (setq row (1+ row))))))
 
 (defun completion--insert-one-column (strings group-fun &rest _)
-  (let ((last-title nil) (last-string nil))
+  (let ((last-title nil))
     (dolist (str strings)
-      (unless (equal last-string str) ; Remove (consecutive) duplicates.
-       (setq last-string str)
-        (when group-fun
-          (let ((title (funcall group-fun (if (consp str) (car str) str) nil)))
-            (unless (equal title last-title)
-              (setq last-title title)
-              (when title
-                (insert (format completions-group-format title) "\n")))))
-        (completion--insert str group-fun)
-        (insert "\n")))
+      (when group-fun
+        (let ((title (funcall group-fun (if (consp str) (car str) str) nil)))
+          (unless (equal title last-title)
+            (setq last-title title)
+            (when title
+              (insert (format completions-group-format title) "\n")))))
+      (completion--insert str group-fun)
+      (insert "\n"))
     (delete-char -1)))
 
 (defun completion--insert (str group-fun)