From d616bf6ffad9ba9eec3bc12e6a6610affbd0b687 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Tue, 16 Jan 2024 10:44:46 +0100 Subject: [PATCH] ; Align completion annotations with spaces for multi-column format Use actual spaces to align completion annotations instead of "specified space" display properties, since that allows 'completion--insert-strings' to correctly align multiple completion columns when 'completions-format' is not 'one-column'. * lisp/faces.el (completion-face-name-affixation) * lisp/minibuffer.el (completion-styles-affixation) (completion-file-name-affixation) (minibuffer-narrow-buffer-completions) (completion-buffer-name-affixation) * lisp/simple.el (read-extended-command--affixation): Align annotations with spaces instead of using '(space :align-to ...)' display properties. --- lisp/faces.el | 2 +- lisp/minibuffer.el | 57 ++++++++++++++++--------------- lisp/simple.el | 84 +++++++++++++++++++++++++++------------------- 3 files changed, 80 insertions(+), 63 deletions(-) diff --git a/lisp/faces.el b/lisp/faces.el index a85ffa21299..a67aa41acc1 100644 --- a/lisp/faces.el +++ b/lisp/faces.el @@ -1130,7 +1130,7 @@ of `read-face-name-sample-text', which see." (list name "" (concat - (propertize " " 'display `(space :align-to ,(+ max-name 4))) + (make-string (- (+ max-name 2) (string-width name)) ?\s) (propertize read-face-name-sample-text 'face name)))))) (read-face-name-sample-text (lambda (name) (list (propertize name 'face name) "" ""))) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 31833e6e36b..fe8d513c195 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2783,8 +2783,9 @@ current order instead." "" (if-let ((desc (nth 3 (assoc (intern name) completion-styles-alist)))) - (concat (propertize " " 'display - `(space :align-to ,(+ max-name 4))) + (concat (make-string (- (+ max-name 4) + (string-width name)) + ?\s) (propertize ;; Only use the first line. (substring desc 0 (string-search "\n" desc)) @@ -3599,11 +3600,10 @@ same as `substitute-in-file-name'." (concat minibuffer-completion-base file)))) (list file "" (if-let ((ann (file-name-completion-annotation full))) - (propertize - (concat (propertize " " 'display - `(space :align-to ,(+ max-file 2))) - ann) - 'face 'completions-annotations) + (concat (make-string (- (+ max-file 2) + (string-width file)) + ?\s) + (propertize ann 'face 'completions-annotations)) "")))) files))) @@ -4087,9 +4087,8 @@ See `read-file-name' for the meaning of the arguments." (doc (ignore-errors (documentation sym)))) (when doc (concat - (propertize - " " - 'display `(space :align-to ,(+ max 2))) + (make-string + (- (+ max 2) (string-width cand)) ?\s) (propertize (substring doc 0 (string-search "\n" doc)) 'face 'completions-annotations))))))) @@ -4113,31 +4112,35 @@ See `read-file-name' for the meaning of the arguments." (mapcar #'get-buffer names))))))) (mapcar (lambda (name) - (let ((buf (get-buffer name))) + (let* ((buf (get-buffer name)) + (mode (capitalize + (string-replace + "-mode" "" + (symbol-name (buffer-local-value 'major-mode buf)))))) (list name (concat (if (and (buffer-modified-p buf) (buffer-file-name buf)) (propertize "*" 'face 'completions-annotations) " ") " ") (propertize - (concat (propertize " " 'display `(space :align-to - ,(+ max-name 4))) - (capitalize - (string-replace - "-mode" "" - (symbol-name (buffer-local-value 'major-mode buf)))) + (concat (make-string (- (+ max-name 2) + (string-width name)) + ?\s) + mode (if-let ((file-name (buffer-file-name buf))) - (concat (propertize " " 'display - `(space :align-to - ,(+ max-name max-mode 2))) - file-name) + (concat + (make-string (- (+ max-mode 2) + (string-width mode)) + ?\s) + file-name) (when-let ((proc (get-buffer-process buf))) - (concat (propertize " " 'display - `(space :align-to - ,(+ max-name max-mode 2))) - (format "%s (%s)" - (process-name proc) - (process-status proc)))))) + (concat + (make-string (- (+ max-mode 2) + (string-width mode)) + ?\s) + (format "%s (%s)" + (process-name proc) + (process-status proc)))))) 'face 'completions-annotations)))) names))) diff --git a/lisp/simple.el b/lisp/simple.el index c681cf2c446..6faeeba125a 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2483,8 +2483,6 @@ or (if one of MODES is a minor mode), if it is switched on in BUFFER." (let* ((max-name (seq-max (mapcar #'string-width (or (remove nil command-names) '(""))))) - (spc-dsp1 (propertize " " 'display - `(space :align-to ,(+ max-name 2)))) (bindings (when suggest-key-bindings (with-selected-window (or (minibuffer-selected-window) @@ -2500,9 +2498,7 @@ or (if one of MODES is a minor mode), if it is switched on in BUFFER." command-names)))) (max-bind (seq-max (mapcar #'string-width (or (remove nil (mapcar #'cdr bindings)) - '(""))))) - (spc-dsp2 (propertize " " 'display - `(space :align-to ,(+ max-name max-bind 4))))) + '("")))))) (mapcar (lambda (command-name) (let* ((fun (and (stringp command-name) (intern-soft command-name))) @@ -2511,38 +2507,56 @@ or (if one of MODES is a minor mode), if it is switched on in BUFFER." (alias (symbol-function fun)) (doc (condition-case nil (documentation fun) (error nil))) (doc (and doc (substring doc 0 (string-search "\n" doc)))) - (suffix (cond ((symbolp alias) + (suffix (cond + ((symbolp alias) + (concat + (make-string (- (+ max-name max-bind 4) + (string-width command-name)) + ?\s) + (propertize + (concat + "alias for " + (substitute-quotes (concat "`" + (symbol-name alias) + "'"))) + 'face 'completions-annotations))) + (obsolete + (if-let ((other (car obsolete)) + (string + (cond + ((symbolp other) + (concat "deprecated in favor of `" + (symbol-name other) "'")) + ((stringp other) other)))) + (concat + (make-string (- (+ max-name max-bind 4) + (string-width command-name)) + ?\s) (propertize - (concat spc-dsp2 "alias for " - (substitute-quotes - (concat "`" (symbol-name alias) "'"))) + (substitute-quotes string) 'face 'completions-annotations)) - (obsolete - (if-let ((other (car obsolete)) - (string - (cond - ((symbolp other) - (concat "deprecated in favor of `" - (symbol-name other) "'")) - ((stringp other) other)))) - (concat spc-dsp2 - (propertize - (substitute-quotes string) - 'face 'completions-annotations)) - "")) - (binding - (concat spc-dsp1 - (propertize binding 'face 'help-key-binding) - (when doc - (concat spc-dsp2 - (propertize - doc 'face - 'completions-annotations))))) - (doc - (concat spc-dsp2 (propertize - doc 'face - 'completions-annotations))) - (t "")))) + "")) + (binding + (concat (make-string (- (+ max-name 2) + (string-width command-name)) + ?\s) + (propertize binding 'face 'help-key-binding) + (when doc + (concat + (make-string (- (+ max-bind 2) + (string-width binding)) + ?\s) + (propertize + doc 'face + 'completions-annotations))))) + (doc + (concat (make-string (- (+ max-name max-bind 4) + (string-width command-name)) + ?\s) + (propertize + doc 'face + 'completions-annotations))) + (t "")))) (when extended-command-dim-hyphens (named-let dim ((hy (string-search "-" command-name))) (when hy -- 2.39.5