Closed jdujava closed 8 months ago
I worry a bit about performance. Calling out to vim.eval is slow and this code will run on every cursor movement. This should probably be checked in vimscript before calling into python. Overall, I am fine with the feature.
I worry a bit about performance. Calling out to vim.eval is slow and this code will run on every cursor movement. This should probably be checked in vimscript before calling into python. Overall, I am fine with the feature.
Yes this can be done much better by removing/re-creating the UltiSnips_AutoTrigger
autogroup from plugin/UltiSnips.vim
using vimscript. There's no need to write python code for this.
To not complicate things, I added only a global toggling mechanism.
@ces42 To be honest, I wasn't sure wheter UltiSnips_Manager._track_change()
was needed also for other purposes than AutoTrigger, so I tried it this way. But I am certainly open to other (possibly better) solutions!
Adding this to autoload/UltiSnips.vim
provides control over autotrigger:
function! UltiSnips#EnableAutotrigger() abort
augroup UltiSnips_AutoTrigger
au!
au InsertCharPre * call UltiSnips#TrackChange()
au TextChangedI * call UltiSnips#TrackChange()
if exists('##TextChangedP')
au TextChangedP * call UltiSnips#TrackChange()
endif
augroup END
endfunction
function! UltiSnips#DisableAutotrigger() abort
augroup UltiSnips_AutoTrigger
au!
augroup END
endfunction
function! UltiSnips#ToggleAutotrigger() abort
" if exists('#UltiSnips_AutoTrigger')
if exists('#UltiSnips_AutoTrigger#TextChangedI')
call UltiSnips#DisableAutotrigger()
else
call UltiSnips#EnableAutotrigger()
endif
endfunction
EDIT: apparently the augroup doesn't get deleted when you do au!
, only it's autocommands. So you need to replace exists('#UltiSnips_AutoTrigger')
with exists('#UltiSnips_AutoTrigger#TextChangedI')
.
Great, but a test is still missing. Will you work on that @jdujava ?
@SirVer Added tests and documentation, does it look OK?
@SirVer is it good to merge, or is there perhaps anything else to do?
@jdujava Yes, it looks great, an exemplary contribution to an open source project. Thank you very much! Sorry that I took so long to get around to it.
~Now it is possible to disable AutoTrigger in the current buffer by setting the buffer variable
b:UltiSnipsAutoTrigger = 0
.~Now it is possible to disable AutoTrigger via global variable
g:UltiSnipsAutoTrigger
, and to dynamically toggle AutoTrigger on/off withUltisnips#ToggleAutoTrigger()
.This is just a first crude shot at implementing this "toggling feature" (documentation and so on TODO). What do you think, is this alright, or is there perhaps some better way in your opinion?