diff options
| author | Juri Linkov | 2024-01-09 19:57:50 +0200 |
|---|---|---|
| committer | Juri Linkov | 2024-01-09 19:57:50 +0200 |
| commit | aff1d53cd466b64ded08d5cf12f83e5746704c07 (patch) | |
| tree | ad65a89f8e6f32e84501f32dd5f3cdb24d24703e | |
| parent | 29e59b835c86e1ebac12adcb28ab7e1d0c275b2f (diff) | |
| download | emacs-aff1d53cd466b64ded08d5cf12f83e5746704c07.tar.gz emacs-aff1d53cd466b64ded08d5cf12f83e5746704c07.zip | |
Support more metadata properties in completion-extra-properties (bug#68214)
* doc/lispref/minibuf.texi (Completion Variables): Add
to the table of completion-extra-properties new items:
`group-function', `display-sort-function', `cycle-sort-function'.
* lisp/icomplete.el (icomplete--augment): Remove unnecessary
plist-get from completion-extra-properties since now
completion-metadata-get does this.
* lisp/minibuffer.el (completion-metadata-get): Use plist-get to
get prop from completion-extra-properties and cache the keyword.
Thanks to Daniel Mendler <mail@daniel-mendler.de>.
(completion-extra-properties): Mention new properties in docstring.
(minibuffer-completion-help): Remove unnecessary
plist-get from completion-extra-properties since now
completion-metadata-get does this.
* lisp/net/eww.el (eww-switch-to-buffer):
* test/lisp/minibuffer-tests.el (completions-affixation-navigation-test):
Unquote lambda in completion-extra-properties.
| -rw-r--r-- | doc/lispref/minibuf.texi | 9 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/icomplete.el | 6 | ||||
| -rw-r--r-- | lisp/minibuffer.el | 33 | ||||
| -rw-r--r-- | lisp/net/eww.el | 7 | ||||
| -rw-r--r-- | test/lisp/minibuffer-tests.el | 10 |
6 files changed, 49 insertions, 21 deletions
diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index 8d25a53161e..18df44256a8 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi | |||
| @@ -1928,6 +1928,15 @@ element of the returned list must be a three-element list, the | |||
| 1928 | completion, a prefix string, and a suffix string. This function takes | 1928 | completion, a prefix string, and a suffix string. This function takes |
| 1929 | priority over @code{:annotation-function}. | 1929 | priority over @code{:annotation-function}. |
| 1930 | 1930 | ||
| 1931 | @item :group-function | ||
| 1932 | The function to group completions. | ||
| 1933 | |||
| 1934 | @item :display-sort-function | ||
| 1935 | The function to sort entries in the @file{*Completions*} buffer. | ||
| 1936 | |||
| 1937 | @item :cycle-sort-function | ||
| 1938 | The function to sort entries when cycling. | ||
| 1939 | |||
| 1931 | @item :exit-function | 1940 | @item :exit-function |
| 1932 | The value should be a function to run after performing completion. | 1941 | The value should be a function to run after performing completion. |
| 1933 | The function should accept two arguments, @var{string} and | 1942 | The function should accept two arguments, @var{string} and |
| @@ -752,6 +752,11 @@ The new supported completion properties are 'cycle-sort-function', | |||
| 752 | 'completion-category-overrides' that will override the properties | 752 | 'completion-category-overrides' that will override the properties |
| 753 | defined in completion metadata. | 753 | defined in completion metadata. |
| 754 | 754 | ||
| 755 | +++ | ||
| 756 | *** 'completion-extra-properties' supports more metadata. | ||
| 757 | The new supported completion properties are 'group-function', | ||
| 758 | 'display-sort-function', 'cycle-sort-function'. | ||
| 759 | |||
| 755 | ** Pcomplete | 760 | ** Pcomplete |
| 756 | 761 | ||
| 757 | --- | 762 | --- |
diff --git a/lisp/icomplete.el b/lisp/icomplete.el index d49714f3204..aa3c5680a7e 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el | |||
| @@ -789,10 +789,8 @@ and SUFFIX, if non-nil, are obtained from `affixation-function' or | |||
| 789 | `group-function'. Consecutive `equal' sections are avoided. | 789 | `group-function'. Consecutive `equal' sections are avoided. |
| 790 | COMP is the element in PROSPECTS or a transformation also given | 790 | COMP is the element in PROSPECTS or a transformation also given |
| 791 | by `group-function''s second \"transformation\" protocol." | 791 | by `group-function''s second \"transformation\" protocol." |
| 792 | (let* ((aff-fun (or (completion-metadata-get md 'affixation-function) | 792 | (let* ((aff-fun (completion-metadata-get md 'affixation-function)) |
| 793 | (plist-get completion-extra-properties :affixation-function))) | 793 | (ann-fun (completion-metadata-get md 'annotation-function)) |
| 794 | (ann-fun (or (completion-metadata-get md 'annotation-function) | ||
| 795 | (plist-get completion-extra-properties :annotation-function))) | ||
| 796 | (grp-fun (and completions-group | 794 | (grp-fun (and completions-group |
| 797 | (completion-metadata-get md 'group-function))) | 795 | (completion-metadata-get md 'group-function))) |
| 798 | (annotated | 796 | (annotated |
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 04b36f03d11..42d04e0ff96 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -151,15 +151,25 @@ The metadata of a completion table should be constant between two boundaries." | |||
| 151 | minibuffer-completion-predicate)) | 151 | minibuffer-completion-predicate)) |
| 152 | 152 | ||
| 153 | (defun completion-metadata-get (metadata prop) | 153 | (defun completion-metadata-get (metadata prop) |
| 154 | "Get PROP from completion METADATA. | 154 | "Get property PROP from completion METADATA. |
| 155 | If the metadata specifies a completion category, the variables | 155 | If the metadata specifies a completion category, the variables |
| 156 | `completion-category-overrides' and | 156 | `completion-category-overrides' and |
| 157 | `completion-category-defaults' take precedence." | 157 | `completion-category-defaults' take precedence for |
| 158 | category-specific overrides. If the completion metadata does not | ||
| 159 | specify the property, the `completion-extra-properties' plist is | ||
| 160 | consulted. Note that the keys of the | ||
| 161 | `completion-extra-properties' plist are keyword symbols, not | ||
| 162 | plain symbols." | ||
| 158 | (if-let (((not (eq prop 'category))) | 163 | (if-let (((not (eq prop 'category))) |
| 159 | (cat (alist-get 'category metadata)) | 164 | (cat (alist-get 'category metadata)) |
| 160 | (over (completion--category-override cat prop))) | 165 | (over (completion--category-override cat prop))) |
| 161 | (cdr over) | 166 | (cdr over) |
| 162 | (alist-get prop metadata))) | 167 | (or (alist-get prop metadata) |
| 168 | (plist-get completion-extra-properties | ||
| 169 | ;; Cache the keyword | ||
| 170 | (or (get prop 'completion-extra-properties--keyword) | ||
| 171 | (put prop 'completion-extra-properties--keyword | ||
| 172 | (intern (concat ":" (symbol-name prop))))))))) | ||
| 163 | 173 | ||
| 164 | (defun complete-with-action (action collection string predicate) | 174 | (defun complete-with-action (action collection string predicate) |
| 165 | "Perform completion according to ACTION. | 175 | "Perform completion according to ACTION. |
| @@ -2447,6 +2457,15 @@ These include: | |||
| 2447 | `:annotation-function' when both are provided, so only this | 2457 | `:annotation-function' when both are provided, so only this |
| 2448 | function is used. | 2458 | function is used. |
| 2449 | 2459 | ||
| 2460 | `:group-function': Function for grouping the completion candidates. | ||
| 2461 | |||
| 2462 | `:display-sort-function': Function to sort entries in *Completions*. | ||
| 2463 | |||
| 2464 | `:cycle-sort-function': Function to sort entries when cycling. | ||
| 2465 | |||
| 2466 | See more information about these functions above | ||
| 2467 | in `completion-metadata'. | ||
| 2468 | |||
| 2450 | `:exit-function': Function to run after completion is performed. | 2469 | `:exit-function': Function to run after completion is performed. |
| 2451 | 2470 | ||
| 2452 | The function must accept two arguments, STRING and STATUS. | 2471 | The function must accept two arguments, STRING and STATUS. |
| @@ -2569,12 +2588,8 @@ The candidate will still be chosen by `choose-completion' unless | |||
| 2569 | base-size md | 2588 | base-size md |
| 2570 | minibuffer-completion-table | 2589 | minibuffer-completion-table |
| 2571 | minibuffer-completion-predicate)) | 2590 | minibuffer-completion-predicate)) |
| 2572 | (ann-fun (or (completion-metadata-get all-md 'annotation-function) | 2591 | (ann-fun (completion-metadata-get all-md 'annotation-function)) |
| 2573 | (plist-get completion-extra-properties | 2592 | (aff-fun (completion-metadata-get all-md 'affixation-function)) |
| 2574 | :annotation-function))) | ||
| 2575 | (aff-fun (or (completion-metadata-get all-md 'affixation-function) | ||
| 2576 | (plist-get completion-extra-properties | ||
| 2577 | :affixation-function))) | ||
| 2578 | (sort-fun (completion-metadata-get all-md 'display-sort-function)) | 2593 | (sort-fun (completion-metadata-get all-md 'display-sort-function)) |
| 2579 | (group-fun (completion-metadata-get all-md 'group-function)) | 2594 | (group-fun (completion-metadata-get all-md 'group-function)) |
| 2580 | (mainbuf (current-buffer)) | 2595 | (mainbuf (current-buffer)) |
diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 22f07cbc5b4..6c46ef0fedb 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el | |||
| @@ -2064,9 +2064,10 @@ If CHARSET is nil then use UTF-8." | |||
| 2064 | "Prompt for an EWW buffer to display in the selected window." | 2064 | "Prompt for an EWW buffer to display in the selected window." |
| 2065 | (interactive nil eww-mode) | 2065 | (interactive nil eww-mode) |
| 2066 | (let ((completion-extra-properties | 2066 | (let ((completion-extra-properties |
| 2067 | '(:annotation-function (lambda (buf) | 2067 | `(:annotation-function |
| 2068 | (with-current-buffer buf | 2068 | ,(lambda (buf) |
| 2069 | (format " %s" (eww-current-url)))))) | 2069 | (with-current-buffer buf |
| 2070 | (format " %s" (eww-current-url)))))) | ||
| 2070 | (curbuf (current-buffer))) | 2071 | (curbuf (current-buffer))) |
| 2071 | (pop-to-buffer-same-window | 2072 | (pop-to-buffer-same-window |
| 2072 | (read-buffer "Switch to EWW buffer: " | 2073 | (read-buffer "Switch to EWW buffer: " |
diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el index 6dc15d0801f..c1fe3032cb5 100644 --- a/test/lisp/minibuffer-tests.el +++ b/test/lisp/minibuffer-tests.el | |||
| @@ -505,11 +505,11 @@ | |||
| 505 | 505 | ||
| 506 | (ert-deftest completions-affixation-navigation-test () | 506 | (ert-deftest completions-affixation-navigation-test () |
| 507 | (let ((completion-extra-properties | 507 | (let ((completion-extra-properties |
| 508 | '(:affixation-function | 508 | `(:affixation-function |
| 509 | (lambda (completions) | 509 | ,(lambda (completions) |
| 510 | (mapcar (lambda (c) | 510 | (mapcar (lambda (c) |
| 511 | (list c "prefix " " suffix")) | 511 | (list c "prefix " " suffix")) |
| 512 | completions))))) | 512 | completions))))) |
| 513 | (completing-read-with-minibuffer-setup | 513 | (completing-read-with-minibuffer-setup |
| 514 | '("aa" "ab" "ac") | 514 | '("aa" "ab" "ac") |
| 515 | (insert "a") | 515 | (insert "a") |