Updated documentation for new/changed functionality.

This commit is contained in:
rygwdn@gmail.com 2010-07-29 23:02:15 -03:00
parent 6a98c5439d
commit 54e849b71b

View File

@ -261,19 +261,20 @@ endsnippet
4.3.3 Python: *UltiSnips-python*
By far the most powerful interpolation is by using python code. The syntax is
similar to the one for Vimscript, but in python code the value of the python
variable "res" is inserting at the position of the code. Also, the code is
inside a `!p ` block. Python code gets some special variables defined which
can be used: >
similar to the one for Vimscript, but in python code the value of the property
"rv" on the "snip" object is inserted at the position of the code. Also, the
code is inside a `!p ` block. Python code gets some special variables defined
which can be used: >
fn - The current filename
path - The complete path to the current file
t - The values of the placeholders, t[1] -> current text of ${1} and so on
cur - The current text of the placeholder. You can check if this is != ""
to make sure that the interpolation is only done once
to make sure that the interpolation is only done once.
Note: this is deprecated in favor of snip.c
snip - Provides easy indentation handling, and snippet-local variables.
The snip variable provides four methods >
The snip variable provides the following methods >
snip.mkline(line="", indent=None):
Returns a line ready to be appended to the result. If indent
@ -281,18 +282,37 @@ The snip variable provides four methods >
current tabstop and expandtab variables.
snip.shift(amount=1):
Shifts the default indentatation level used by mkline right by the
Shifts the default indentation level used by mkline right by the
number of spaces defined by shiftwidth, 'amount' times.
snip.unshift(amount=1):
Shifts the default indentatation level used by mkline left by the
Shifts the default indentation level used by mkline left by the
number of spaces defined by shiftwidth, 'amount' times.
snip.reset_indent():
Resets the indentation level to its initial value.
snip.locals:
Is a dictionary which is available to any python block inside the
snippet.
The snip variable also acts as dictionary which can be accessed by any of the
python code in the snippet.
snip.opt(var, default):
Checks if the vim variable "var" has been set, if so, it returns it,
otherwise it returns "default".
snip.rv and snip.c:
snip.rv is the text that will fill this python block's position, and
snip.c is the text currently in it.
The snip variable also provides some operators to make python snippets
easier: >
snip >> amount:
is equivalent to snip.shift(amount)
snip << amount:
is equivalent to snip.unshift(amount)
snip += line:
is equivalent to "snip.rv += '\n' + snip.mkline(line)"
Also, the vim, re, os, string and random modules are already imported inside
the snippet code. This allows for very flexible snippets. For example, the
@ -301,7 +321,7 @@ uppercase and right aligned:
------------------- SNIP -------------------
snippet wow
${1:Text}`!p res = (75-2*len(t[1]))*' '+t[1].upper()`
${1:Text}`!p snip.rv = (75-2*len(t[1]))*' '+t[1].upper()`
endsnippet
------------------- SNAP -------------------
wow<tab>Hello World ->