Thursday, December 10, 2015

Dynamic completion

Hi

I'm trying to enhance an old completion function. I'd like it to update the choices displayed in the popup menu as I type new characters

My completion function is

function! lh#icomplete#ecm(findstart, base) abort
if a:findstart
let l = getline('.')
let startcol = match(l[0:col('.')-1], '\v\S+$')
if startcol == -1
let startcol = col('.')-1
endif
" let g:debug+= ["findstart(".a:base.") -> ".(startcol)]
return startcol
else
" let g:debug += ["matching(".a:base.")"]
let words = ['un', 'deux', 'trois', 'trente-deux', 'unité']
let matching = filter(words, 'v:val =~ a:base')
" return { 'words' : words}
return { 'words' : words, 'refresh' : 'always'}
endif
endfunction


That I use with
:set completefunc=lh#icomplete#ecm
and
:inoremap µ <c-x><c-u><c-p>


From my understanding of the documentation, the fact I use <c-p>, I go into the "third state" (according to |ins-completion-menu|), and when I type "any printable, non-white character" I should be able to "Add this character and reduce the number of matches."

When I type in insert mode "uµ", the completion menu pops-up as expected.
Alas when I type 'x' (just after the 'µ'), I'm out of completion mode and "ux" is what I have in mu buffer.

What did I do wrong or missed in the documentation?

NB: I've seen that without "refresh=always", result are filtered, except I'd like to call the function again in order to apply a custom filter.

Regards,

(Just in case, I'm using gvim 7.4-908)
--
Luc Hermitte

--
--
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 because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment