emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 2a3420d 3/3: Give test-completion's PREDICATE the h


From: Noam Postavsky
Subject: [Emacs-diffs] master 2a3420d 3/3: Give test-completion's PREDICATE the hashtable key
Date: Wed, 7 Dec 2016 03:28:28 +0000 (UTC)

branch: master
commit 2a3420d94206a97f094580e06c25af91d5949516
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Give test-completion's PREDICATE the hashtable key
    
    For hashtable entries with symbol keys, `test-completion' would convert
    the key to a string before calling PREDICATE, unlike `try-completion'
    and `all-completions'.
    
    * src/minibuf.c (Ftest_completion): Pass original key from hashtable.
---
 src/minibuf.c             |   33 +++++++++++++++++----------------
 test/src/minibuf-tests.el |    5 +----
 2 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/minibuf.c b/src/minibuf.c
index 6c694cb..7c5af34 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1736,26 +1736,27 @@ the values STRING, PREDICATE and `lambda'.  */)
   else if (HASH_TABLE_P (collection))
     {
       struct Lisp_Hash_Table *h = XHASH_TABLE (collection);
-      Lisp_Object key = Qnil;
       i = hash_lookup (h, string, NULL);
       if (i >= 0)
-       tem = HASH_KEY (h, i);
+        {
+          tem = HASH_KEY (h, i);
+          goto found_matching_key;
+        }
       else
        for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
-         if (!NILP (HASH_HASH (h, i))
-             && (key = HASH_KEY (h, i),
-                 SYMBOLP (key) ? key = Fsymbol_name (key) : key,
-                 STRINGP (key))
-             && EQ (Fcompare_strings (string, make_number (0), Qnil,
-                                      key, make_number (0) , Qnil,
-                                      completion_ignore_case ? Qt : Qnil),
-                    Qt))
-           {
-             tem = key;
-             break;
-           }
-      if (!STRINGP (tem))
-       return Qnil;
+          {
+            if (NILP (HASH_HASH (h, i))) continue;
+            tem = HASH_KEY (h, i);
+            Lisp_Object strkey = (SYMBOLP (tem) ? Fsymbol_name (tem) : tem);
+            if (!STRINGP (strkey)) continue;
+            if (EQ (Fcompare_strings (string, Qnil, Qnil,
+                                      strkey, Qnil, Qnil,
+                                      completion_ignore_case ? Qt : Qnil),
+                    Qt))
+              goto found_matching_key;
+          }
+      return Qnil;
+    found_matching_key: ;
     }
   else
     return call3 (collection, string, predicate, Qlambda);
diff --git a/test/src/minibuf-tests.el b/test/src/minibuf-tests.el
index 98b8614..82ac037 100644
--- a/test/src/minibuf-tests.el
+++ b/test/src/minibuf-tests.el
@@ -394,10 +394,7 @@
 (ert-deftest test-completion-symbol-hashtable-predicate ()
   (minibuf-tests--test-completion-pred
    #'minibuf-tests--strings-to-symbol-hashtable
-   ;; The predicate recieves a string as the key in this case.
-   (lambda (table)
-     (let ((in-table (minibuf-tests--part-of-hashtable table)))
-       (lambda (k v) (funcall in-table (intern k) v))))))
+   #'minibuf-tests--part-of-hashtable))
 (ert-deftest test-completion-symbol-hashtable-completion-regexp ()
   (minibuf-tests--test-completion-regexp
    #'minibuf-tests--strings-to-symbol-hashtable))



reply via email to

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