From 9c9850de654c60b000fe3be4365b1bd261bf4f21 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Sun, 2 May 2021 16:19:42 +0200 Subject: [PATCH 4/4] (completion--insert-vertical): Separate groups completely Insert the candidates vertically within the groups, but keep the groups completely 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 b743b2bd40..73a38a8137 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1866,66 +1866,54 @@ completion--insert-horizontal (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)) -- 2.20.1