GNU bug report logs - #14054
completing against a hash-table doesn't work as documented

Previous Next

Package: emacs;

Reported by: Jonas Bernoulli <jonas <at> bernoul.li>

Date: Tue, 26 Mar 2013 02:59:01 UTC

Severity: normal

Done: Stefan Monnier <monnier <at> IRO.UMontreal.CA>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14054 in the body.
You can then email your comments to 14054 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#14054; Package emacs. (Tue, 26 Mar 2013 02:59:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jonas Bernoulli <jonas <at> bernoul.li>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 26 Mar 2013 02:59:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jonas Bernoulli <jonas <at> bernoul.li>
To: bug-gnu-emacs <at> gnu.org
Subject: completing against a hash-table doesn't work as documented
Date: Tue, 26 Mar 2013 03:55:51 +0100
`completing-read's doc-strings sais I should read `try-completion's
(and `all-completions's) doc-string for details on COLLECTION.

`try-completion's doc-string sais:

>   If COLLECTION is a hash-table, all the keys that are strings or
>   symbols are the possible completions.

(1) To my this implies that all other keys are simply ignored, as it
    doesn't say that all keys _have to by_ strings or symbols.

    However using e.g. a vector or number as key causes a
    `wrong-type-argument' error in `test-completion'.

(2) It explicity sais that a key can be a symbol.

    However this causes the same error:

    (let ((ht (make-hash-table)))
      (puthash 'key 'val ht)
      (test-completion "input" ht))

I tried using hash-tables created with all three predefined hash-table
tests `eq', `eql', and `equal; none worked.

Note that depending on the "order" of elements in the hash-table no
error is raised by `test-completion' if a string key "before" the first
non-string key matches:

no error

    (let ((ht (make-hash-table)))
      (puthash "first" 'val ht)
      (puthash 'second 'val ht)
      (test-completion "first" ht))

error

    (let ((ht (make-hash-table)))
      (puthash 'first   'val ht)
      (puthash "second" 'val ht)
      (test-completion "second" ht))

I have tried with 23.4, 24.2, 24.3, and 24.3.50; they all behave the
this way.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14054; Package emacs. (Wed, 27 Mar 2013 19:58:04 GMT) Full text and rfc822 format available.

Message #8 received at 14054 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Jonas Bernoulli <jonas <at> bernoul.li>
Cc: 14054 <at> debbugs.gnu.org
Subject: Re: bug#14054: completing against a hash-table doesn't work as
	documented
Date: Wed, 27 Mar 2013 15:55:07 -0400
> (1) To my this implies that all other keys are simply ignored, as it
>     doesn't say that all keys _have to by_ strings or symbols.
> (2) It explicity sais that a key can be a symbol.

Indeed, test-completion was too strict.  The patch below should
fix this.  Can you confirm?


        Stefan


=== modified file 'src/minibuf.c'
--- src/minibuf.c	2013-01-02 16:13:04 +0000
+++ src/minibuf.c	2013-03-27 19:52:34 +0000
@@ -1800,17 +1800,21 @@
     {
       struct Lisp_Hash_Table *h = XHASH_TABLE (collection);
       i = hash_lookup (h, string, NULL);
+      Lisp_Object key = Qnil;
       if (i >= 0)
 	tem = HASH_KEY (h, i);
       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,
-				       HASH_KEY (h, i), make_number (0) , Qnil,
+				       key, make_number (0) , Qnil,
 				       completion_ignore_case ? Qt : Qnil),
 		     Qt))
 	    {
-	      tem = HASH_KEY (h, i);
+	      tem = key;
 	      break;
 	    }
       if (!STRINGP (tem))






bug closed, send any further explanations to 14054 <at> debbugs.gnu.org and Jonas Bernoulli <jonas <at> bernoul.li> Request was from Stefan Monnier <monnier <at> IRO.UMontreal.CA> to control <at> debbugs.gnu.org. (Tue, 09 Apr 2013 20:14:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 08 May 2013 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 41 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.