unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* test-completion and hash-tables
@ 2003-12-15  3:17 Luc Teirlinck
  2003-12-15  3:46 ` Luc Teirlinck
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Luc Teirlinck @ 2003-12-15  3:17 UTC (permalink / raw)


`try-completion' and `all-completions' use `compare-strings' to compare
strings, in its case-sensitive or case-insensitive variant, depending
on `completion-ignore-case', independently of how the collection of
strings is specified (alist, list, obarray, hash-table, function).
However, when the collection of strings is specified as a hash-table,
then `test-completion' uses whichever test the hash-table uses and, in
particular, `completion-ignore-case' is ignored.

Which of the following possibilities applies?

1.  This is a bug.

2.  `test-completion' is only supposed to be used on the results of
    calling either `try-completion' or `all-completions'.  In all
    cases where I saw `test-completion' being used, this was the case.
    If so, there is no inconsistency, as even `eq' hash-tables will
    work.

3.  It is the job of the programmer passing the hash table to
    `test-completion' to make sure that the hash-table uses the correct
    test, that is, the version of compare-strings that is consistent
    with `completion-ignore-case'.

In cases (2) or (3), this should be clearly documented in
`(elisp)Basic Completion' as well as in the docstring of
`test-completion', which I could do.  But I am not sure which of 1--3
applies.

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: test-completion and hash-tables
  2003-12-15  3:17 test-completion and hash-tables Luc Teirlinck
@ 2003-12-15  3:46 ` Luc Teirlinck
  2003-12-15  4:23 ` Luc Teirlinck
  2003-12-18 23:05 ` Stefan Monnier
  2 siblings, 0 replies; 8+ messages in thread
From: Luc Teirlinck @ 2003-12-15  3:46 UTC (permalink / raw)
  Cc: emacs-devel

>From my previous message:

   2.  `test-completion' is only supposed to be used on the results of
       calling either `try-completion' or `all-completions'.  In all
       cases where I saw `test-completion' being used, this was the case.
       If so, there is no inconsistency, as even `eq' hash-tables will
       work.

This possibility probably makes no sense.  If the match of
`try-completion' is not exact, there still is a problem and for
elements of the list returned by `all-completions', the check is
redundant.  The fact that in all concrete minibuffer completion cases
I tried a bug was avoided, because this assumption held, must have
been a coincidence.

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: test-completion and hash-tables
  2003-12-15  3:17 test-completion and hash-tables Luc Teirlinck
  2003-12-15  3:46 ` Luc Teirlinck
@ 2003-12-15  4:23 ` Luc Teirlinck
  2003-12-18 23:05 ` Stefan Monnier
  2 siblings, 0 replies; 8+ messages in thread
From: Luc Teirlinck @ 2003-12-15  4:23 UTC (permalink / raw)
  Cc: emacs-devel

>From my previous message:
   
   Which of the following possibilities applies?

   1.  This is a bug.

   2.  `test-completion' is only supposed to be used on the results of
       calling either `try-completion' or `all-completions'.  In all
       cases where I saw `test-completion' being used, this was the case.
       If so, there is no inconsistency, as even `eq' hash-tables will
       work.

   3.  It is the job of the programmer passing the hash table to
       `test-completion' to make sure that the hash-table uses the correct
       test, that is, the version of compare-strings that is consistent
       with `completion-ignore-case'.

I just checked that `completing-read' actually does behave differently
for hash tables and ignores `completion-ignore-case', for exact but
not unique completions.  So, even if (2) would be a correct
assumption, we _still_ would _also_ have either (1) or (3).

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: test-completion and hash-tables
  2003-12-15  3:17 test-completion and hash-tables Luc Teirlinck
  2003-12-15  3:46 ` Luc Teirlinck
  2003-12-15  4:23 ` Luc Teirlinck
@ 2003-12-18 23:05 ` Stefan Monnier
  2003-12-18 23:57   ` Luc Teirlinck
  2 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2003-12-18 23:05 UTC (permalink / raw)
  Cc: emacs-devel

> `try-completion' and `all-completions' use `compare-strings' to compare
> strings, in its case-sensitive or case-insensitive variant, depending
> on `completion-ignore-case', independently of how the collection of
> strings is specified (alist, list, obarray, hash-table, function).
> However, when the collection of strings is specified as a hash-table,
> then `test-completion' uses whichever test the hash-table uses and, in
> particular, `completion-ignore-case' is ignored.

This is a bug.
I completely forgot the issue of case-fold when writing the code.
But I think the same problem is present with obarrays (tho you might want
to check), in which case it´s a very long standing bug.


        Stefan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: test-completion and hash-tables
  2003-12-18 23:05 ` Stefan Monnier
