]> git.eshelyaron.com Git - emacs.git/commitdiff
Add completion-tab-width to align prefix chars with names in read-char-by-name
authorJuri Linkov <juri@linkov.net>
Fri, 27 Nov 2020 09:17:12 +0000 (11:17 +0200)
committerJuri Linkov <juri@linkov.net>
Fri, 27 Nov 2020 09:17:12 +0000 (11:17 +0200)
* lisp/international/mule-cmds.el (mule--ucs-names-affixation):
Replace mule--ucs-names-annotation to display chars in prefixes
that implements two FIXME items.
(read-char-by-name): Let-bind completion-tab-width to 4.
Use affixation-function instead of annotation-function.

* lisp/minibuffer.el (completion-tab-width): New variable.
(completion--insert-strings): Align colwidth to tab positions
when completion-tab-width is non-nil.

* lisp/simple.el (completion-setup-function): Set tab-width to
completion-tab-width when completion-tab-width is non-nil.

https://lists.gnu.org/archive/html/emacs-devel/2020-11/msg01263.html

lisp/international/mule-cmds.el
lisp/minibuffer.el
lisp/simple.el

index d361971a1fca81bfadd6bf5175181348cdfca072..d59f2c0ebfca4cd428b46a3682a1d9b74ce5d316 100644 (file)
@@ -3084,13 +3084,11 @@ on encoding."
         (puthash "BELL (BEL)" ?\a names)
         (setq ucs-names names))))
 
-(defun mule--ucs-names-annotation (name)
-  ;; FIXME: It would be much better to add this annotation before rather than
-  ;; after the char name, so the annotations are aligned.
-  ;; FIXME: The default behavior of displaying annotations in italics
-  ;; doesn't work well here.
-  (let ((char (gethash name ucs-names)))
-    (when char (format " (%c)" char))))
+(defun mule--ucs-names-affixation (names)
+  (mapcar (lambda (name)
+            (let ((char (gethash name ucs-names)))
+              (list name (concat (if char (format "%c" char) " ") "\t") "")))
+          names))
 
 (defun char-from-name (string &optional ignore-case)
   "Return a character as a number from its Unicode name STRING.
@@ -3133,13 +3131,14 @@ octal).  Treat otherwise-ambiguous strings like \"BED\" (U+1F6CF)
 as names, not numbers."
   (let* ((enable-recursive-minibuffers t)
         (completion-ignore-case t)
+        (completion-tab-width 4)
         (input
          (completing-read
           prompt
           (lambda (string pred action)
             (if (eq action 'metadata)
                 '(metadata
-                  (annotation-function . mule--ucs-names-annotation)
+                  (affixation-function . mule--ucs-names-affixation)
                   (category . unicode-name))
               (complete-with-action action (ucs-names) string pred)))))
         (char
index 87bf3d36fa46e4cab37a420cfe9a30b4b26e0105..d44d89682216e3e085d3ab311547bddfdf7bff9b 100644 (file)
@@ -1134,6 +1134,7 @@ completion candidates than this number."
 (defvar-local completion-all-sorted-completions nil)
 (defvar-local completion--all-sorted-completions-location nil)
 (defvar completion-cycling nil)      ;Function that takes down the cycling map.
+(defvar completion-tab-width nil)
 
 (defvar completion-fail-discreetly nil
   "If non-nil, stay quiet when there  is no match.")
@@ -1718,6 +1719,11 @@ It also eliminates runs of equal strings."
           (row 0)
            (first t)
           (laststring nil))
+      (unless (or tab-stop-list (null completion-tab-width)
+                  (zerop (mod colwidth completion-tab-width)))
+        ;; Align to tab positions for the case
+        ;; when the caller uses tabs inside prefix.
+        (setq colwidth (- colwidth (mod colwidth completion-tab-width))))
       ;; The insertion should be "sensible" no matter what choices were made
       ;; for the parameters above.
       (dolist (str strings)
@@ -1758,9 +1764,10 @@ It also eliminates runs of equal strings."
                  ;; already past the goal column, there is still
                  ;; a space displayed.
                  (set-text-properties (1- (point)) (point)
-                                      ;; We can't just set tab-width, because
-                                      ;; completion-setup-function will kill
-                                      ;; all local variables :-(
+                                      ;; 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)
index 77888d07f1e25d31f5bdf9f891566eb231ec2ec2..93fda7de8a17b3ea557216151b72b7ab93363f2d 100644 (file)
@@ -8822,6 +8822,8 @@ Called from `temp-buffer-show-hook'."
             insert-fun))
       (set (make-local-variable 'completion-reference-buffer) mainbuf)
       (if base-dir (setq default-directory base-dir))
+      (when completion-tab-width
+        (setq tab-width completion-tab-width))
       ;; Maybe insert help string.
       (when completion-show-help
        (goto-char (point-min))