Am 17.08.2010 16:33, schrieb SirVer:
Hi,
I am the developer of UltiSnips, the ultimate snippet solution for
vim[1]. A user of mine has reported a bug [2] that is hard for me to
fix and I am in search of inspiration on this list.
UltiSnips selects part of text by using feedkeys(). For example to
select two lines for overwriting in insert mode, we would use
something like
feedkeys("\<Esc>v2j\<c-g>")
The user now has a langmap set, which remaps the j key and the whole
scheme falls down. My idea was now to cache the content of the langmap
option and restore it after the feedkeys() call. Unfortunately, the
feedkeys() keys are not evaluated till after my script has finished
running; at this point in time, the langmap is already restored and
therefore the feedkeys call does not work out.
Is there a way to force the evaluation of the keyboard buffer? Or is
there maybe a clever autocommand in which I can restore the contents
of langmap, so that it is not set after my scripts run (so that
feedkeys() does the right thing) but it is reset as soon as the user
needs it.
[1] http://www.vim.org/scripts/script.php?script_id=2715
[2] https://bugs.launchpad.net/ultisnips/+bug/501727
feedkeys() with "n" argument doesn't help:
:set langmap=jG
:call feedkeys("j", "n")
Here is an attempt with <script> mappings.
The following example doesn't use feedkeys() at all.
I guess the tricky part will be to make sure that RestoreOptions()
is executed always -- for example, it will not be executed when
the InsertActions produce a Beep!.
set langmap=jG
inoremap <script> <Tab> <C-R>=ProcessTab()<CR><SID>go!!
noremap! <SID>post <C-R>=RestoreOptions()<CR>
noremap <SID>post :<C-U>call RestoreOptions()<CR>
func! MapInsertActions(rhs)
exec "inoremap <script> <SID>go!!" a:rhs."<SID>post"
endfunc
" --------------------------------------------------
" could be a 2nd script
func! ProcessTab()
call SaveOptions(['lmap'])
set langmap=
call MapInsertActions("<Esc>v2j<C-G>")
return ""
endfunc
" --------------------------------------------------
" could be a 3rd script
let g:saved_options = []
func! SaveOptions(opt_list)
let g:saved_options = reverse(
\ map(copy(a:opt_list), '[v:val, eval("&". v:val)]'))
endfunc
func! RestoreOptions()
for [optname, value] in g:saved_options
exec 'let &l:'.optname "= value"
endfor
let g:saved_options = []
endfunc
--
Andy
--
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