@ 2003-12-18 23:57   ` Luc Teirlinck
  2003-12-20  0:28     ` Luc Teirlinck
  2003-12-20 16:58     ` Luc Teirlinck
  0 siblings, 2 replies; 8+ messages in thread
From: Luc Teirlinck @ 2003-12-18 23:57 UTC (permalink / raw)
  Cc: emacs-devel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1822 bytes --]

Stefan Monnier wrote:

   I completely forgot the issue of case-fold when writing the code.
   But I think the same problem is present with obarrays (tho you might want
   to check), in which case it´s a very long standing bug.

The problem indeed occurs for obarrays as well.  Moreover there is an
additional problem for the obarray case.  In the ielm run below,
test-completion threw an error, because minibuffer-completion-table
was nil.  But nothing in the documentation of test-completion talks
about minibuffer-completion-table.  Since test-completion got exported
to Lisp, it is supposed to be a general function, having nothing in
itself to do with minibuffers.  At least, that is what `(elisp)Basic
Completion' currently says.  The docstring does not talk about
minibuffers either.

I do not understand the following line in the Ftest_completion code in
minibuf.c (line 1679 in the latest unchanged version I have):

	    tem = oblookup (Vminibuffer_completion_table,
                            ....

This is the second call to oblookup in the "else if (VECTORP (alist))"
case.

Ielm run illustrating both problems:

===File ~/obarrayielm=======================================
*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (intern "aBcxYz")
aBcxYz
ELISP> (test-completion "AbCXyZ" obarray)
*** Eval error ***  Wrong type argument: vectorp, nil
ELISP> (try-completion "AbCXyZ" obarray)
nil
ELISP> (all-completions "AbCXyZ" obarray)
nil
ELISP> minibuffer-completion-table
nil
ELISP> (setq minibuffer-completion-table obarray)
;; Long output flushed.
ELISP> (test-completion "AbCXyZ" obarray)
nil
ELISP> (setq completion-ignore-case t)
t
ELISP> (test-completion "AbCXyZ" obarray)
nil
ELISP> (test-completion "aBcxYz" obarray)
t
ELISP> ============================================================

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: test-completion and hash-tables
  2003-12-18 23:57   ` Luc Teirlinck
@ 2003-12-20  0:28     ` Luc Teirlinck
  2003-12-21 23:28       ` Stefan Monnier
  2003-12-20 16:58     ` Luc Teirlinck
  1 sibling, 1 reply; 8+ messages in thread
From: Luc Teirlinck @ 2003-12-20  0:28 UTC (permalink / raw)
  Cc: monnier, emacs-devel

>From my previous message:

   I do not understand the following line in the Ftest_completion code in
   minibuf.c (line 1679 in the latest unchanged version I have):

	       tem = oblookup (Vminibuffer_completion_table,
			       ....

I believe I understand now.  The "Vminibuffer_completion_table" was
probably just inadvertently left in from an earlier version of the
function and should be replaced with "alist".

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: test-completion and hash-tables
  2003-12-18 23:57   ` Luc Teirlinck
  2003-12-20  0:28     ` Luc Teirlinck
@ 2003-12-20 16:58     ` Luc Teirlinck
  1 sibling, 0 replies; 8+ messages in thread
From: Luc Teirlinck @ 2003-12-20 16:58 UTC (permalink / raw)
  Cc: monnier, emacs-devel

>From my previous message:

   The problem indeed occurs for obarrays as well.  Moreover there is an
   additional problem for the obarray case.

I believe I have a fix for both problems with obarrays, as well as the
problem for hash tables.  I will still double check some details
before posting a patch.

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: test-completion and hash-tables
  2003-12-20  0:28     ` Luc Teirlinck
@ 2003-12-21 23:28       ` Stefan Monnier
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2003-12-21 23:28 UTC (permalink / raw)
  Cc: emacs-devel

> I believe I understand now.  The "Vminibuffer_completion_table" was
> probably just inadvertently left in from an earlier version of the
> function and should be replaced with "alist".

Indeed.  Sorry about that.  And thanks for investigating,


        Stefan

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-12-21 23:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-15  3:17 test-completion and hash-tables Luc Teirlinck
2003-12-15  3:46 ` Luc Teirlinck
2003-12-15  4:23 ` Luc Teirlinck
2003-12-18 23:05 ` Stefan Monnier
2003-12-18 23:57   ` Luc Teirlinck
2003-12-20  0:28     ` Luc Teirlinck
2003-12-21 23:28       ` Stefan Monnier
2003-12-20 16:58     ` Luc Teirlinck

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).