diff options
| author | Juri Linkov | 2020-11-27 11:17:12 +0200 |
|---|---|---|
| committer | Juri Linkov | 2020-11-27 11:17:12 +0200 |
| commit | 13e032bab34fb33efee23184c02baa62ebe4dbfc (patch) | |
| tree | 20e5b7b75e65226d369c0b3201de30c2e20f0fe6 | |
| parent | 597a49b2e2ef664cc99a7f1a1ecad7d22df096a1 (diff) | |
| download | emacs-13e032bab34fb33efee23184c02baa62ebe4dbfc.tar.gz emacs-13e032bab34fb33efee23184c02baa62ebe4dbfc.zip | |
Add completion-tab-width to align prefix chars with names in read-char-by-name
* 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
| -rw-r--r-- | lisp/international/mule-cmds.el | 15 | ||||
| -rw-r--r-- | lisp/minibuffer.el | 13 | ||||
| -rw-r--r-- | lisp/simple.el | 2 |
3 files changed, 19 insertions, 11 deletions
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index d361971a1fc..d59f2c0ebfc 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el | |||
| @@ -3084,13 +3084,11 @@ on encoding." | |||
| 3084 | (puthash "BELL (BEL)" ?\a names) | 3084 | (puthash "BELL (BEL)" ?\a names) |
| 3085 | (setq ucs-names names)))) | 3085 | (setq ucs-names names)))) |
| 3086 | 3086 | ||
| 3087 | (defun mule--ucs-names-annotation (name) | 3087 | (defun mule--ucs-names-affixation (names) |
| 3088 | ;; FIXME: It would be much better to add this annotation before rather than | 3088 | (mapcar (lambda (name) |
| 3089 | ;; after the char name, so the annotations are aligned. | 3089 | (let ((char (gethash name ucs-names))) |
| 3090 | ;; FIXME: The default behavior of displaying annotations in italics | 3090 | (list name (concat (if char (format "%c" char) " ") "\t") ""))) |
| 3091 | ;; doesn't work well here. | 3091 | names)) |
| 3092 | (let ((char (gethash name ucs-names))) | ||
| 3093 | (when char (format " (%c)" char)))) | ||
| 3094 | 3092 | ||
| 3095 | (defun char-from-name (string &optional ignore-case) | 3093 | (defun char-from-name (string &optional ignore-case) |
| 3096 | "Return a character as a number from its Unicode name STRING. | 3094 | "Return a character as a number from its Unicode name STRING. |
| @@ -3133,13 +3131,14 @@ octal). Treat otherwise-ambiguous strings like \"BED\" (U+1F6CF) | |||
| 3133 | as names, not numbers." | 3131 | as names, not numbers." |
| 3134 | (let* ((enable-recursive-minibuffers t) | 3132 | (let* ((enable-recursive-minibuffers t) |
| 3135 | (completion-ignore-case t) | 3133 | (completion-ignore-case t) |
| 3134 | (completion-tab-width 4) | ||
| 3136 | (input | 3135 | (input |
| 3137 | (completing-read | 3136 | (completing-read |
| 3138 | prompt | 3137 | prompt |
| 3139 | (lambda (string pred action) | 3138 | (lambda (string pred action) |
| 3140 | (if (eq action 'metadata) | 3139 | (if (eq action 'metadata) |
| 3141 | '(metadata | 3140 | '(metadata |
| 3142 | (annotation-function . mule--ucs-names-annotation) | 3141 | (affixation-function . mule--ucs-names-affixation) |
| 3143 | (category . unicode-name)) | 3142 | (category . unicode-name)) |
| 3144 | (complete-with-action action (ucs-names) string pred))))) | 3143 | (complete-with-action action (ucs-names) string pred))))) |
| 3145 | (char | 3144 | (char |
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 87bf3d36fa4..d44d8968221 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -1134,6 +1134,7 @@ completion candidates than this number." | |||
| 1134 | (defvar-local completion-all-sorted-completions nil) | 1134 | (defvar-local completion-all-sorted-completions nil) |
| 1135 | (defvar-local completion--all-sorted-completions-location nil) | 1135 | (defvar-local completion--all-sorted-completions-location nil) |
| 1136 | (defvar completion-cycling nil) ;Function that takes down the cycling map. | 1136 | (defvar completion-cycling nil) ;Function that takes down the cycling map. |
| 1137 | (defvar completion-tab-width nil) | ||
| 1137 | 1138 | ||
| 1138 | (defvar completion-fail-discreetly nil | 1139 | (defvar completion-fail-discreetly nil |
| 1139 | "If non-nil, stay quiet when there is no match.") | 1140 | "If non-nil, stay quiet when there is no match.") |
| @@ -1718,6 +1719,11 @@ It also eliminates runs of equal strings." | |||
| 1718 | (row 0) | 1719 | (row 0) |
| 1719 | (first t) | 1720 | (first t) |
| 1720 | (laststring nil)) | 1721 | (laststring nil)) |
| 1722 | (unless (or tab-stop-list (null completion-tab-width) | ||
| 1723 | (zerop (mod colwidth completion-tab-width))) | ||
| 1724 | ;; Align to tab positions for the case | ||
| 1725 | ;; when the caller uses tabs inside prefix. | ||
| 1726 | (setq colwidth (- colwidth (mod colwidth completion-tab-width)))) | ||
| 1721 | ;; The insertion should be "sensible" no matter what choices were made | 1727 | ;; The insertion should be "sensible" no matter what choices were made |
| 1722 | ;; for the parameters above. | 1728 | ;; for the parameters above. |
| 1723 | (dolist (str strings) | 1729 | (dolist (str strings) |
| @@ -1758,9 +1764,10 @@ It also eliminates runs of equal strings." | |||
| 1758 | ;; already past the goal column, there is still | 1764 | ;; already past the goal column, there is still |
| 1759 | ;; a space displayed. | 1765 | ;; a space displayed. |
| 1760 | (set-text-properties (1- (point)) (point) | 1766 | (set-text-properties (1- (point)) (point) |
| 1761 | ;; We can't just set tab-width, because | 1767 | ;; We can set tab-width using |
| 1762 | ;; completion-setup-function will kill | 1768 | ;; completion-tab-width, but |
| 1763 | ;; all local variables :-( | 1769 | ;; the caller can prefer using |
| 1770 | ;; \t to align prefixes. | ||
| 1764 | `(display (space :align-to ,column))) | 1771 | `(display (space :align-to ,column))) |
| 1765 | nil)))) | 1772 | nil)))) |
| 1766 | (setq first nil) | 1773 | (setq first nil) |
diff --git a/lisp/simple.el b/lisp/simple.el index 77888d07f1e..93fda7de8a1 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -8822,6 +8822,8 @@ Called from `temp-buffer-show-hook'." | |||
| 8822 | insert-fun)) | 8822 | insert-fun)) |
| 8823 | (set (make-local-variable 'completion-reference-buffer) mainbuf) | 8823 | (set (make-local-variable 'completion-reference-buffer) mainbuf) |
| 8824 | (if base-dir (setq default-directory base-dir)) | 8824 | (if base-dir (setq default-directory base-dir)) |
| 8825 | (when completion-tab-width | ||
| 8826 | (setq tab-width completion-tab-width)) | ||
| 8825 | ;; Maybe insert help string. | 8827 | ;; Maybe insert help string. |
| 8826 | (when completion-show-help | 8828 | (when completion-show-help |
| 8827 | (goto-char (point-min)) | 8829 | (goto-char (point-min)) |