On 12-Jan-2010 15:40, Bram Moolenaar wrote:
Ingo Karkat wrote:
Hi Vim developers,

I found a discrepancy between the two methods for custom insert-mode
completion, 'completefunc' and complete(). The latter doesn't respect
the ':set completeopt+=longest' setting; its completions always expand
to the first match, not just the longest common text of matches.  I
see no reason for not observing that setting, and think that this is a
bug in the complete() function.

No, this works as intended.  The whole idea of complete() is that the
script has full control over the matches.  If you want to return the
longest matching text, then pass that to complete().

At least the way I use completion, 'completeopt=longest' is orthogonal to the content and number of matches. Take the calendar-month example I used. When I type "M", and perform completion, it'll offer "March" and "May"; by default (no "longest"), the first match "March" is inserted. I use 'completeopt=longest' to have only "Ma" inserted, so that I can refine and select the match by typing additional letters instead of repeating CTRL-N to go through all matches sequentially. If my script passed only the common text "Ma" on completion, I would lose the ability to preview all matches (via the "match n of m" message and the popup menu), and would then have to re-start the custom completion in order to complete.

So, in my daily use 'completeopt=longest' is just a preference that allows to gradually refine the number of matches while avoiding sequential browsing through the list of matches, it has nothing to do with what kind of matches are displayed.

'completefunc' and complete() are intentionally different.  Otherwise we
could omit one of them.

Yes, there's quite some overlap; the way I've seen it, complete() offers a simple interface for short lists of matches, while 'completefunc' is for more complex implementations that may search multiple buffers for matches and gradually build up the matches via complete_add().

If the behavior of 'completeopt=longest' is the actual difference, I wonder whether it's not possible to emulate that by temporarily modifying the 'completeopt' value before invoking complete() (and why this fact isn't mentioned in the help ;-).

I can probably re-write my script to use 'completefunc', so this isn't a serious issue. In any case, thanks for clarifying this, Bram!

-- regards, ingo
-- 
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui