Sunday, July 31, 2011

Re: Custom Completion Function

I forgot something regarding your need to know the exact choice even if there are ambiguities.

> Hello,
>
>
> "Amit Dev" wrote:
>
> > One thing I'm trying to do is to
> > use the custom completion function (^X^U). [...]
> >
> > Is there a callback or something that can be registered to find out
> > which item user chose?
>
> In mu-template [1], I've proceeded the following (asynchronous) way.
> (I've found no way to proceed synchronously) :
>
> - use feedkey (in s:ChooseTemplateFile(), l.680) to call a function
> that returns nothing, but that calls complete()
>
> - the function called (s:ChooseByComplete(), l.643) prepares the
> dictionary for complete(), registers a hook (to be called at the end
> of the process), and calls complete() -- this is all done through a
> "library" that I wrote for the occasion (lh-vim-lib ->
> autoload/lh/icomplete.vim)
>
> - the hook function (s:FinishCompletion(), l.659) extracts from the
> buffer what has really been inserted, and then do what I wished to
> do (here insert and interpret a template-file)

At this point, the string inserted is by no mean the final string, but something like a temporary identifier that I use to know which was the user's choice.


> The hook itself is triggered when <cr> or <c-y> are pressed. Both key
> are temporarily overriden for this purpose.
> NB: I also register a clear-once-the-temporary-mappings hook on
> InsertLeave, thanks to lh-vim-lib again.
>
>
> HTH,
>
> [1] the source code that'll interest you is here:
> http://code.google.com/p/lh-vim/source/browse/mu-template/trunk/autoload/lh/mut.vim
>
> --
> Luc Hermitte
> http://lh-vim.googlecode.com/
> http://hermitte.free.fr/vim/

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: