]> git.eshelyaron.com Git - emacs.git/commitdiff
Rewrite gnus-search-query-expand-key
authorEric Abrahamsen <eric@ericabrahamsen.net>
Sat, 10 Jul 2021 17:00:32 +0000 (10:00 -0700)
committerEric Abrahamsen <eric@ericabrahamsen.net>
Sun, 11 Jul 2021 03:22:35 +0000 (20:22 -0700)
* 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.

lisp/gnus/gnus-search.el
test/lisp/gnus/gnus-search-tests.el

index 898b57bcef81d622fc268dfd7262b1198d7aa19b..56675eb8651ac850c01a7b027a8ee00fa6a4dcf4 100644 (file)
@@ -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.
index e30ed9a80a78de4330df722711cce7b10988f16a..6148da656215e07a2dcca17c8ba65f5422b917ef 100644 (file)
@@ -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))))