diff options
| author | Stefan Monnier | 2019-10-29 16:17:14 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2019-10-29 16:17:14 -0400 |
| commit | 7208c4f8c930a7d91f89fab154fff8a9df0aeeeb (patch) | |
| tree | ef090258f0d79ecff2b7e22d871dddcbd975d603 | |
| parent | 6d2c73e8c725863db5d4fbbf1a59e35ebaa5f6b4 (diff) | |
| download | emacs-7208c4f8c930a7d91f89fab154fff8a9df0aeeeb.tar.gz emacs-7208c4f8c930a7d91f89fab154fff8a9df0aeeeb.zip | |
* lisp/minibuffer.el: Tweak and undo parts of recent changes
(completion-metadata): Always return a fresh new cons cell.
(completion--nth-completion): Don't bother calling adjust-metadata
if the result won't be used.
(completion-pcm--hilit-commonality): Revert recent change which had
removed support for `completions-first-difference` in `substring` and
`partial-completion` styles.
(completion--flex-adjust-metadata): Treat the arg as immutable.
| -rw-r--r-- | lisp/minibuffer.el | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 9a8db078193..43dd277a2e4 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -129,9 +129,9 @@ This metadata is an alist. Currently understood keys are: | |||
| 129 | The metadata of a completion table should be constant between two boundaries." | 129 | The metadata of a completion table should be constant between two boundaries." |
| 130 | (let ((metadata (if (functionp table) | 130 | (let ((metadata (if (functionp table) |
| 131 | (funcall table string pred 'metadata)))) | 131 | (funcall table string pred 'metadata)))) |
| 132 | (if (eq (car-safe metadata) 'metadata) | 132 | (cons 'metadata |
| 133 | metadata | 133 | (if (eq (car-safe metadata) 'metadata) |
| 134 | '(metadata)))) | 134 | (cdr metadata))))) |
| 135 | 135 | ||
| 136 | (defun completion--field-metadata (field-start) | 136 | (defun completion--field-metadata (field-start) |
| 137 | (completion-metadata (buffer-substring-no-properties field-start (point)) | 137 | (completion-metadata (buffer-substring-no-properties field-start (point)) |
| @@ -909,9 +909,6 @@ This overrides the defaults specified in `completion-category-defaults'." | |||
| 909 | 909 | ||
| 910 | (defun completion--nth-completion (n string table pred point metadata) | 910 | (defun completion--nth-completion (n string table pred point metadata) |
| 911 | "Call the Nth method of completion styles." | 911 | "Call the Nth method of completion styles." |
| 912 | (unless metadata | ||
| 913 | (setq metadata | ||
| 914 | (completion-metadata (substring string 0 point) table pred))) | ||
| 915 | ;; We provide special support for quoting/unquoting here because it cannot | 912 | ;; We provide special support for quoting/unquoting here because it cannot |
| 916 | ;; reliably be done within the normal completion-table routines: Completion | 913 | ;; reliably be done within the normal completion-table routines: Completion |
| 917 | ;; styles such as `substring' or `partial-completion' need to match the | 914 | ;; styles such as `substring' or `partial-completion' need to match the |
| @@ -922,13 +919,16 @@ This overrides the defaults specified in `completion-category-defaults'." | |||
| 922 | ;; The quote/unquote function needs to come from the completion table (rather | 919 | ;; The quote/unquote function needs to come from the completion table (rather |
| 923 | ;; than from completion-extra-properties) because it may apply only to some | 920 | ;; than from completion-extra-properties) because it may apply only to some |
| 924 | ;; part of the string (e.g. substitute-in-file-name). | 921 | ;; part of the string (e.g. substitute-in-file-name). |
| 925 | (let* ((requote | 922 | (let* ((md (or metadata |
| 923 | (completion-metadata (substring string 0 point) table pred))) | ||
| 924 | (requote | ||
| 926 | (when (and | 925 | (when (and |
| 927 | (completion-metadata-get metadata 'completion--unquote-requote) | 926 | (completion-metadata-get md 'completion--unquote-requote) |
| 928 | ;; Sometimes a table's metadata is used on another | 927 | ;; Sometimes a table's metadata is used on another |
| 929 | ;; table (typically that other table is just a list taken | 928 | ;; table (typically that other table is just a list taken |
| 930 | ;; from the output of `all-completions' or something equivalent, | 929 | ;; from the output of `all-completions' or something |
| 931 | ;; for progressive refinement). See bug#28898 and bug#16274. | 930 | ;; equivalent, for progressive refinement). |
| 931 | ;; See bug#28898 and bug#16274. | ||
| 932 | ;; FIXME: Rather than do nothing, we should somehow call | 932 | ;; FIXME: Rather than do nothing, we should somehow call |
| 933 | ;; the original table, in that case! | 933 | ;; the original table, in that case! |
| 934 | (functionp table)) | 934 | (functionp table)) |
| @@ -945,9 +945,9 @@ This overrides the defaults specified in `completion-category-defaults'." | |||
| 945 | completion-styles-alist)) | 945 | completion-styles-alist)) |
| 946 | string table pred point))) | 946 | string table pred point))) |
| 947 | (and probe (cons probe style)))) | 947 | (and probe (cons probe style)))) |
| 948 | (completion--styles metadata))) | 948 | (completion--styles md))) |
| 949 | (adjust-fn (get (cdr result-and-style) 'completion--adjust-metadata))) | 949 | (adjust-fn (get (cdr result-and-style) 'completion--adjust-metadata))) |
| 950 | (when adjust-fn | 950 | (when (and adjust-fn metadata) |
| 951 | (setcdr metadata (cdr (funcall adjust-fn metadata)))) | 951 | (setcdr metadata (cdr (funcall adjust-fn metadata)))) |
| 952 | (if requote | 952 | (if requote |
| 953 | (funcall requote (car result-and-style) n) | 953 | (funcall requote (car result-and-style) n) |
| @@ -1684,14 +1684,11 @@ See also `display-completion-list'.") | |||
| 1684 | 1684 | ||
| 1685 | (defface completions-first-difference | 1685 | (defface completions-first-difference |
| 1686 | '((t (:inherit bold))) | 1686 | '((t (:inherit bold))) |
| 1687 | "Face for the first uncommon character in prefix completions. | 1687 | "Face for the first character after point in completions. |
| 1688 | See also the face `completions-common-part'.") | 1688 | See also the face `completions-common-part'.") |
| 1689 | 1689 | ||
| 1690 | (defface completions-common-part '((t nil)) | 1690 | (defface completions-common-part '((t nil)) |
| 1691 | "Face for the common prefix substring in completions. | 1691 | "Face for the parts of completions which matched the pattern. |
| 1692 | The idea of this face is that you can use it to make the common parts | ||
| 1693 | less visible than normal, so that the differing parts are emphasized | ||
| 1694 | by contrast. | ||
| 1695 | See also the face `completions-first-difference'.") | 1692 | See also the face `completions-first-difference'.") |
| 1696 | 1693 | ||
| 1697 | (defun completion-hilit-commonality (completions prefix-len &optional base-size) | 1694 | (defun completion-hilit-commonality (completions prefix-len &optional base-size) |
| @@ -3078,6 +3075,7 @@ one-letter-long matches).") | |||
| 3078 | (defun completion-pcm--hilit-commonality (pattern completions) | 3075 | (defun completion-pcm--hilit-commonality (pattern completions) |
| 3079 | (when completions | 3076 | (when completions |
| 3080 | (let* ((re (completion-pcm--pattern->regex pattern 'group)) | 3077 | (let* ((re (completion-pcm--pattern->regex pattern 'group)) |
| 3078 | (point-idx (completion-pcm--pattern-point-idx pattern)) | ||
| 3081 | (case-fold-search completion-ignore-case)) | 3079 | (case-fold-search completion-ignore-case)) |
| 3082 | (mapcar | 3080 | (mapcar |
| 3083 | (lambda (str) | 3081 | (lambda (str) |
| @@ -3085,7 +3083,8 @@ one-letter-long matches).") | |||
| 3085 | (setq str (copy-sequence str)) | 3083 | (setq str (copy-sequence str)) |
| 3086 | (unless (string-match re str) | 3084 | (unless (string-match re str) |
| 3087 | (error "Internal error: %s does not match %s" re str)) | 3085 | (error "Internal error: %s does not match %s" re str)) |
| 3088 | (let* ((md (match-data)) | 3086 | (let* ((pos (if point-idx (match-beginning point-idx) (match-end 0))) |
| 3087 | (md (match-data)) | ||
| 3089 | (start (pop md)) | 3088 | (start (pop md)) |
| 3090 | (end (pop md)) | 3089 | (end (pop md)) |
| 3091 | (len (length str)) | 3090 | (len (length str)) |
| @@ -3153,6 +3152,10 @@ one-letter-long matches).") | |||
| 3153 | (put-text-property start end | 3152 | (put-text-property start end |
| 3154 | 'font-lock-face 'completions-common-part | 3153 | 'font-lock-face 'completions-common-part |
| 3155 | str) | 3154 | str) |
| 3155 | (if (> (length str) pos) | ||
| 3156 | (put-text-property pos (1+ pos) | ||
| 3157 | 'font-lock-face 'completions-first-difference | ||
| 3158 | str)) | ||
| 3156 | (unless (zerop (length str)) | 3159 | (unless (zerop (length str)) |
| 3157 | (put-text-property | 3160 | (put-text-property |
| 3158 | 0 1 'completion-score | 3161 | 0 1 'completion-score |
| @@ -3495,12 +3498,14 @@ that is non-nil." | |||
| 3495 | (or (equal c1 minibuffer-default) | 3498 | (or (equal c1 minibuffer-default) |
| 3496 | (> (get-text-property 0 'completion-score c1) | 3499 | (> (get-text-property 0 'completion-score c1) |
| 3497 | (get-text-property 0 'completion-score c2))))))))) | 3500 | (get-text-property 0 'completion-score c2))))))))) |
| 3498 | (let ((alist (cdr metadata))) | 3501 | `(metadata |
| 3499 | (setf (alist-get 'display-sort-function alist) | 3502 | (display-sort-function |
| 3500 | (compose-flex-sort-fn (alist-get 'display-sort-function alist))) | 3503 | . ,(compose-flex-sort-fn |
| 3501 | (setf (alist-get 'cycle-sort-function alist) | 3504 | (completion-metadata-get metadata 'display-sort-function))) |
| 3502 | (compose-flex-sort-fn (alist-get 'cycle-sort-function alist))) | 3505 | (cycle-sort-function |
| 3503 | `(metadata . ,alist)))) | 3506 | . ,(compose-flex-sort-fn |
| 3507 | (completion-metadata-get metadata 'cycle-sort-function))) | ||
| 3508 | ,@(cdr metadata)))) | ||
| 3504 | 3509 | ||
| 3505 | (defun completion-flex--make-flex-pattern (pattern) | 3510 | (defun completion-flex--make-flex-pattern (pattern) |
| 3506 | "Convert PCM-style PATTERN into PCM-style flex pattern. | 3511 | "Convert PCM-style PATTERN into PCM-style flex pattern. |