From: Eric Abrahamsen Date: Sat, 10 Jul 2021 17:00:32 +0000 (-0700) Subject: Rewrite gnus-search-query-expand-key X-Git-Tag: emacs-28.0.90~1908 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d93ff9459feb77ed5df0d3af563d1280ff42062f;p=emacs.git 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. --- 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." mark)) (defun gnus-search-query-expand-key (key) - (cond ((test-completion key gnus-search-expandable-keys) - ;; We're done! - key) - ;; There is more than one possible completion. - ((consp (cdr (completion-all-completions - key gnus-search-expandable-keys #'stringp 0))) - (signal 'gnus-search-parse-error - (list (format "Ambiguous keyword: %s" key)))) - ;; Return KEY, either completed or untouched. - ((car-safe (completion-try-completion - key gnus-search-expandable-keys - #'stringp 0))))) + (let ((comp (try-completion key gnus-search-expandable-keys))) + (if (or (eql comp 't) ; Already a key. + (null comp)) ; An unknown key. + key + (if (string= comp key) + ;; KEY matches multiple possible keys. + (signal 'gnus-search-parse-error + (list (format "Ambiguous keyword: %s" key))) + ;; We completed to a unique known key. + comp)))) (defun gnus-search-query-return-string (&optional delimited trim) "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 @@ (default-value 'gnus-search-expandable-keys)) (pairs '(("su" . "subject") - ("sin" . "since")))) + ("sin" . "since") + ("body" . "body") + ("list-id" . "list-id")))) (dolist (p pairs) (should (equal (gnus-search-query-expand-key (car p)) (cdr p))))