emacs-diffs
[Top][All Lists]
Advanced

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

master 836d69b 4/6: (completion--insert-vertical): Separate groups compl


From: Juri Linkov
Subject: master 836d69b 4/6: (completion--insert-vertical): Separate groups completely
Date: Thu, 20 May 2021 13:52:28 -0400 (EDT)

branch: master
commit 836d69bc60b3be349c658e9cc78f60d7e7730fd9
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Juri Linkov <juri@linkov.net>

    (completion--insert-vertical): Separate groups completely
    
    Insert the candidates vertically within the groups, but keep the
    groups separate using the full width group separators.
    
    * minibuffer.el (completion--insert-vertical): Adjust grouping.
---
 lisp/minibuffer.el | 108 ++++++++++++++++++++++++-----------------------------
 1 file changed, 48 insertions(+), 60 deletions(-)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 35bb12f..35ae4b8 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1869,66 +1869,54 @@ Runs of equal candidate strings are eliminated.  
GROUP-FUN is a
 (defun completion--insert-vertical (strings group-fun
                                             _length _wwidth
                                             colwidth columns)
-  (let ((column 0)
-        (rows (/ (length strings) columns))
-       (row 0)
-       (last-title nil)
-       (last-string nil)
-        (start-point (point))
-        (next 0) (pos 0))
-    (dolist (str strings)
-      (unless (equal last-string str) ; Remove (consecutive) duplicates.
-       (setq last-string str)
-       (when (> row rows)
-         (goto-char start-point)
-         (setq row 0 column (+ column 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
-                ;; Align before title insertion
-               (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))))
-                (let* ((fmt completions-group-format)
-                       (len (length fmt)))
-                  ;; Adjust display space for columns
-                  (when (equal (get-text-property (- len 1) 'display fmt) 
'(space :align-to right))
-                    (setq fmt (substring fmt))
-                    (put-text-property (- len 1) len
-                                       'display
-                                       `(space :align-to ,(+ colwidth column 
-1))
-                                       fmt))
-                  (insert (format fmt title)))
-                ;; Align after title insertion
-               (if (> column 0)
-                   (forward-line)
-                 (insert "\n"))))))
-        ;; Align before candidate insertion
-       (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)
-        ;; Align after candidate insertion
-       (if (> column 0)
-           (forward-line)
-         (insert "\n"))
-       (setq row (1+ row))))))
+  (while strings
+    (let ((group nil)
+          (column 0)
+         (row 0)
+          (rows)
+          (last-string nil))
+      (if group-fun
+          (let* ((str (car strings))
+                 (title (funcall group-fun (if (consp str) (car str) str) 
nil)))
+            (while (and strings
+                        (equal title (funcall group-fun
+                                              (if (consp (car strings))
+                                                  (car (car strings))
+                                                (car strings))
+                                              nil)))
+              (push (car strings) group)
+              (pop strings))
+            (setq group (nreverse group)))
+        (setq group strings
+              strings nil))
+      (setq rows (/ (length group) columns))
+      (when group-fun
+        (let* ((str (car group))
+               (title (funcall group-fun (if (consp str) (car str) str) nil)))
+          (when title
+            (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)))))))
 
 (defun completion--insert-one-column (strings group-fun &rest _)
   (let ((last-title nil) (last-string nil))



reply via email to

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