From: Eshel Yaron Date: Tue, 19 Mar 2024 12:44:05 +0000 (+0100) Subject: Cease removing consecutive duplicate completion candidates X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6fd772f353e16740d39bf54e703773ec2643161c;p=emacs.git Cease removing consecutive duplicate completion candidates --- diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 204fb2758c7..59f991b97f4 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -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)