emacs-devel
[Top][All Lists]
Advanced

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

Re: Completion


From: Lars Ingebrigtsen
Subject: Re: Completion
Date: Mon, 03 Sep 2018 18:45:10 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> Let's say the set is '("foo" "zot") and the string is "fo".  Then
>> there's one match, and it's unique, of course.  But it's not exact?  So
>> should it return nil, then?
>
> It should return "foo".

Then I guess the documentation should say so...  Does the following look
correct? 

diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi
index d091787a68..4cd2210e2f 100644
--- a/doc/lispref/minibuf.texi
+++ b/doc/lispref/minibuf.texi
@@ -1777,11 +1777,12 @@ Programmed Completion
 @item nil
 This specifies a @code{try-completion} operation.  The function should
 return @code{t} if the specified string is a unique and exact match;
-if there is more than one match, it should return the common substring
-of all matches (if the string is an exact match for one completion
-alternative but also matches other longer alternatives, the return
-value is the string); if there are no matches, it should return
address@hidden
+if there is one match, but it's not an exact match, the function
+should return the match; if there is more than one match, it should
+return the common substring of all matches (if the string is an exact
+match for one completion alternative but also matches other longer
+alternatives, the return value is the string); if there are no
+matches, it should return @code{nil}.
 
 @item t
 This specifies an @code{all-completions} operation.  The function

>> 2) The entire `completing-read' machinery is based on prefix, matches
>> and nothing else; is that right?
>
> No.  The *completion tables* (i.e. the "objects" that define what
> completions are available) only offer methods that work for prefixes.
> But `completing-read` uses completion commands which do a lot more than
> just let the completion tables do the completion for them.

Hm, I see..

>> That is, if you want to do completion on words inside strings (for
>> instance, if you want "foo" to have a match in a collection string
>> like "zot foo bar", then there is no built-in machinery in Emacs
>> for this?
>
> There's completion-try-completion and completion-all-completions, both
> of which offer completions according to completion-styles.

Ah, right, the choices from `completion-styles-alist'.  I thought I had
checked that, but I must have missed that bit.

Thanks.

>> `minibuffer-allow-text-properties' exists.  Would it make sense to add a
>> new variable, like `completion-allow-text-properties', to handle this
>> case as well?
>
> We could, I guess.  What's your use case?

I'm completing over people and films from the IMDB database, and they're
uniquely identified by IDs.  I'd like to complete over the names (or
perhaps also adorn the names with more...  stuff, like years for the
films (but not complete over that bit))), but get the IMDB IDs back
after choosing a name.

So I just propertize the strings before handing them over
`choose-completion', and it almost works except that it strips the text
properties.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



reply via email to

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