>From 6b587c804c6a98b30de984e58e56b9ba3794810a Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 27 Nov 2016 14:41:02 -0500 Subject: [PATCH v1 2/2] 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 | 23 ++++++++++++----------- test/src/minibuf-tests.el | 5 +---- 2 files changed, 13 insertions(+), 15 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 @@ DEFUN ("test-completion", Ftest_completion, Stest_completion, 2, 3, 0, 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); + 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, + { + 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)) - { - tem = key; - break; + goto found_matching_key; } - if (!STRINGP (tem)) 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 @@ minibuf-tests--test-completion-regexp (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)) -- 2.9.3