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

Re: setting refresh: 'always' in a completion function breaks the dot ('.') register

Expand Messages
  • Val Markovic
    Sorry for the delay; for some reason, I didn t get an email update for your response. A misconfiguration on my side. You re right, I should have provided more
    Message 1 of 7 , May 5 1:49 PM
    • 0 Attachment
      Sorry for the delay; for some reason, I didn't get an email update for your response. A misconfiguration on my side.

      You're right, I should have provided more detail. The original problem report (https://groups.google.com/forum/#!msg/vim_dev/k1Wo5Fv6e3E/CUjMnFEWlxYJ) provides more info, but that's no excuse for not going in-depth here.

      I've encountered this problem with two different plugins; one of them is something I'm still working on, the other plugin is neocomplcache. The issue report for neo is here: https://github.com/Shougo/neocomplcache/issues/185#issuecomment-5527679 . That issue report has more details as well.

      The problem is the following: let's say we have the following mapping in our vimrc:

      " With this command, when the completion window is visible, the tab key will
      " select the next candidate in the window. In vim, this also changes the
      " typed-in text to that of the candidate completion.
      inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"

      completeopt has 'menuone' and 'preview'.

      Let's say we also have a function tied to CursorMovedI that basically just calls feedkeys like this:

      " <c-x><c-u> invokes the user's completion function and <c-p> tells vim to select the previous
      " completion candidate. This is necessary because by default, vim selects the
      " first candidate when completion is invoked, and selecting a candidate
      " automatically replaces the current text with it. Calling <c-p> forces vim to
      " deselect the first candidate and in turn preserve the user's current text
      " until he explicitly chooses to replace it with a completion with, say, the <TAB>
      call feedkeys( "\<C-X>\<C-U>\<C-P>", 'n' )

      This means that the custom completefunc is called on every keystroke in insert mode. Let's say that that completefunc always returns a dictionary with the 'words' list containing one string ("example") and 'refresh' is set to 'always'. It does this for every keystroke. (Of course, when findstart is set, it returns the location of the beginning of the typed-in word. Nothing special.)

      Something like the following (this was quickly hacked together from multiple parts for the sake of example; I'm not saying it works):

      fun! NewComplete(findstart, base)
      if a:findstart
      " locate the start of the word
      let line = getline('.')
      let start = col('.') - 1
      while start > 0 && line[start - 1] =~ '\a'
      let start -= 1
      endwhile
      return start
      else
      let l:results = ['example']
      let dict = { 'words' : results }
      let dict.refresh = 'always'
      return dict
      endif
      endfun

      This completefunc in combination with the feedkeys call ensures that no matter what the user types in insert mode, the completion window pops up with "example". This completion suggestion is not inserted automatically; it's only inserted if the user presses TAB. If the user then:

      1. Goes in insert mode.
      2. Types in "example test" (ignoring the offered completions)
      3. Leaves insert mode (now we're back in normal mode)
      4. Presses '.'

      ... the user will then see gibberish inserted instead of "example test" again. Without refresh set to always, "example test" is inserted correctly.

      This is what I mean when I say that the dot register breaks for refresh: always.

      Of course, the plugins I'm referring to don't use such a simple completefunc; they in fact return new completion candidates on every keystroke, but I believe that's besides the point here.

      On Monday, April 30, 2012 12:35:30 AM UTC-7, JohnBeckett wrote:
      > Val Markovic wrote:
      > > Any help, advice or guidance would be greatly appreciated.
      >
      > Someone needs to spend quality time:
      > 1. Working out the problem is.
      > 2. Fixing problem.
      >
      > You could help point 1 by giving a brief indication of what the
      > problem is. Yes, the subject line tried to do that, but a few
      > lines with a simple demo and a description (what does "break"
      > mean?) may help.
      >
      > John

      --
      You received this message from the "vim_dev" 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
    • Val Markovic
      ... For those not following the issue report for neocomplcache, here s a screencast showing the problem:
      Message 2 of 7 , May 6 8:11 PM
      • 0 Attachment
        On Sat, May 5, 2012 at 1:49 PM, Val Markovic <val@...> wrote:
        > I've encountered this problem with two different plugins; one of them is
        > something I'm still working on, the other plugin is neocomplcache. The issue
        > report for neo is here:
        > https://github.com/Shougo/neocomplcache/issues/185#issuecomment-5527679 .
        > That issue report has more details as well.

        For those not following the issue report for neocomplcache, here's a
        screencast showing the problem:
        http://dl.dropbox.com/u/2076969/vim_broken_dot_register.mov

        --
        You received this message from the "vim_dev" 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
      • mattn
        I just testing following patch. https://gist.github.com/2626352 ... -- You received this message from the vim_dev maillist. Do not top-post! Type your reply
        Message 3 of 7 , May 7 12:05 AM
        • 0 Attachment
          I just testing following patch.

          https://gist.github.com/2626352

          On Monday, May 7, 2012 12:11:45 PM UTC+9, Val Markovic wrote:
          > On Sat, May 5, 2012 at 1:49 PM, Val Markovic <val@...> wrote:
          > > I've encountered this problem with two different plugins; one of them is
          > > something I'm still working on, the other plugin is neocomplcache. The issue
          > > report for neo is here:
          > > https://github.com/Shougo/neocomplcache/issues/185#issuecomment-5527679 .
          > > That issue report has more details as well.
          >
          > For those not following the issue report for neocomplcache, here's a
          > screencast showing the problem:
          > http://dl.dropbox.com/u/2076969/vim_broken_dot_register.mov

          --
          You received this message from the "vim_dev" 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
        • Val Markovic
          I can confirm that mattn s patch does appear to fix this problem; the dot register works again. -- You received this message from the vim_dev maillist. Do
          Message 4 of 7 , May 7 7:11 PM
          • 0 Attachment
            I can confirm that mattn's patch does appear to fix this problem; the dot register works again.

            --
            You received this message from the "vim_dev" 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
          • Val Markovic
            ... Any chance of this patch landing in trunk soon? I ve been using a version of Vim patched with it every day since it was posted and have experienced zero
            Message 5 of 7 , May 15 6:22 PM
            • 0 Attachment
              On Mon, May 7, 2012 at 7:11 PM, Val Markovic <val@...> wrote:
              >
              > I can confirm that mattn's patch does appear to fix this problem; the dot register works again.

              Any chance of this patch landing in trunk soon? I've been using a
              version of Vim patched with it every day since it was posted and have
              experienced zero issues.

              Val

              --
              You received this message from the "vim_dev" 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.