unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
To: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Completion
Date: Wed, 05 Sep 2018 18:03:17 -0500	[thread overview]
Message-ID: <867ejzfsy2.fsf@stephe-leake.org> (raw)
In-Reply-To: <m35zzm1nti.fsf@gnus.org> (Lars Ingebrigtsen's message of "Mon, 03 Sep 2018 19:40:57 +0200")

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>>> +if there is one match, but it's not an exact match, the function
>>> +should return the match;
>>
>> Actualy, when there is one match, "the common substring of all matches"
>> is that match, so I think we can make it simpler, e.g.:
>>
>>     This specifies a @code{try-completion} operation.  The function should
>>     return @code{t} if the specified string is a unique and exact match;
>>     It should return @code{nil} if there are no matches; and it should
>>     return the longest common prefix of all matches otherwise.
>
> Yes, that seems clearer.
>
>> What if the user writes the whole name by hand: how do you get the ID in
>> this case?  In my experience, the need to handle that "manual case" most
>> of the time ends up covering just as well the case where the user
>> selected an entry from the *Completions*.
>
> Oh, I didn't even consider that the user may type the name.  Yeah,
> you're right; returning the text properties wouldn't really be generally
> useful here...

I had a similar problem completing on names in an Ada buffer; names can
be overloaded, so just the name is not unique.

So I included the line number with the name in the completion table;
each entry looks like:

foo<1>
bar<10>
foo<20>

The user sees those strings, and can complete on the line number to pick
the instance of an overloaded name.

Then the code can retrieve the line number from the completed string.

If the user types the name without completing, you're out of luck (my
code throws an unhelpful error). But that never happens in practice,
since completion works so nicely.

I use icomplete-mode, with completion options set so I have to type C-j
to get out of a completing read with non-matching text.

This code is in a development version of ada-mode; available via email
on request.

For IMDB, you could use | to separate fields, and complete on
filmname|year|actor1|...

Whether the user will ever or often enter text without completing
depends on the use case; finding function names in source code is a much
smaller problem than finding films in IMDB.

-- 
-- Stephe



      reply	other threads:[~2018-09-05 23:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-01  9:51 Completion Lars Ingebrigtsen
2018-09-01 14:49 ` Completion Drew Adams
2018-09-03 16:48   ` Completion Lars Ingebrigtsen
2018-09-01 15:14 ` Completion Stefan Monnier
2018-09-03 16:45   ` Completion Lars Ingebrigtsen
2018-09-03 17:19     ` Completion Stefan Monnier
2018-09-03 17:40       ` Completion Lars Ingebrigtsen
2018-09-05 23:03         ` Stephen Leake [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=867ejzfsy2.fsf@stephe-leake.org \
    --to=stephen_leake@stephe-leake.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).