Updated documentation for new/changed functionality.
This commit is contained in:
parent
6a98c5439d
commit
54e849b71b
@ -261,19 +261,20 @@ endsnippet
|
|||||||
4.3.3 Python: *UltiSnips-python*
|
4.3.3 Python: *UltiSnips-python*
|
||||||
|
|
||||||
By far the most powerful interpolation is by using python code. The syntax is
|
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
|
similar to the one for Vimscript, but in python code the value of the property
|
||||||
variable "res" is inserting at the position of the code. Also, the code is
|
"rv" on the "snip" object is inserted at the position of the code. Also, the
|
||||||
inside a `!p ` block. Python code gets some special variables defined which
|
code is inside a `!p ` block. Python code gets some special variables defined
|
||||||
can be used: >
|
which can be used: >
|
||||||
|
|
||||||
fn - The current filename
|
fn - The current filename
|
||||||
path - The complete path to the current file
|
path - The complete path to the current file
|
||||||
t - The values of the placeholders, t[1] -> current text of ${1} and so on
|
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 != ""
|
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.
|
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):
|
snip.mkline(line="", indent=None):
|
||||||
Returns a line ready to be appended to the result. If indent
|
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.
|
current tabstop and expandtab variables.
|
||||||
|
|
||||||
snip.shift(amount=1):
|
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.
|
number of spaces defined by shiftwidth, 'amount' times.
|
||||||
|
|
||||||
snip.unshift(amount=1):
|
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.
|
number of spaces defined by shiftwidth, 'amount' times.
|
||||||
|
|
||||||
snip.reset_indent():
|
snip.reset_indent():
|
||||||
Resets the indentation level to its initial value.
|
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
|
snip.opt(var, default):
|
||||||
python code in the snippet.
|
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
|
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
|
the snippet code. This allows for very flexible snippets. For example, the
|
||||||
@ -301,7 +321,7 @@ uppercase and right aligned:
|
|||||||
|
|
||||||
------------------- SNIP -------------------
|
------------------- SNIP -------------------
|
||||||
snippet wow
|
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
|
endsnippet
|
||||||
------------------- SNAP -------------------
|
------------------- SNAP -------------------
|
||||||
wow<tab>Hello World ->
|
wow<tab>Hello World ->
|
||||||
|
Loading…
Reference in New Issue
Block a user