]> git.eshelyaron.com Git - emacs.git/commitdiff
; Align completion annotations with spaces for multi-column format
authorEshel Yaron <me@eshelyaron.com>
Tue, 16 Jan 2024 09:44:46 +0000 (10:44 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 16 Jan 2024 09:44:46 +0000 (10:44 +0100)
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
lisp/minibuffer.el
lisp/simple.el

index a85ffa212998ec02002a4cfb3d6008ddbb342192..a67aa41acc19533a677691800dc00272e121008d 100644 (file)
@@ -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) "" "")))
index 31833e6e36be4cfdcc50a9633b9e6d8d9cd60f44..fe8d513c19582e09bc9a6483cd31cf15fed7dba8 100644 (file)
@@ -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)))
 
index c681cf2c44688fbe01d1ddc23dd819bcf91422b3..6faeeba125a7a6ccfbede9df6ac69b6c64fed05a 100644 (file)
@@ -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