Loading ...
Sorry, an error occurred while loading the content.

Custom Completion Function

Expand Messages
  • Amit Dev
    Hi, I m learning to write a vim plugin. One thing I m trying to do is to use the custom completion function (^X^U). The problem is I need a list of completion
    Message 1 of 4 , Jul 31, 2011
    • 0 Attachment
      Hi,

      I'm learning to write a vim plugin. One thing I'm trying to do is to use the custom completion function (^X^U). The problem is I need a list of completion items and a short description. So I tried to use each item as a dict ('word' : <word> and 'menu' : <description>). This works fine, except that I need to find out what was the completion chosen by user. How to find that? There are duplicates in the completion items and only way to find correct entry is by knowing description as well. Eg:

      abcd <a@...>
      dup   <d1@...>
      dup   <d2@...>
      xyz   <x@...

      Is there a callback or something that can be registered to find out which item user chose?

      Another minor thing is doing ^X^U will complete to the first item. Is there a way not to do that? I want something like completion on browsers. While user types it should show the options. Currently I have to do ^X^U then backspace till beginning and start typing.

      Thanks,
      Amit

      --
      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
    • hermitte@free.fr
      Hello, ... In mu-template [1], I ve proceeded the following (asynchronous) way. (I ve found no way to proceed synchronously) : - use feedkey (in
      Message 2 of 4 , Jul 31, 2011
      • 0 Attachment
        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)
        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
      • hermitte@free.fr
        I forgot something regarding your need to know the exact choice even if there are ambiguities. ... At this point, the string inserted is by no mean the final
        Message 3 of 4 , Jul 31, 2011
        • 0 Attachment
          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
        • Amit Dev
          Thanks Luc. I haven t completely understood it yet, but I ll try it out. ... -- You received this message from the vim_use maillist. Do not top-post! Type
          Message 4 of 4 , Aug 3, 2011
          • 0 Attachment
            Thanks Luc. I haven't completely understood it yet, but I'll try it out.

            On Mon, Aug 1, 2011 at 6:27 AM, <hermitte@...> wrote:

            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

            --
            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
          Your message has been successfully submitted and would be delivered to recipients shortly.