c4ee3ecf10
It can be useful to set up mappings that apply only during expansion of a snippet. UltiSnips does this internally with the `_setup_inner_state` and `_teardown_inner_state` methods. This commit adds some `User` autocommands so that users of UltiSnips can set up their own mappings and tear them down at the same time as `_setup_inner_state` and `_teardown_inner_state`. This is particularly useful for people who are writing their own expansion and jump functions using `UltiSnips#JumpForwards` and `UltiSnips#ExpandSnippet()` and friends. Here's an example from my own dotfiles: -0664b627e7
-3740c248ee
Using this approach I've been able to get rid of Supertab and have a more nuanced autocompletion experience that works exactly as I'd like with YouCompleteMe.
32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
# encoding: utf-8
|
|
from test.vim_test_case import VimTestCase as _VimTest
|
|
from test.constant import *
|
|
|
|
# Autocommands {{{#
|
|
|
|
class Autocommands(_VimTest):
|
|
snippets = ('test', '[ ${1:foo} ]')
|
|
args = ''
|
|
keys = 'test' + EX + 'test' + EX + 'bar' + JF + JF + ' done ' + ESC + \
|
|
':execute "normal aM" . g:mapper_call_count . "\<Esc>"' + "\n" + \
|
|
':execute "normal aU" . g:unmapper_call_count . "\<Esc>"' + "\n"
|
|
wanted = '[ [ bar ] ] done M1U1'
|
|
|
|
def _extra_vim_config(self, vim_config):
|
|
vim_config.append('let g:mapper_call_count = 0')
|
|
vim_config.append('function! CustomMapper()')
|
|
vim_config.append(' let g:mapper_call_count += 1')
|
|
vim_config.append('endfunction')
|
|
|
|
vim_config.append('let g:unmapper_call_count = 0')
|
|
vim_config.append('function! CustomUnmapper()')
|
|
vim_config.append(' let g:unmapper_call_count += 1')
|
|
vim_config.append('endfunction')
|
|
|
|
vim_config.append('autocmd! User UltiSnipsEnterFirstSnippet')
|
|
vim_config.append('autocmd User UltiSnipsEnterFirstSnippet call CustomMapper()')
|
|
vim_config.append('autocmd! User UltiSnipsExitLastSnippet')
|
|
vim_config.append('autocmd User UltiSnipsExitLastSnippet call CustomUnmapper()')
|
|
|
|
# end: Autocommands #}}}
|