diff options
| author | Eric Abrahamsen | 2021-07-10 10:00:32 -0700 |
|---|---|---|
| committer | Eric Abrahamsen | 2021-07-10 20:22:35 -0700 |
| commit | d93ff9459feb77ed5df0d3af563d1280ff42062f (patch) | |
| tree | a121d6d4218ca8e8e0d73c7a0f777f68f68386ea | |
| parent | e7f6bb38ddb71bfe08bdca87119ff13cd40ecf62 (diff) | |
| download | emacs-d93ff9459feb77ed5df0d3af563d1280ff42062f.tar.gz emacs-d93ff9459feb77ed5df0d3af563d1280ff42062f.zip | |
Rewrite gnus-search-query-expand-key
* lisp/gnus/gnus-search.el (gnus-search-query-expand-key): There was a
misunderstanding about how completion-all-completion works (if the
test string can't be completed, the whole table is returned). Simplify
to use try-completion.
* test/lisp/gnus/gnus-search-tests.el (gnus-s-expand-keyword): Ensure
that an unknown/uncompletable keyword is returned unmolested.
| -rw-r--r-- | lisp/gnus/gnus-search.el | 22 | ||||
| -rw-r--r-- | test/lisp/gnus/gnus-search-tests.el | 4 |
2 files changed, 13 insertions, 13 deletions
diff --git a/lisp/gnus/gnus-search.el b/lisp/gnus/gnus-search.el index 898b57bcef8..56675eb8651 100644 --- a/lisp/gnus/gnus-search.el +++ b/lisp/gnus/gnus-search.el | |||
| @@ -629,18 +629,16 @@ gnus-*-mark marks, and return an appropriate string." | |||
| 629 | mark)) | 629 | mark)) |
| 630 | 630 | ||
| 631 | (defun gnus-search-query-expand-key (key) | 631 | (defun gnus-search-query-expand-key (key) |
| 632 | (cond ((test-completion key gnus-search-expandable-keys) | 632 | (let ((comp (try-completion key gnus-search-expandable-keys))) |
| 633 | ;; We're done! | 633 | (if (or (eql comp 't) ; Already a key. |
| 634 | key) | 634 | (null comp)) ; An unknown key. |
| 635 | ;; There is more than one possible completion. | 635 | key |
| 636 | ((consp (cdr (completion-all-completions | 636 | (if (string= comp key) |
| 637 | key gnus-search-expandable-keys #'stringp 0))) | 637 | ;; KEY matches multiple possible keys. |
| 638 | (signal 'gnus-search-parse-error | 638 | (signal 'gnus-search-parse-error |
| 639 | (list (format "Ambiguous keyword: %s" key)))) | 639 | (list (format "Ambiguous keyword: %s" key))) |
| 640 | ;; Return KEY, either completed or untouched. | 640 | ;; We completed to a unique known key. |
| 641 | ((car-safe (completion-try-completion | 641 | comp)))) |
| 642 | key gnus-search-expandable-keys | ||
| 643 | #'stringp 0))))) | ||
| 644 | 642 | ||
| 645 | (defun gnus-search-query-return-string (&optional delimited trim) | 643 | (defun gnus-search-query-return-string (&optional delimited trim) |
| 646 | "Return a string from the current buffer. | 644 | "Return a string from the current buffer. |
diff --git a/test/lisp/gnus/gnus-search-tests.el b/test/lisp/gnus/gnus-search-tests.el index e30ed9a80a7..6148da65621 100644 --- a/test/lisp/gnus/gnus-search-tests.el +++ b/test/lisp/gnus/gnus-search-tests.el | |||
| @@ -49,7 +49,9 @@ | |||
| 49 | (default-value 'gnus-search-expandable-keys)) | 49 | (default-value 'gnus-search-expandable-keys)) |
| 50 | (pairs | 50 | (pairs |
| 51 | '(("su" . "subject") | 51 | '(("su" . "subject") |
| 52 | ("sin" . "since")))) | 52 | ("sin" . "since") |
| 53 | ("body" . "body") | ||
| 54 | ("list-id" . "list-id")))) | ||
| 53 | (dolist (p pairs) | 55 | (dolist (p pairs) |
| 54 | (should (equal (gnus-search-query-expand-key (car p)) | 56 | (should (equal (gnus-search-query-expand-key (car p)) |
| 55 | (cdr p)))) | 57 | (cdr p)))) |