emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master d93ff94 2/2: Rewrite gnus-search-query-expand-key


From: Eric Abrahamsen
Subject: master d93ff94 2/2: Rewrite gnus-search-query-expand-key
Date: Sat, 10 Jul 2021 23:22:52 -0400 (EDT)

branch: master
commit d93ff9459feb77ed5df0d3af563d1280ff42062f
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>

    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.
---
 lisp/gnus/gnus-search.el            | 22 ++++++++++------------
 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 898b57b..56675eb 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 e30ed9a..6148da6 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))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]