2009-07-21 04:21:05 -04:00
|
|
|
" File: UltiSnips.vim
|
|
|
|
" Author: Holger Rapp <SirVer@gmx.de>
|
|
|
|
" Description: The Ultimate Snippets solution for Vim
|
|
|
|
"
|
2014-02-11 01:56:56 -05:00
|
|
|
" Testing Info:
|
2013-04-21 11:18:14 -04:00
|
|
|
" See directions at the top of the test.py script located one
|
A "clearsnippets" feature
=========================
It's difficult for the user to control which of the default
bundled snippets are active in his environment. The
'runtimepath' variable must be set to the root of the ultisnips
installation, which brings in all of the bundled snippets.
Though the user may individually override the definition of the
bundled snippets using the "!" flag, the method has a couple of
problems:
- There's no way to remove a snippet, only to override it (and
each snippet must be overridden individually).
- The "!" flag currently doesn't remove the overridden snippets
from the "list snippets" command.
It might be considered a feature that "!" doesn't actually
remove the snippets from the "list snippets" command, though
perhaps that's an unintended effect. In any case, it would be
more convenient to allow the user to selectively remove the
bundled snippets from his environment.
A patch is provided in the following branch to address these problems:
http://code.launchpad.net/~drmikehenry/ultisnips/clearsnippets
The branch's primary purpose is the addition of a
"clearsnippets" command that may be placed in a user's
~/.vim/UltiSnips/ft.snippets file. The user may clear all
lower-priority snippet for that file type with the line:
clearsnippets
Alternatively, he may clear individual snippets by listing their
triggers:
clearsnippets trigger1 trigger2
A few changes were made to the testing system as part of the
incorporation of this new feature. These changes include:
- The "extends" directive is now supported on multiple lines
throughout file.
- A completely empty .snippets file is now possible.
- The test.py scripts now handles most of the vim setup,
simplifying the running of the tests. The invocation of Vim
now reduces to:
vim -u NONE
Instructions for running the tests are included at top of
test.py, where they should be more visible to interested
users; UltiSnips.vim now just points to test.py's
instructions.
- A new function vim_quote() encodes an arbitrary string into a
singly-quoted Vim string, with embedded quotes escaped.
- SnippetsFileParser() now allows file_data to be passed
directly for unit testing, avoiding the need to create files
in the filesystem for test purposes.
- A new _error() function reports errors to the user. At
runtime, this function uses :echo_err in general, but also can
append error text to current buffer to check for expected
errors during unit tests.
- Added error checks to snippets file parsing, along with unit
tests for the parsing.
- Increased retries from 2 to 4 (on my system, occasionally the
timing still causes tests to fail).
2009-09-08 20:15:10 -04:00
|
|
|
" directory above this file.
|
2009-07-04 10:08:14 -04:00
|
|
|
|
2014-02-11 01:56:56 -05:00
|
|
|
if exists('did_UltiSnips_plugin') || &cp || version < 700
|
A "clearsnippets" feature
=========================
It's difficult for the user to control which of the default
bundled snippets are active in his environment. The
'runtimepath' variable must be set to the root of the ultisnips
installation, which brings in all of the bundled snippets.
Though the user may individually override the definition of the
bundled snippets using the "!" flag, the method has a couple of
problems:
- There's no way to remove a snippet, only to override it (and
each snippet must be overridden individually).
- The "!" flag currently doesn't remove the overridden snippets
from the "list snippets" command.
It might be considered a feature that "!" doesn't actually
remove the snippets from the "list snippets" command, though
perhaps that's an unintended effect. In any case, it would be
more convenient to allow the user to selectively remove the
bundled snippets from his environment.
A patch is provided in the following branch to address these problems:
http://code.launchpad.net/~drmikehenry/ultisnips/clearsnippets
The branch's primary purpose is the addition of a
"clearsnippets" command that may be placed in a user's
~/.vim/UltiSnips/ft.snippets file. The user may clear all
lower-priority snippet for that file type with the line:
clearsnippets
Alternatively, he may clear individual snippets by listing their
triggers:
clearsnippets trigger1 trigger2
A few changes were made to the testing system as part of the
incorporation of this new feature. These changes include:
- The "extends" directive is now supported on multiple lines
throughout file.
- A completely empty .snippets file is now possible.
- The test.py scripts now handles most of the vim setup,
simplifying the running of the tests. The invocation of Vim
now reduces to:
vim -u NONE
Instructions for running the tests are included at top of
test.py, where they should be more visible to interested
users; UltiSnips.vim now just points to test.py's
instructions.
- A new function vim_quote() encodes an arbitrary string into a
singly-quoted Vim string, with embedded quotes escaped.
- SnippetsFileParser() now allows file_data to be passed
directly for unit testing, avoiding the need to create files
in the filesystem for test purposes.
- A new _error() function reports errors to the user. At
runtime, this function uses :echo_err in general, but also can
append error text to current buffer to check for expected
errors during unit tests.
- Added error checks to snippets file parsing, along with unit
tests for the parsing.
- Increased retries from 2 to 4 (on my system, occasionally the
timing still causes tests to fail).
2009-09-08 20:15:10 -04:00
|
|
|
finish
|
2009-07-21 04:21:05 -04:00
|
|
|
endif
|
2009-07-04 10:08:14 -04:00
|
|
|
|
2014-02-11 01:56:56 -05:00
|
|
|
" The Commands we define.
|
2014-03-06 03:10:48 -05:00
|
|
|
command! -bang -nargs=? -complete=customlist,UltiSnips#FileTypeComplete UltiSnipsEdit
|
|
|
|
\ :call UltiSnips#Edit(<q-bang>, <q-args>)
|
2010-09-22 07:01:04 -04:00
|
|
|
|
2014-02-11 01:56:56 -05:00
|
|
|
command! -nargs=1 UltiSnipsAddFiletypes :call UltiSnips#AddFiletypes(<q-args>)
|
2012-04-01 10:42:34 -04:00
|
|
|
|
2014-02-11 01:56:56 -05:00
|
|
|
" Backwards compatible functions. Prefer the ones in autoload/.
|
2014-02-19 16:54:37 -05:00
|
|
|
function! UltiSnips_FileTypeChanged()
|
|
|
|
echoerr "Deprecated UltiSnips_FileTypeChanged called. Please use UltiSnips#FileTypeChanged." | sleep 1
|
|
|
|
return UltiSnips#FileTypeChanged()
|
|
|
|
endfunction
|
|
|
|
|
2009-07-21 04:21:05 -04:00
|
|
|
function! UltiSnips_ExpandSnippet()
|
2014-02-19 14:30:46 -05:00
|
|
|
echoerr "Deprecated UltiSnips_ExpandSnippet called. Please use UltiSnips#ExpandSnippet." | sleep 1
|
2014-02-11 01:56:56 -05:00
|
|
|
return UltiSnips#ExpandSnippet()
|
2009-07-21 04:21:05 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! UltiSnips_ExpandSnippetOrJump()
|
2014-02-19 14:30:46 -05:00
|
|
|
echoerr "Deprecated UltiSnips_ExpandSnippetOrJump called. Please use UltiSnips#ExpandSnippetOrJump." | sleep 1
|
2014-02-11 01:56:56 -05:00
|
|
|
return UltiSnips#ExpandSnippetOrJump()
|
2009-08-16 12:50:14 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-06-10 12:27:48 -04:00
|
|
|
function! UltiSnips_SnippetsInCurrentScope()
|
2014-02-19 14:30:46 -05:00
|
|
|
echoerr "Deprecated UltiSnips_SnippetsInCurrentScope called. Please use UltiSnips#SnippetsInCurrentScope." | sleep 1
|
2014-02-11 01:56:56 -05:00
|
|
|
return UltiSnips#SnippetsInCurrentScope()
|
2012-01-11 13:17:13 -05:00
|
|
|
endfunction
|
|
|
|
|
2009-07-10 06:47:54 -04:00
|
|
|
function! UltiSnips_JumpBackwards()
|
2014-02-19 14:30:46 -05:00
|
|
|
echoerr "Deprecated UltiSnips_JumpBackwards called. Please use UltiSnips#JumpBackwards." | sleep 1
|
2014-02-11 01:56:56 -05:00
|
|
|
return UltiSnips#JumpBackwards()
|
2009-07-09 09:30:23 -04:00
|
|
|
endfunction
|
|
|
|
|
2009-07-10 06:47:54 -04:00
|
|
|
function! UltiSnips_JumpForwards()
|
2014-02-19 14:30:46 -05:00
|
|
|
echoerr "Deprecated UltiSnips_JumpForwards called. Please use UltiSnips#JumpForwards." | sleep 1
|
2014-02-11 01:56:56 -05:00
|
|
|
return UltiSnips#JumpForwards()
|
2012-02-21 15:47:12 -05:00
|
|
|
endfunction
|
|
|
|
|
2014-02-11 01:56:56 -05:00
|
|
|
function! UltiSnips_AddSnippet(...)
|
2014-02-19 15:04:52 -05:00
|
|
|
echoerr "Deprecated UltiSnips_AddSnippet called. Please use UltiSnips#AddSnippetWithPriority." | sleep 1
|
2014-02-11 01:56:56 -05:00
|
|
|
return call(function('UltiSnips#AddSnippet'), a:000)
|
2010-12-18 12:07:46 -05:00
|
|
|
endfunction
|
|
|
|
|
2014-02-11 01:56:56 -05:00
|
|
|
function! UltiSnips_Anon(...)
|
2014-02-19 14:30:46 -05:00
|
|
|
echoerr "Deprecated UltiSnips_Anon called. Please use UltiSnips#Anon." | sleep 1
|
2014-02-11 01:56:56 -05:00
|
|
|
return call(function('UltiSnips#Anon'), a:000)
|
2010-12-18 12:07:46 -05:00
|
|
|
endfunction
|
2009-07-04 06:15:12 -04:00
|
|
|
|
2014-04-09 13:04:30 -04:00
|
|
|
augroup UltiSnips
|
|
|
|
au!
|
|
|
|
au CursorMovedI * call UltiSnips#CursorMoved()
|
|
|
|
au CursorMoved * call UltiSnips#CursorMoved()
|
|
|
|
au BufLeave * call UltiSnips#LeavingBuffer()
|
|
|
|
au InsertLeave * call UltiSnips#LeavingInsertMode()
|
|
|
|
augroup END
|
2009-07-27 03:51:09 -04:00
|
|
|
|
2014-02-17 02:15:04 -05:00
|
|
|
call UltiSnips#map_keys#MapKeys()
|
2011-04-27 11:37:07 -04:00
|
|
|
|
2014-02-11 01:56:56 -05:00
|
|
|
let did_UltiSnips_plugin=1
|
2009-07-21 04:21:05 -04:00
|
|
|
|
2011-04-27 11:37:07 -04:00
|
|
|
" vim: ts=8 sts=4 sw=4
|