Moved the core of the plugin into autoload. This will not really impact loading times because UltiSnips is loaded on the first CursorMovedI command anyways, but it might fix some issues with --noplugin.
This commit is contained in:
parent
d0c4f31c1f
commit
82ca377aaf
@ -4,11 +4,10 @@
|
|||||||
" Supertab)
|
" Supertab)
|
||||||
" Last Modified: July 27, 2009
|
" Last Modified: July 27, 2009
|
||||||
|
|
||||||
if exists('did_UltiSnips_vim_after') || &cp || version < 700 || !exists("did_UltiSnips_vim") || !has("python")
|
if exists('did_UltiSnips_after') || &cp || version < 700 || !exists("did_UltiSnips_vim") || !has("python")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call UltiSnips_MapKeys()
|
call UltiSnips#MapKeys()
|
||||||
|
|
||||||
let did_UltiSnips_vim_after=1
|
|
||||||
|
|
||||||
|
let did_UltiSnips_after=1
|
||||||
|
283
autoload/UltiSnips.vim
Normal file
283
autoload/UltiSnips.vim
Normal file
@ -0,0 +1,283 @@
|
|||||||
|
" File: UltiSnips.vim
|
||||||
|
" Author: Holger Rapp <SirVer@gmx.de>
|
||||||
|
" Description: The Ultimate Snippets solution for Vim
|
||||||
|
|
||||||
|
if exists('did_UltiSnips_autoload') || &cp || version < 700
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Define dummy version of function called by autocommand setup in
|
||||||
|
" ftdetect/UltiSnips.vim. If the function isn't defined (probably due to
|
||||||
|
" using a copy of vim without python support) it will cause an error anytime a
|
||||||
|
" new file is opened.
|
||||||
|
function! UltiSnips_FileTypeChanged()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
if !exists("g:UltiSnipsUsePythonVersion")
|
||||||
|
let g:_uspy=":py3 "
|
||||||
|
if !has("python3")
|
||||||
|
if !has("python")
|
||||||
|
if !exists("g:UltiSnipsNoPythonWarning")
|
||||||
|
echo "UltiSnips requires py >= 2.6 or any py3"
|
||||||
|
endif
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let g:_uspy=":py "
|
||||||
|
endif
|
||||||
|
let g:UltiSnipsUsePythonVersion = "<tab>"
|
||||||
|
else
|
||||||
|
if g:UltiSnipsUsePythonVersion == 2
|
||||||
|
let g:_uspy=":py "
|
||||||
|
else
|
||||||
|
let g:_uspy=":py3 "
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Global Variables {{{
|
||||||
|
|
||||||
|
" The trigger used to expand a snippet.
|
||||||
|
" NOTE: expansion and forward jumping can, but needn't be the same trigger
|
||||||
|
if !exists("g:UltiSnipsExpandTrigger")
|
||||||
|
let g:UltiSnipsExpandTrigger = "<tab>"
|
||||||
|
endif
|
||||||
|
|
||||||
|
" The trigger used to display all triggers that could possible
|
||||||
|
" match in the current position.
|
||||||
|
if !exists("g:UltiSnipsListSnippets")
|
||||||
|
let g:UltiSnipsListSnippets = "<c-tab>"
|
||||||
|
endif
|
||||||
|
|
||||||
|
" The trigger used to jump forward to the next placeholder.
|
||||||
|
" NOTE: expansion and forward jumping can, but needn't be the same trigger
|
||||||
|
if !exists("g:UltiSnipsJumpForwardTrigger")
|
||||||
|
let g:UltiSnipsJumpForwardTrigger = "<c-j>"
|
||||||
|
endif
|
||||||
|
|
||||||
|
" The trigger to jump backward inside a snippet
|
||||||
|
if !exists("g:UltiSnipsJumpBackwardTrigger")
|
||||||
|
let g:UltiSnipsJumpBackwardTrigger = "<c-k>"
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Should UltiSnips unmap select mode mappings automagically?
|
||||||
|
if !exists("g:UltiSnipsRemoveSelectModeMappings")
|
||||||
|
let g:UltiSnipsRemoveSelectModeMappings = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
" If UltiSnips should remove Mappings, which should be ignored
|
||||||
|
if !exists("g:UltiSnipsMappingsToIgnore")
|
||||||
|
let g:UltiSnipsMappingsToIgnore = []
|
||||||
|
endif
|
||||||
|
|
||||||
|
" UltiSnipsEdit will use this variable to decide if a new window
|
||||||
|
" is opened when editing. default is "normal", allowed are also
|
||||||
|
" "vertical", "horizontal"
|
||||||
|
if !exists("g:UltiSnipsEditSplit")
|
||||||
|
let g:UltiSnipsEditSplit = 'normal'
|
||||||
|
endif
|
||||||
|
|
||||||
|
" A list of directory names that are searched for snippets.
|
||||||
|
if !exists("g:UltiSnipsSnippetDirectories")
|
||||||
|
let g:UltiSnipsSnippetDirectories = [ "UltiSnips" ]
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Should UltiSnips map JumpForwardTrigger and JumpBackwardTrigger only during
|
||||||
|
" snippet expansion?
|
||||||
|
if !exists("g:UltiSnipsClearJumpTrigger")
|
||||||
|
let g:UltiSnipsClearJumpTrigger = 1
|
||||||
|
endif
|
||||||
|
" }}}
|
||||||
|
|
||||||
|
|
||||||
|
" FUNCTIONS {{{
|
||||||
|
function! s:compensate_for_pum()
|
||||||
|
""" The CursorMovedI event is not triggered while the popup-menu is visible,
|
||||||
|
""" and it's by this event that UltiSnips updates its vim-state. The fix is
|
||||||
|
""" to explicitly check for the presence of the popup menu, and update
|
||||||
|
""" the vim-state accordingly.
|
||||||
|
if pumvisible()
|
||||||
|
exec g:_uspy "UltiSnips_Manager.cursor_moved()"
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#Edit(...)
|
||||||
|
if a:0 == 1 && a:1 != ''
|
||||||
|
let type = a:1
|
||||||
|
else
|
||||||
|
exec g:_uspy "vim.command(\"let type = '%s'\" % UltiSnips_Manager.primary_filetype)"
|
||||||
|
endif
|
||||||
|
exec g:_uspy "vim.command(\"let file = '%s'\" % UltiSnips_Manager.file_to_edit(vim.eval(\"type\")))"
|
||||||
|
|
||||||
|
let mode = 'e'
|
||||||
|
if exists('g:UltiSnipsEditSplit')
|
||||||
|
if g:UltiSnipsEditSplit == 'vertical'
|
||||||
|
let mode = 'vs'
|
||||||
|
elseif g:UltiSnipsEditSplit == 'horizontal'
|
||||||
|
let mode = 'sp'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
exe ':'.mode.' '.file
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#AddFiletypes(filetypes)
|
||||||
|
exec g:_uspy "UltiSnips_Manager.add_buffer_filetypes('" . a:filetypes . ".all')"
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#FileTypeComplete(arglead, cmdline, cursorpos)
|
||||||
|
let ret = {}
|
||||||
|
let items = map(
|
||||||
|
\ split(globpath(&runtimepath, 'syntax/*.vim'), '\n'),
|
||||||
|
\ 'fnamemodify(v:val, ":t:r")'
|
||||||
|
\ )
|
||||||
|
call insert(items, 'all')
|
||||||
|
for item in items
|
||||||
|
if !has_key(ret, item) && item =~ '^'.a:arglead
|
||||||
|
let ret[item] = 1
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return sort(keys(ret))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#MapKeys()
|
||||||
|
" Map the keys correctly
|
||||||
|
if g:UltiSnipsExpandTrigger == g:UltiSnipsJumpForwardTrigger
|
||||||
|
|
||||||
|
exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=UltiSnips#ExpandSnippetOrJump()<cr>"
|
||||||
|
exec "snoremap <silent> " . g:UltiSnipsExpandTrigger . " <Esc>:call UltiSnips#ExpandSnippetOrJump()<cr>"
|
||||||
|
else
|
||||||
|
exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=UltiSnips#ExpandSnippet()<cr>"
|
||||||
|
exec "snoremap <silent> " . g:UltiSnipsExpandTrigger . " <Esc>:call UltiSnips#ExpandSnippet()<cr>"
|
||||||
|
if g:UltiSnipsClearJumpTrigger == 0
|
||||||
|
exec "inoremap <silent> " . g:UltiSnipsJumpForwardTrigger . " <C-R>=UltiSnips#JumpForwards()<cr>"
|
||||||
|
exec "snoremap <silent> " . g:UltiSnipsJumpForwardTrigger . " <Esc>:call UltiSnips#JumpForwards()<cr>"
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
exec 'xnoremap ' . g:UltiSnipsExpandTrigger. ' :call UltiSnips#SaveLastVisualSelection()<cr>gvs'
|
||||||
|
if g:UltiSnipsClearJumpTrigger == 0
|
||||||
|
exec "inoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=UltiSnips#JumpBackwards()<cr>"
|
||||||
|
exec "snoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <Esc>:call UltiSnips#JumpBackwards()<cr>"
|
||||||
|
endif
|
||||||
|
exec "inoremap <silent> " . g:UltiSnipsListSnippets . " <C-R>=UltiSnips#ListSnippets()<cr>"
|
||||||
|
exec "snoremap <silent> " . g:UltiSnipsListSnippets . " <Esc>:call UltiSnips#ListSnippets()<cr>"
|
||||||
|
|
||||||
|
snoremap <silent> <BS> <c-g>c
|
||||||
|
snoremap <silent> <DEL> <c-g>c
|
||||||
|
snoremap <silent> <c-h> <c-g>c
|
||||||
|
endf
|
||||||
|
|
||||||
|
function! UltiSnips#MapInnerKeys()
|
||||||
|
if g:UltiSnipsExpandTrigger != g:UltiSnipsJumpForwardTrigger
|
||||||
|
exec "inoremap <buffer> <silent> " . g:UltiSnipsJumpForwardTrigger . " <C-R>=UltiSnips#JumpForwards()<cr>"
|
||||||
|
exec "snoremap <buffer> <silent> " . g:UltiSnipsJumpForwardTrigger . " <Esc>:call UltiSnips#JumpForwards()<cr>"
|
||||||
|
endif
|
||||||
|
exec "inoremap <buffer> <silent> " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=UltiSnips#JumpBackwards()<cr>"
|
||||||
|
exec "snoremap <buffer> <silent> " . g:UltiSnipsJumpBackwardTrigger . " <Esc>:call UltiSnips#JumpBackwards()<cr>"
|
||||||
|
endf
|
||||||
|
|
||||||
|
function! UltiSnips#RestoreInnerKeys()
|
||||||
|
if g:UltiSnipsExpandTrigger != g:UltiSnipsJumpForwardTrigger
|
||||||
|
exec "iunmap <buffer> " . g:UltiSnipsJumpForwardTrigger
|
||||||
|
exec "sunmap <buffer> " . g:UltiSnipsJumpForwardTrigger
|
||||||
|
endif
|
||||||
|
exec "iunmap <buffer> " . g:UltiSnipsJumpBackwardTrigger
|
||||||
|
exec "sunmap <buffer> " . g:UltiSnipsJumpBackwardTrigger
|
||||||
|
endf
|
||||||
|
|
||||||
|
function! UltiSnips#ExpandSnippet()
|
||||||
|
exec g:_uspy "UltiSnips_Manager.expand()"
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#ExpandSnippetOrJump()
|
||||||
|
call s:compensate_for_pum()
|
||||||
|
exec g:_uspy "UltiSnips_Manager.expand_or_jump()"
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#ListSnippets()
|
||||||
|
exec g:_uspy "UltiSnips_Manager.list_snippets()"
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#SnippetsInCurrentScope()
|
||||||
|
let g:current_ulti_dict = {}
|
||||||
|
exec g:_uspy "UltiSnips_Manager.snippets_in_current_scope()"
|
||||||
|
return g:current_ulti_dict
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#SaveLastVisualSelection()
|
||||||
|
exec g:_uspy "UltiSnips_Manager.save_last_visual_selection()"
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#JumpBackwards()
|
||||||
|
call s:compensate_for_pum()
|
||||||
|
exec g:_uspy "UltiSnips_Manager.jump_backwards()"
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#JumpForwards()
|
||||||
|
call s:compensate_for_pum()
|
||||||
|
exec g:_uspy "UltiSnips_Manager.jump_forwards()"
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#FileTypeChanged()
|
||||||
|
exec g:_uspy "UltiSnips_Manager.reset_buffer_filetypes()"
|
||||||
|
exec g:_uspy "UltiSnips_Manager.add_buffer_filetypes('" . &ft . "')"
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#AddSnippet(trigger, value, description, options, ...)
|
||||||
|
" Takes the same arguments as SnippetManager.add_snippet:
|
||||||
|
" (trigger, value, description, options, ft = "all", globals = None)
|
||||||
|
exec g:_uspy "args = vim.eval(\"a:000\")"
|
||||||
|
exec g:_uspy "trigger = vim.eval(\"a:trigger\")"
|
||||||
|
exec g:_uspy "value = vim.eval(\"a:value\")"
|
||||||
|
exec g:_uspy "description = vim.eval(\"a:description\")"
|
||||||
|
exec g:_uspy "options = vim.eval(\"a:options\")"
|
||||||
|
exec g:_uspy "UltiSnips_Manager.add_snippet(trigger, value, description, options, *args)"
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! UltiSnips#Anon(value, ...)
|
||||||
|
" Takes the same arguments as SnippetManager.expand_anon:
|
||||||
|
" (value, trigger="", description="", options="", globals = None)
|
||||||
|
exec g:_uspy "args = vim.eval(\"a:000\")"
|
||||||
|
exec g:_uspy "value = vim.eval(\"a:value\")"
|
||||||
|
exec g:_uspy "UltiSnips_Manager.expand_anon(value, *args)"
|
||||||
|
return ""
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! UltiSnips#CursorMoved()
|
||||||
|
exec g:_uspy "UltiSnips_Manager.cursor_moved()"
|
||||||
|
endf
|
||||||
|
|
||||||
|
function! UltiSnips#EnteredInsertMode()
|
||||||
|
exec g:_uspy "UltiSnips_Manager.entered_insert_mode()"
|
||||||
|
endf
|
||||||
|
|
||||||
|
function! UltiSnips#LeavingBuffer()
|
||||||
|
exec g:_uspy "UltiSnips_Manager.leaving_buffer()"
|
||||||
|
endf
|
||||||
|
|
||||||
|
function! UltiSnips#LeavingInsertMode()
|
||||||
|
exec g:_uspy "UltiSnips_Manager.leaving_insert_mode()"
|
||||||
|
endfunction
|
||||||
|
" }}}
|
||||||
|
|
||||||
|
" Expand our path
|
||||||
|
exec g:_uspy "import vim, os, sys"
|
||||||
|
exec g:_uspy "new_path = os.path.abspath(os.path.join(
|
||||||
|
\ vim.eval('expand(\"<sfile>:h\")'), '..', 'pythonx'))"
|
||||||
|
exec g:_uspy "vim.command(\"let g:UltiSnipsPythonPath = '%s'\" % new_path)"
|
||||||
|
exec g:_uspy "if not hasattr(vim, 'VIM_SPECIAL_PATH'): sys.path.append(new_path)"
|
||||||
|
exec g:_uspy "from UltiSnips import SnippetManager"
|
||||||
|
exec g:_uspy "UltiSnips_Manager = SnippetManager(
|
||||||
|
\ vim.eval('g:UltiSnipsExpandTrigger'),
|
||||||
|
\ vim.eval('g:UltiSnipsJumpForwardTrigger'),
|
||||||
|
\ vim.eval('g:UltiSnipsJumpBackwardTrigger'))"
|
||||||
|
|
||||||
|
let did_UltiSnips_autoload=1
|
@ -16,9 +16,9 @@ UltiSnips *snippet* *snippets* *UltiSnips*
|
|||||||
3.3 Snippet Search Path |UltiSnips-snippet-search-path|
|
3.3 Snippet Search Path |UltiSnips-snippet-search-path|
|
||||||
3.4 Warning About Select Mode Mappings |UltiSnips-warning-smappings|
|
3.4 Warning About Select Mode Mappings |UltiSnips-warning-smappings|
|
||||||
3.5 Functions |UltiSnips-functions|
|
3.5 Functions |UltiSnips-functions|
|
||||||
3.5.1 UltiSnips_AddSnippet |UltiSnips_AddSnippet|
|
3.5.1 UltiSnips#AddSnippet |UltiSnips#AddSnippet|
|
||||||
3.5.2 UltiSnips_Anon |UltiSnips_Anon|
|
3.5.2 UltiSnips#Anon |UltiSnips#Anon|
|
||||||
3.5.3 UltiSnips_SnippetsInCurrentScope |UltiSnips_SnippetsInCurrentScope|
|
3.5.3 UltiSnips#SnippetsInCurrentScope |UltiSnips#SnippetsInCurrentScope|
|
||||||
3.6 Missing python support |UltiSnips-python-warning|
|
3.6 Missing python support |UltiSnips-python-warning|
|
||||||
4. Syntax |UltiSnips-syntax|
|
4. Syntax |UltiSnips-syntax|
|
||||||
4.1 Adding Snippets |UltiSnips-adding-snippets|
|
4.1 Adding Snippets |UltiSnips-adding-snippets|
|
||||||
@ -250,25 +250,25 @@ following to your vimrc file. >
|
|||||||
|
|
||||||
For advanced users there are four functions that you can map directly to a
|
For advanced users there are four functions that you can map directly to a
|
||||||
key and that correspond to some of the triggers previously defined:
|
key and that correspond to some of the triggers previously defined:
|
||||||
g:UltiSnipsExpandTrigger <--> UltiSnips_ExpandSnippet
|
g:UltiSnipsExpandTrigger <--> UltiSnips#ExpandSnippet
|
||||||
g:UltiSnipsJumpForwardTrigger <--> UltiSnips_JumpForwards
|
g:UltiSnipsJumpForwardTrigger <--> UltiSnips#JumpForwards
|
||||||
g:UltiSnipsJumpBackwardTrigger <--> UltiSnips_JumpBackwards
|
g:UltiSnipsJumpBackwardTrigger <--> UltiSnips#JumpBackwards
|
||||||
|
|
||||||
If you have g:UltiSnipsExpandTrigger and g:UltiSnipsJumpForwardTrigger set
|
If you have g:UltiSnipsExpandTrigger and g:UltiSnipsJumpForwardTrigger set
|
||||||
to the same value then the function you are actually going to use is
|
to the same value then the function you are actually going to use is
|
||||||
UltiSnips_ExpandSnippetOrJump.
|
UltiSnips#ExpandSnippetOrJump.
|
||||||
|
|
||||||
Each time any of the functions UltiSnips_ExpandSnippet,
|
Each time any of the functions UltiSnips#ExpandSnippet,
|
||||||
UltiSnips_ExpandSnippet, UltiSnips_JumpBackwards or UltiSnips_JumpBackwards is
|
UltiSnips#ExpandSnippet, UltiSnips#JumpBackwards or UltiSnips#JumpBackwards is
|
||||||
called a global variable is set that contains the return value of the
|
called a global variable is set that contains the return value of the
|
||||||
corresponding function.
|
corresponding function.
|
||||||
|
|
||||||
The corresponding variables and functions are:
|
The corresponding variables and functions are:
|
||||||
UltiSnips_ExpandSnippet --> g:ulti_expand_res (0: fail, 1: success)
|
UltiSnips#ExpandSnippet --> g:ulti_expand_res (0: fail, 1: success)
|
||||||
UltiSnips_ExpandSnippetOrJump --> g:ulti_expand_or_jump_res (0: fail,
|
UltiSnips#ExpandSnippetOrJump --> g:ulti_expand_or_jump_res (0: fail,
|
||||||
1: expand, 2: jump)
|
1: expand, 2: jump)
|
||||||
UltiSnips_JumpForwards --> g:ulti_jump_forwards_res (0: fail, 1: success)
|
UltiSnips#JumpForwards --> g:ulti_jump_forwards_res (0: fail, 1: success)
|
||||||
UltiSnips_JumpBackwards --> g:ulti_jump_backwards_res (0: fail, 1: success)
|
UltiSnips#JumpBackwards --> g:ulti_jump_backwards_res (0: fail, 1: success)
|
||||||
|
|
||||||
To see how these return values may come in handy, suppose that you want to map
|
To see how these return values may come in handy, suppose that you want to map
|
||||||
a key to expand or jump, but if none of these actions is successful you want
|
a key to expand or jump, but if none of these actions is successful you want
|
||||||
@ -279,7 +279,7 @@ Usage is as follows: You define a function >
|
|||||||
|
|
||||||
let g:ulti_expand_or_jump_res = 0 "default value, just set once
|
let g:ulti_expand_or_jump_res = 0 "default value, just set once
|
||||||
function! Ulti_ExpandOrJump_and_getRes()
|
function! Ulti_ExpandOrJump_and_getRes()
|
||||||
call UltiSnips_ExpandSnippetOrJump()
|
call UltiSnips#ExpandSnippetOrJump()
|
||||||
return g:ulti_expand_or_jump_res
|
return g:ulti_expand_or_jump_res
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -389,9 +389,9 @@ complete definition as listed by the |:smap| command. >
|
|||||||
UltiSnips provides some functions for extending core functionality.
|
UltiSnips provides some functions for extending core functionality.
|
||||||
|
|
||||||
|
|
||||||
3.5.1 UltiSnips_AddSnippet *UltiSnips_AddSnippet*
|
3.5.1 UltiSnips#AddSnippet *UltiSnips#AddSnippet*
|
||||||
|
|
||||||
The first function is UltiSnips_AddSnippet(trigger, value, description,
|
The first function is UltiSnips#AddSnippet(trigger, value, description,
|
||||||
options, ...). It adds a new snippet with the provided trigger, value,
|
options, ...). It adds a new snippet with the provided trigger, value,
|
||||||
description, and options to the current list of snippets. See
|
description, and options to the current list of snippets. See
|
||||||
|UltiSnips-syntax| for details on the meaning of the function arguments. All
|
|UltiSnips-syntax| for details on the meaning of the function arguments. All
|
||||||
@ -399,21 +399,21 @@ arguments are strings. An optional fifth argument can be used to specify the
|
|||||||
filetype for the new snippet.
|
filetype for the new snippet.
|
||||||
|
|
||||||
|
|
||||||
3.5.2 UltiSnips_Anon *UltiSnips_Anon*
|
3.5.2 UltiSnips#Anon *UltiSnips#Anon*
|
||||||
|
|
||||||
The second function is UltiSnips_Anon(value, ...). It expands an anonymous
|
The second function is UltiSnips#Anon(value, ...). It expands an anonymous
|
||||||
snippet. Anonymous snippets are defined on the spot, expanded and immediately
|
snippet. Anonymous snippets are defined on the spot, expanded and immediately
|
||||||
discarded again. Anonymous snippets are not added to the global list of
|
discarded again. Anonymous snippets are not added to the global list of
|
||||||
snippets, so they cannot be expanded a second time unless the function is
|
snippets, so they cannot be expanded a second time unless the function is
|
||||||
called again. The function takes three optional arguments, in order: trigger,
|
called again. The function takes three optional arguments, in order: trigger,
|
||||||
description, options. Arguments coincide with the arguments of the
|
description, options. Arguments coincide with the arguments of the
|
||||||
|UltiSnips_AddSnippet| function of the same name. The trigger and options
|
|UltiSnips#AddSnippet| function of the same name. The trigger and options
|
||||||
arguments can change the way the snippet expands. The description is unused at
|
arguments can change the way the snippet expands. The description is unused at
|
||||||
this point.
|
this point.
|
||||||
|
|
||||||
An example use case might be this line from a reStructuredText plugin file:
|
An example use case might be this line from a reStructuredText plugin file:
|
||||||
|
|
||||||
inoremap <silent> $$ $$<C-R>=UltiSnips_Anon(':latex:\`$1\`', '$$')<cr>
|
inoremap <silent> $$ $$<C-R>=UltiSnips#Anon(':latex:\`$1\`', '$$')<cr>
|
||||||
|
|
||||||
This expands the snippet whenever two $ signs are typed.
|
This expands the snippet whenever two $ signs are typed.
|
||||||
Note: The right-hand side of the mapping starts with an immediate retype of
|
Note: The right-hand side of the mapping starts with an immediate retype of
|
||||||
@ -421,9 +421,9 @@ the '$$' trigger and passes '$$' to the function as the trigger argument.
|
|||||||
This is required in order for UltiSnips to have access to the characters
|
This is required in order for UltiSnips to have access to the characters
|
||||||
typed so it can determine if the trigger matches or not.
|
typed so it can determine if the trigger matches or not.
|
||||||
|
|
||||||
3.5.3 UltiSnips_SnippetsInCurrentScope *UltiSnips_SnippetsInCurrentScope*
|
3.5.3 UltiSnips#SnippetsInCurrentScope *UltiSnips#SnippetsInCurrentScope*
|
||||||
|
|
||||||
A third function is UltiSnips_SnippetsInCurrentScope which is the equivalent
|
A third function is UltiSnips#SnippetsInCurrentScope which is the equivalent
|
||||||
of snipmate GetSnipsInCurrentScope function.
|
of snipmate GetSnipsInCurrentScope function.
|
||||||
This function simply returns a vim dictionary with the snippets whose trigger
|
This function simply returns a vim dictionary with the snippets whose trigger
|
||||||
matches the current word.
|
matches the current word.
|
||||||
@ -443,7 +443,7 @@ you just have to define the function GetSnipsInCurrentScope. Put the following
|
|||||||
in your vimrc:
|
in your vimrc:
|
||||||
|
|
||||||
function! GetSnipsInCurrentScope()
|
function! GetSnipsInCurrentScope()
|
||||||
return UltiSnips_SnippetsInCurrentScope()
|
return UltiSnips#SnippetsInCurrentScope()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
@ -451,8 +451,8 @@ As a second example on how to use this function consider the following
|
|||||||
function and mapping definition:
|
function and mapping definition:
|
||||||
|
|
||||||
function! ExpandPossibleShorterSnippet()
|
function! ExpandPossibleShorterSnippet()
|
||||||
if len(UltiSnips_SnippetsInCurrentScope()) == 1 "only one candidate...
|
if len(UltiSnips#SnippetsInCurrentScope()) == 1 "only one candidate...
|
||||||
let curr_key = keys(UltiSnips_SnippetsInCurrentScope())[0]
|
let curr_key = keys(UltiSnips#SnippetsInCurrentScope())[0]
|
||||||
normal diw
|
normal diw
|
||||||
exe "normal a" . curr_key
|
exe "normal a" . curr_key
|
||||||
exe "normal a "
|
exe "normal a "
|
||||||
@ -460,7 +460,7 @@ function! ExpandPossibleShorterSnippet()
|
|||||||
endif
|
endif
|
||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
inoremap <silent> <C-L> <C-R>=(ExpandPossibleShorterSnippet() == 0? '': UltiSnips_ExpandSnippet())<CR>
|
inoremap <silent> <C-L> <C-R>=(ExpandPossibleShorterSnippet() == 0? '': UltiSnips#ExpandSnippet())<CR>
|
||||||
|
|
||||||
If the trigger for your snippet is lorem, you type lor, and you have no other
|
If the trigger for your snippet is lorem, you type lor, and you have no other
|
||||||
snippets whose trigger matches lor then hitting <C-L> will expand to whatever
|
snippets whose trigger matches lor then hitting <C-L> will expand to whatever
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
" This has to be called before ftplugins are loaded. Therefore
|
" This has to be called before ftplugins are loaded. Therefore
|
||||||
" it is here in ftdetect though it maybe shouldn't
|
" it is here in ftdetect though it maybe shouldn't
|
||||||
if has("autocmd")
|
if has("autocmd")
|
||||||
autocmd FileType * call UltiSnips_FileTypeChanged()
|
autocmd FileType * call UltiSnips#FileTypeChanged()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -2,305 +2,56 @@
|
|||||||
" Author: Holger Rapp <SirVer@gmx.de>
|
" Author: Holger Rapp <SirVer@gmx.de>
|
||||||
" Description: The Ultimate Snippets solution for Vim
|
" Description: The Ultimate Snippets solution for Vim
|
||||||
"
|
"
|
||||||
" Testing Info: {{{
|
" Testing Info:
|
||||||
" See directions at the top of the test.py script located one
|
" See directions at the top of the test.py script located one
|
||||||
" directory above this file.
|
" directory above this file.
|
||||||
" }}}
|
|
||||||
|
|
||||||
if exists('did_UltiSnips_vim') || &cp || version < 700
|
if exists('did_UltiSnips_plugin') || &cp || version < 700
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Define dummy version of function called by autocommand setup in
|
" The Commands we define.
|
||||||
" ftdetect/UltiSnips.vim. If the function isn't defined (probably due to
|
command! -nargs=? -complete=customlist,UltiSnips#FileTypeComplete UltiSnipsEdit
|
||||||
" using a copy of vim without python support) it will cause an error anytime a
|
\ :call UltiSnips#Edit(<q-args>)
|
||||||
" new file is opened.
|
|
||||||
function! UltiSnips_FileTypeChanged()
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
if !exists("g:UltiSnipsUsePythonVersion")
|
command! -nargs=1 UltiSnipsAddFiletypes :call UltiSnips#AddFiletypes(<q-args>)
|
||||||
let g:_uspy=":py3 "
|
|
||||||
if !has("python3")
|
|
||||||
if !has("python")
|
|
||||||
if !exists("g:UltiSnipsNoPythonWarning")
|
|
||||||
echo "UltiSnips requires py >= 2.6 or any py3"
|
|
||||||
endif
|
|
||||||
finish
|
|
||||||
endif
|
|
||||||
let g:_uspy=":py "
|
|
||||||
endif
|
|
||||||
let g:UltiSnipsUsePythonVersion = "<tab>"
|
|
||||||
else
|
|
||||||
if g:UltiSnipsUsePythonVersion == 2
|
|
||||||
let g:_uspy=":py "
|
|
||||||
else
|
|
||||||
let g:_uspy=":py3 "
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Global Variables {{{
|
" Backwards compatible functions. Prefer the ones in autoload/.
|
||||||
|
|
||||||
" The trigger used to expand a snippet.
|
|
||||||
" NOTE: expansion and forward jumping can, but needn't be the same trigger
|
|
||||||
if !exists("g:UltiSnipsExpandTrigger")
|
|
||||||
let g:UltiSnipsExpandTrigger = "<tab>"
|
|
||||||
endif
|
|
||||||
|
|
||||||
" The trigger used to display all triggers that could possible
|
|
||||||
" match in the current position.
|
|
||||||
if !exists("g:UltiSnipsListSnippets")
|
|
||||||
let g:UltiSnipsListSnippets = "<c-tab>"
|
|
||||||
endif
|
|
||||||
|
|
||||||
" The trigger used to jump forward to the next placeholder.
|
|
||||||
" NOTE: expansion and forward jumping can, but needn't be the same trigger
|
|
||||||
if !exists("g:UltiSnipsJumpForwardTrigger")
|
|
||||||
let g:UltiSnipsJumpForwardTrigger = "<c-j>"
|
|
||||||
endif
|
|
||||||
|
|
||||||
" The trigger to jump backward inside a snippet
|
|
||||||
if !exists("g:UltiSnipsJumpBackwardTrigger")
|
|
||||||
let g:UltiSnipsJumpBackwardTrigger = "<c-k>"
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Should UltiSnips unmap select mode mappings automagically?
|
|
||||||
if !exists("g:UltiSnipsRemoveSelectModeMappings")
|
|
||||||
let g:UltiSnipsRemoveSelectModeMappings = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
" If UltiSnips should remove Mappings, which should be ignored
|
|
||||||
if !exists("g:UltiSnipsMappingsToIgnore")
|
|
||||||
let g:UltiSnipsMappingsToIgnore = []
|
|
||||||
endif
|
|
||||||
|
|
||||||
" UltiSnipsEdit will use this variable to decide if a new window
|
|
||||||
" is opened when editing. default is "normal", allowed are also
|
|
||||||
" "vertical", "horizontal"
|
|
||||||
if !exists("g:UltiSnipsEditSplit")
|
|
||||||
let g:UltiSnipsEditSplit = 'normal'
|
|
||||||
endif
|
|
||||||
|
|
||||||
" A list of directory names that are searched for snippets.
|
|
||||||
if !exists("g:UltiSnipsSnippetDirectories")
|
|
||||||
let g:UltiSnipsSnippetDirectories = [ "UltiSnips" ]
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Should UltiSnips map JumpForwardTrigger and JumpBackwardTrigger only during
|
|
||||||
" snippet expansion?
|
|
||||||
if !exists("g:UltiSnipsClearJumpTrigger")
|
|
||||||
let g:UltiSnipsClearJumpTrigger = 1
|
|
||||||
endif
|
|
||||||
" }}}
|
|
||||||
|
|
||||||
" Global Commands {{{
|
|
||||||
function! UltiSnipsEdit(...)
|
|
||||||
if a:0 == 1 && a:1 != ''
|
|
||||||
let type = a:1
|
|
||||||
else
|
|
||||||
exec g:_uspy "vim.command(\"let type = '%s'\" % UltiSnips_Manager.primary_filetype)"
|
|
||||||
endif
|
|
||||||
exec g:_uspy "vim.command(\"let file = '%s'\" % UltiSnips_Manager.file_to_edit(vim.eval(\"type\")))"
|
|
||||||
|
|
||||||
let mode = 'e'
|
|
||||||
if exists('g:UltiSnipsEditSplit')
|
|
||||||
if g:UltiSnipsEditSplit == 'vertical'
|
|
||||||
let mode = 'vs'
|
|
||||||
elseif g:UltiSnipsEditSplit == 'horizontal'
|
|
||||||
let mode = 'sp'
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
exe ':'.mode.' '.file
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" edit snippets, default of current file type or the specified type
|
|
||||||
command! -nargs=? -complete=customlist,UltiSnipsFiletypeComplete UltiSnipsEdit
|
|
||||||
\ :call UltiSnipsEdit(<q-args>)
|
|
||||||
|
|
||||||
" Global Commands {{{
|
|
||||||
function! UltiSnipsAddFiletypes(filetypes)
|
|
||||||
exec g:_uspy "UltiSnips_Manager.add_buffer_filetypes('" . a:filetypes . ".all')"
|
|
||||||
return ""
|
|
||||||
endfunction
|
|
||||||
command! -nargs=1 UltiSnipsAddFiletypes :call UltiSnipsAddFiletypes(<q-args>)
|
|
||||||
|
|
||||||
"" }}}
|
|
||||||
|
|
||||||
" FUNCTIONS {{{
|
|
||||||
function! CompensateForPUM()
|
|
||||||
""" The CursorMovedI event is not triggered while the popup-menu is visible,
|
|
||||||
""" and it's by this event that UltiSnips updates its vim-state. The fix is
|
|
||||||
""" to explicitly check for the presence of the popup menu, and update
|
|
||||||
""" the vim-state accordingly.
|
|
||||||
if pumvisible()
|
|
||||||
exec g:_uspy "UltiSnips_Manager.cursor_moved()"
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
function! UltiSnips_ExpandSnippet()
|
function! UltiSnips_ExpandSnippet()
|
||||||
exec g:_uspy "UltiSnips_Manager.expand()"
|
return UltiSnips#ExpandSnippet()
|
||||||
return ""
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! UltiSnips_ExpandSnippetOrJump()
|
function! UltiSnips_ExpandSnippetOrJump()
|
||||||
call CompensateForPUM()
|
return UltiSnips#ExpandSnippetOrJump()
|
||||||
exec g:_uspy "UltiSnips_Manager.expand_or_jump()"
|
|
||||||
return ""
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! UltiSnips_ListSnippets()
|
|
||||||
exec g:_uspy "UltiSnips_Manager.list_snippets()"
|
|
||||||
return ""
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! UltiSnips_SnippetsInCurrentScope()
|
function! UltiSnips_SnippetsInCurrentScope()
|
||||||
let g:current_ulti_dict = {}
|
return UltiSnips#SnippetsInCurrentScope()
|
||||||
exec g:_uspy "UltiSnips_Manager.snippets_in_current_scope()"
|
|
||||||
return g:current_ulti_dict
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! UltiSnips_SaveLastVisualSelection()
|
|
||||||
exec g:_uspy "UltiSnips_Manager.save_last_visual_selection()"
|
|
||||||
return ""
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! UltiSnips_JumpBackwards()
|
function! UltiSnips_JumpBackwards()
|
||||||
call CompensateForPUM()
|
return UltiSnips#JumpBackwards()
|
||||||
exec g:_uspy "UltiSnips_Manager.jump_backwards()"
|
|
||||||
return ""
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! UltiSnips_JumpForwards()
|
function! UltiSnips_JumpForwards()
|
||||||
call CompensateForPUM()
|
return UltiSnips#JumpForwards()
|
||||||
exec g:_uspy "UltiSnips_Manager.jump_forwards()"
|
|
||||||
return ""
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! UltiSnips_FileTypeChanged()
|
function! UltiSnips_AddSnippet(...)
|
||||||
exec g:_uspy "UltiSnips_Manager.reset_buffer_filetypes()"
|
return call(function('UltiSnips#AddSnippet'), a:000)
|
||||||
exec g:_uspy "UltiSnips_Manager.add_buffer_filetypes('" . &ft . "')"
|
|
||||||
return ""
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! UltiSnips_AddSnippet(trigger, value, description, options, ...)
|
function! UltiSnips_Anon(...)
|
||||||
" Takes the same arguments as SnippetManager.add_snippet:
|
return call(function('UltiSnips#Anon'), a:000)
|
||||||
" (trigger, value, description, options, ft = "all", globals = None)
|
|
||||||
exec g:_uspy "args = vim.eval(\"a:000\")"
|
|
||||||
exec g:_uspy "trigger = vim.eval(\"a:trigger\")"
|
|
||||||
exec g:_uspy "value = vim.eval(\"a:value\")"
|
|
||||||
exec g:_uspy "description = vim.eval(\"a:description\")"
|
|
||||||
exec g:_uspy "options = vim.eval(\"a:options\")"
|
|
||||||
exec g:_uspy "UltiSnips_Manager.add_snippet(trigger, value, description, options, *args)"
|
|
||||||
return ""
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! UltiSnips_Anon(value, ...)
|
au CursorMovedI * call UltiSnips#CursorMoved()
|
||||||
" Takes the same arguments as SnippetManager.expand_anon:
|
au CursorMoved * call UltiSnips#CursorMoved()
|
||||||
" (value, trigger="", description="", options="", globals = None)
|
au BufLeave * call UltiSnips#LeavingBuffer()
|
||||||
exec g:_uspy "args = vim.eval(\"a:000\")"
|
au InsertLeave * call UltiSnips#LeavingInsertMode()
|
||||||
exec g:_uspy "value = vim.eval(\"a:value\")"
|
|
||||||
exec g:_uspy "UltiSnips_Manager.expand_anon(value, *args)"
|
|
||||||
return ""
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! UltiSnips_MapKeys()
|
call UltiSnips#MapKeys()
|
||||||
" Map the keys correctly
|
|
||||||
if g:UltiSnipsExpandTrigger == g:UltiSnipsJumpForwardTrigger
|
|
||||||
|
|
||||||
exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=UltiSnips_ExpandSnippetOrJump()<cr>"
|
let did_UltiSnips_plugin=1
|
||||||
exec "snoremap <silent> " . g:UltiSnipsExpandTrigger . " <Esc>:call UltiSnips_ExpandSnippetOrJump()<cr>"
|
|
||||||
else
|
|
||||||
exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=UltiSnips_ExpandSnippet()<cr>"
|
|
||||||
exec "snoremap <silent> " . g:UltiSnipsExpandTrigger . " <Esc>:call UltiSnips_ExpandSnippet()<cr>"
|
|
||||||
if g:UltiSnipsClearJumpTrigger == 0
|
|
||||||
exec "inoremap <silent> " . g:UltiSnipsJumpForwardTrigger . " <C-R>=UltiSnips_JumpForwards()<cr>"
|
|
||||||
exec "snoremap <silent> " . g:UltiSnipsJumpForwardTrigger . " <Esc>:call UltiSnips_JumpForwards()<cr>"
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
exec 'xnoremap ' . g:UltiSnipsExpandTrigger. ' :call UltiSnips_SaveLastVisualSelection()<cr>gvs'
|
|
||||||
if g:UltiSnipsClearJumpTrigger == 0
|
|
||||||
exec "inoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=UltiSnips_JumpBackwards()<cr>"
|
|
||||||
exec "snoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <Esc>:call UltiSnips_JumpBackwards()<cr>"
|
|
||||||
endif
|
|
||||||
exec "inoremap <silent> " . g:UltiSnipsListSnippets . " <C-R>=UltiSnips_ListSnippets()<cr>"
|
|
||||||
exec "snoremap <silent> " . g:UltiSnipsListSnippets . " <Esc>:call UltiSnips_ListSnippets()<cr>"
|
|
||||||
|
|
||||||
snoremap <silent> <BS> <c-g>c
|
|
||||||
snoremap <silent> <DEL> <c-g>c
|
|
||||||
snoremap <silent> <c-h> <c-g>c
|
|
||||||
endf
|
|
||||||
function! UltiSnips_MapInnerKeys()
|
|
||||||
if g:UltiSnipsExpandTrigger != g:UltiSnipsJumpForwardTrigger
|
|
||||||
exec "inoremap <buffer> <silent> " . g:UltiSnipsJumpForwardTrigger . " <C-R>=UltiSnips_JumpForwards()<cr>"
|
|
||||||
exec "snoremap <buffer> <silent> " . g:UltiSnipsJumpForwardTrigger . " <Esc>:call UltiSnips_JumpForwards()<cr>"
|
|
||||||
endif
|
|
||||||
exec "inoremap <buffer> <silent> " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=UltiSnips_JumpBackwards()<cr>"
|
|
||||||
exec "snoremap <buffer> <silent> " . g:UltiSnipsJumpBackwardTrigger . " <Esc>:call UltiSnips_JumpBackwards()<cr>"
|
|
||||||
endf
|
|
||||||
function! UltiSnips_RestoreInnerKeys()
|
|
||||||
if g:UltiSnipsExpandTrigger != g:UltiSnipsJumpForwardTrigger
|
|
||||||
exec "iunmap <buffer> " . g:UltiSnipsJumpForwardTrigger
|
|
||||||
exec "sunmap <buffer> " . g:UltiSnipsJumpForwardTrigger
|
|
||||||
endif
|
|
||||||
exec "iunmap <buffer> " . g:UltiSnipsJumpBackwardTrigger
|
|
||||||
exec "sunmap <buffer> " . g:UltiSnipsJumpBackwardTrigger
|
|
||||||
endf
|
|
||||||
|
|
||||||
|
|
||||||
function! UltiSnips_CursorMoved()
|
|
||||||
exec g:_uspy "UltiSnips_Manager.cursor_moved()"
|
|
||||||
endf
|
|
||||||
function! UltiSnips_EnteredInsertMode()
|
|
||||||
exec g:_uspy "UltiSnips_Manager.entered_insert_mode()"
|
|
||||||
endf
|
|
||||||
function! UltiSnips_LeavingBuffer()
|
|
||||||
exec g:_uspy "UltiSnips_Manager.leaving_buffer()"
|
|
||||||
endf
|
|
||||||
|
|
||||||
function! UltiSnips_LeavingInsertMode()
|
|
||||||
exec g:_uspy "UltiSnips_Manager.leaving_insert_mode()"
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" }}}
|
|
||||||
" COMPLETE FUNCTIONS {{{
|
|
||||||
function! UltiSnipsFiletypeComplete(arglead, cmdline, cursorpos)
|
|
||||||
let ret = {}
|
|
||||||
let items = map(
|
|
||||||
\ split(globpath(&runtimepath, 'syntax/*.vim'), '\n'),
|
|
||||||
\ 'fnamemodify(v:val, ":t:r")'
|
|
||||||
\ )
|
|
||||||
call insert(items, 'all')
|
|
||||||
for item in items
|
|
||||||
if !has_key(ret, item) && item =~ '^'.a:arglead
|
|
||||||
let ret[item] = 1
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
|
|
||||||
return sort(keys(ret))
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" }}}
|
|
||||||
|
|
||||||
"" STARTUP CODE {{{
|
|
||||||
|
|
||||||
" Expand our path
|
|
||||||
exec g:_uspy "import vim, os, sys"
|
|
||||||
exec g:_uspy "new_path = os.path.abspath(os.path.join(
|
|
||||||
\ vim.eval('expand(\"<sfile>:h\")'), '..', 'pythonx'))"
|
|
||||||
exec g:_uspy "vim.command(\"let g:UltiSnipsPythonPath = '%s'\" % new_path)"
|
|
||||||
exec g:_uspy "if not hasattr(vim, 'VIM_SPECIAL_PATH'): sys.path.append(new_path)"
|
|
||||||
exec g:_uspy "from UltiSnips import SnippetManager"
|
|
||||||
exec g:_uspy "UltiSnips_Manager = SnippetManager(
|
|
||||||
\ vim.eval('g:UltiSnipsExpandTrigger'),
|
|
||||||
\ vim.eval('g:UltiSnipsJumpForwardTrigger'),
|
|
||||||
\ vim.eval('g:UltiSnipsJumpBackwardTrigger'))"
|
|
||||||
|
|
||||||
au CursorMovedI * call UltiSnips_CursorMoved()
|
|
||||||
au CursorMoved * call UltiSnips_CursorMoved()
|
|
||||||
au BufLeave * call UltiSnips_LeavingBuffer()
|
|
||||||
au InsertLeave * call UltiSnips_LeavingInsertMode()
|
|
||||||
|
|
||||||
call UltiSnips_MapKeys()
|
|
||||||
|
|
||||||
let did_UltiSnips_vim=1
|
|
||||||
|
|
||||||
" }}}
|
|
||||||
" vim: ts=8 sts=4 sw=4
|
" vim: ts=8 sts=4 sw=4
|
||||||
|
@ -413,7 +413,7 @@ class SnippetManager(object):
|
|||||||
self._csnippets.pop()
|
self._csnippets.pop()
|
||||||
if (not self._csnippets and
|
if (not self._csnippets and
|
||||||
_vim.eval("g:UltiSnipsClearJumpTrigger") != "0"):
|
_vim.eval("g:UltiSnipsClearJumpTrigger") != "0"):
|
||||||
_vim.command("call UltiSnips_RestoreInnerKeys()")
|
_vim.command("call UltiSnips#RestoreInnerKeys()")
|
||||||
|
|
||||||
def _jump(self, backwards=False):
|
def _jump(self, backwards=False):
|
||||||
"""Helper method that does the actual jump."""
|
"""Helper method that does the actual jump."""
|
||||||
@ -512,7 +512,7 @@ class SnippetManager(object):
|
|||||||
"""Expands the given snippet, and handles everything
|
"""Expands the given snippet, and handles everything
|
||||||
that needs to be done with it."""
|
that needs to be done with it."""
|
||||||
if _vim.eval("g:UltiSnipsClearJumpTrigger") == "1":
|
if _vim.eval("g:UltiSnipsClearJumpTrigger") == "1":
|
||||||
_vim.command("call UltiSnips_MapInnerKeys()")
|
_vim.command("call UltiSnips#MapInnerKeys()")
|
||||||
# Adjust before, maybe the trigger is not the complete word
|
# Adjust before, maybe the trigger is not the complete word
|
||||||
text_before = before
|
text_before = before
|
||||||
if snippet.matched:
|
if snippet.matched:
|
||||||
|
14
test.py
14
test.py
@ -2305,7 +2305,7 @@ class MultiWord_SnippetOptions_ExpandWordSnippets_ExpandSuffix(
|
|||||||
class _AnonBase(_VimTest):
|
class _AnonBase(_VimTest):
|
||||||
args = ""
|
args = ""
|
||||||
def _options_on(self):
|
def _options_on(self):
|
||||||
self.send(":inoremap <silent> " + EA + ' <C-R>=UltiSnips_Anon('
|
self.send(":inoremap <silent> " + EA + ' <C-R>=UltiSnips#Anon('
|
||||||
+ self.args + ')<cr>\n')
|
+ self.args + ')<cr>\n')
|
||||||
def _options_off(self):
|
def _options_off(self):
|
||||||
self.send(":iunmap <silent> " + EA + '\n')
|
self.send(":iunmap <silent> " + EA + '\n')
|
||||||
@ -2358,7 +2358,7 @@ class Anon_Trigger_Opts(_AnonBase):
|
|||||||
class _AddFuncBase(_VimTest):
|
class _AddFuncBase(_VimTest):
|
||||||
args = ""
|
args = ""
|
||||||
def _options_on(self):
|
def _options_on(self):
|
||||||
self.send(":call UltiSnips_AddSnippet("
|
self.send(":call UltiSnips#AddSnippet("
|
||||||
+ self.args + ')\n')
|
+ self.args + ')\n')
|
||||||
|
|
||||||
class AddFunc_Simple(_AddFuncBase):
|
class AddFunc_Simple(_AddFuncBase):
|
||||||
@ -3063,9 +3063,9 @@ class VerifyVimDict1(_VimTest):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
snippets = ('testâ', 'abc123ά', '123\'êabc')
|
snippets = ('testâ', 'abc123ά', '123\'êabc')
|
||||||
keys = ('test=(type(UltiSnips_SnippetsInCurrentScope()) . len(UltiSnips_SnippetsInCurrentScope()) . ' +
|
keys = ('test=(type(UltiSnips#SnippetsInCurrentScope()) . len(UltiSnips#SnippetsInCurrentScope()) . ' +
|
||||||
'UltiSnips_SnippetsInCurrentScope()["testâ"]' + ')\n' +
|
'UltiSnips#SnippetsInCurrentScope()["testâ"]' + ')\n' +
|
||||||
'=len(UltiSnips_SnippetsInCurrentScope())\n')
|
'=len(UltiSnips#SnippetsInCurrentScope())\n')
|
||||||
|
|
||||||
wanted = 'test41123\'êabc0'
|
wanted = 'test41123\'êabc0'
|
||||||
|
|
||||||
@ -3076,7 +3076,7 @@ class VerifyVimDict2(_VimTest):
|
|||||||
|
|
||||||
snippets = ('te"stâ', 'abc123ά', '123êabc')
|
snippets = ('te"stâ', 'abc123ά', '123êabc')
|
||||||
akey = "'te{}stâ'".format('"')
|
akey = "'te{}stâ'".format('"')
|
||||||
keys = ('te"=(UltiSnips_SnippetsInCurrentScope()[{}]'.format(akey) + ')\n')
|
keys = ('te"=(UltiSnips#SnippetsInCurrentScope()[{}]'.format(akey) + ')\n')
|
||||||
wanted = 'te"123êabc'
|
wanted = 'te"123êabc'
|
||||||
|
|
||||||
class VerifyVimDict3(_VimTest):
|
class VerifyVimDict3(_VimTest):
|
||||||
@ -3086,7 +3086,7 @@ class VerifyVimDict3(_VimTest):
|
|||||||
|
|
||||||
snippets = ("te'stâ", 'abc123ά', '123êabc')
|
snippets = ("te'stâ", 'abc123ά', '123êabc')
|
||||||
akey = '"te{}stâ"'.format("'")
|
akey = '"te{}stâ"'.format("'")
|
||||||
keys = ("te'=(UltiSnips_SnippetsInCurrentScope()[{}]".format(akey) + ')\n')
|
keys = ("te'=(UltiSnips#SnippetsInCurrentScope()[{}]".format(akey) + ')\n')
|
||||||
wanted = "te'123êabc"
|
wanted = "te'123êabc"
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user