dot_files/vim-plugins/bundle/xptemplate/doc/xpt.api.txt
2017-07-09 00:26:06 +03:00

153 lines
4.5 KiB
Text

*xpt-api*
This file describes the public functions provided by XPTemplate which
can be used in snippets.
*g:XPTaddBundle()*
g:XPTaddBundle({filetype}, {bundle})
Load a bundle. {filetype} is the current buffer file type in most
case. And {bundle} is the file name which supplies the bundle.
For example loading jquery bundle for HTML buffer(or JAVASCRIPT buffer): >
call g:XPTaddBundle('javascript', 'jquery')
<
*XPTfuncs()*
g:XPTfuncs()
g:XPTfuncs() returns a |Dictionary| container of functions which can
be used in templates in the current buffer. The normal usage of
g:XPTfuncs() to define a template function is : >
let s:f = g:XPTfuncs()
fun! s:f.date() dict
return strftime("%Y %b %d")
endfunction
<
Now you can use functions and variables in the template : >
call XPTemplate("filehead", [
\'/**--------------------/// `sum^ \\\----------------------',
\' *',
\' * @version : `1.0^',
\' * @since : `date()^',
\' * @author : `$author^ | `$email^',
\' * @copyright `.com.cn^ ',
\' * @TODO : ',
\' * ',
\' *---------------------\\\ `sum^ ///----------------------*/',
\''])
<
*XPTemplate()*
XPTemplate({name} [, {context}], {template})
XPTemplate defines a template for the current buffer. It takes 2 or 3
parameters:
{name} is a string representing the key to trigger this template.
{context} can be omitted or an |Dictionary| which defines where this
template can be triggered. For now only "syn" is supported.
{template} is a string or |List|. |List| will be joined with "\n"
forming a template string. This saves you adding "\n" to each line.
*XPTemplateMark()*
XPTemplateMark({leftmark}, {rightmark})
XPTemplateMark defines which characters are used as item quoter in the
current buffer. See |xpt-placeholder-mark|.
NOTE this function affects only the current script and current buffer.
*XPTemplatePriority()*
XPTemplatePriority({priority})
XPTemplatePriority sets the default priority for the current *.xpt.vim
script and current buffer. See |xpt-priority-value|.
NOTE this function affects only the current script and current buffer.
*self.renderContext* *xpt-snippet-function-ctx*
The template context can be accessed from within an
|xpt-snippet-function|. For example in the "item-reference" function:
>
fun! s:f.R(name)
let ctx = self.renderContext
if has_key(ctx.namedStep, a:name)
return ctx.namedStep[a:name]
endif
return a:ctx.name
endfunction
<
*XPTtgr()*
XPTtgr( {snippetName} [, {option} ] )
Trigger an snippet of name {snippetName} in insert mode. This function
returns and |i_CTRL-R_=| expression. You should always use this
function following "<C-R>=".
As Example, the following two command defines auto-complete brace: >
call XPTemplate('brace', '{`^}')
inoremap { <C-r>=XPTtgr('brace')<CR>
<
After executing these 2 command, a "{" key-stroke produces a pair of
braces: "{}" and cursor left between them.
Table below lists all {option} keys: >
{option}.syn Regular expression defines pattern what syntax
name must match for snippet to trigger.
{option}.nosyn Regular expression defines pattern what syntax
name must NOT match for snippet to trigger.
{option}.literal Snippet can only be triggered in string or
comment. Same as
{option}.syn='\V\cstring\|comment'.
{option}.noliteral Snippet can only be triggered outside of
string or comment. Same as
{option}.nosyn='\V\cstring\|comment'.
{option}.k What should be produced if condition is not
satisfied to trigger snippet.
<
*XPTemplateTrigger()*
XPTemplateTrigger( {snippetName} [, {option} ] )
Deprecated.
Same as |XPTtgr()|.
*XPTinfo()*
XPTinfo()
Return 0 if no snippet in processing on screen.
Return an array representing snippets stack on screen in following
format:
>
[ {
"$snipname" : "<snippet-name>",
"$phname" : "<placeholder-name>"
}, ... ]
<
In outer-to-inner order
*XPTinfoStr([fmt,[sep]])*
XPTinfoStr([fmt,[sep]])
Return data of |XPTinfo()| in string.
Argument "fmt": format for rendering infomation of each nested snippet
in stack. Default value is "$snipname.$phname".
Argument "sep": string as a separator. Default value is " > ".
By default XPTinfoStr() returns: >
"<snip-a>.<ph-x> > <snip-inside-a>.<ph-y>..."
<
Example: Adding this function to 'statusline' as a indicator when
working with deeply nested snippets: >
let &statusline .= '%{XPTinfoStr()}'
<
" vim:tw=78:ts=8:sw=8:sts=8:noet:ft=help:norl: