Vsnips
Vsnips copied to clipboard
autocomplete+math mode.
There are three issues that I have. The first is the functionality for automatic snippets (no tab complete) in ultisnips. For example:
snippet mk "Math" wA $$1$ endsnippet
should not require tab-complete in vscode but it does.
The second issue is that if you use snippets without alphanumerical characters, vsnips does not register them. An example:
snippet ,, "ldots" iA , \ldots, $0 endsnippet
The previous snippet will just not register.
The final issue is some of the python integration. The following is a very useful latex function:
global !p texMathZones = ['texMathZone'+x for x in ['A', 'AS', 'B', 'BS', 'C', 'CS', 'D', 'DS', 'V', 'W', 'X', 'Y', 'Z']] texMathZones += ['texMathZone'+x for x in ['E', 'ES', 'F', 'FS', 'G', 'GS', 'H', 'HS', 'I', 'IS', 'J', 'JS', 'K', 'KS', 'L', 'LS']] texIgnoreMathZones = ['texMathText'] texMathZoneIds = vim.eval('map('+str(texMathZones)+", 'hlID(v:val)')") texIgnoreMathZoneIds = vim.eval('map('+str(texIgnoreMathZones)+", 'hlID(v:val)')") def isMath(): synstackids = vim.eval("synstack(line('.'), col('.') - (col('.')>=2 ? 1 : 0))") if not set(texIgnoreMathZoneIds).isdisjoint(synstackids): return False return not set(texMathZoneIds).isdisjoint(synstackids) def prose(): return not isMath() regchars = '([\s\d",._=:$/()|{}[]\]|^)' endglobal
Sorry for the bad formatting.
This does not register, and basically vsnips cannot tell the difference between mathmode and prose mode via these functions. In particular:
context "isMath()" snippet abc "ldots" iA , \ldots, $0 endsnippet
will just run whether I am in math mode or not.
Thank you for reading!
For example:
snippet mk "Math" wA $$1$ endsnippet
should not require tab-complete in vscode but it does.
Well, Vsnips does not support options like 'wA' currently.
w Word boundary - With this option, the snippet is expanded if
the tab trigger start matches a word boundary and the tab trigger end
matches a word boundary. In other words the tab trigger must be
preceded and followed by non-word characters. Word characters are
defined by the 'iskeyword' setting. Use this option, for example, to
permit expansion where the tab trigger follows punctuation without
expanding suffixes of larger words.
A Snippet will be triggered automatically, when condition matches.
See |UltiSnips-autotrigger| for more info.
Now that you have mentioned these options, I will start looking for some ways to support it.
The second issue is that if you use snippets without alphanumerical characters, vsnips does not register them. An example:
snippet ,, "ldots" iA , \ldots, $0 endsnippet
The previous snippet will just not register.
Well, I have tested this code snippet in my vscode and I am sure that the code snippet is registered by vsnips. The reason it doesn't show up in the completion list is because vscode cannot handle prefixes like ,:
correctly.
These options(iA
) are also currently unavailable in this snippet.
The final issue is some of the python integration. The following is a very useful latex function:
global !p texMathZones = ['texMathZone'+x for x in ['A', 'AS', 'B', 'BS', 'C', 'CS', 'D', 'DS', 'V', 'W', 'X', 'Y', 'Z']] texMathZones += ['texMathZone'+x for x in ['E', 'ES', 'F', 'FS', 'G', 'GS', 'H', 'HS', 'I', 'IS', 'J', 'JS', 'K', 'KS', 'L', 'LS']] texIgnoreMathZones = ['texMathText'] texMathZoneIds = vim.eval('map('+str(texMathZones)+", 'hlID(v:val)')") texIgnoreMathZoneIds = vim.eval('map('+str(texIgnoreMathZones)+", 'hlID(v:val)')") def isMath(): synstackids = vim.eval("synstack(line('.'), col('.') - (col('.')>=2 ? 1 : 0))") if not set(texIgnoreMathZoneIds).isdisjoint(synstackids): return False return not set(texMathZoneIds).isdisjoint(synstackids) def prose(): return not isMath() regchars = '([\s\d\",._=:\$\/\(\)\|\{\}\[\]\\]|^)' endglobal
This does not register, and basically vsnips cannot tell the difference between mathmode and prose mode via these functions. In particular:
context "isMath()" snippet abc "ldots" iA , \\ldots, $0 endsnippet
Well, there are two questions on this issue.
Firstly, you want to use the python function in vsnips . I'm sorry that it will be not supported even in the future. For vsnips's user, I'd like to recommend to write JavaScripts
function to do something Please refer to wiki: Vsnips 用户自定义js函数 or code examples.
Secondly, custom-context is not supported yet, and maybe I could find methods to support, but I cannot guarantee it. A good way to know the context is to write a JavaScript
function to detect it.
Well, thanks for your issues, maybe next time you can split it into different issues and it will be easier to track.
Thank you very much for your responses. I will be sure to split up questions next time!
Well, in Vsnips 0.4.1 the 'A'(auto trigger) option is supported, but it may be not recommended because it would damage the performance.
Now that this issue is open, I offer you a solution.
Firstly, you need to set Vsnips.EnableAutoTrigger
to true.
{
"Vsnips.EnableAutoTrigger": true
}
And as for auto-trigger options, you must contains the 'w' with 'A'. let me give you an example:
snippet ,, "ldots" iwA
, \ldots, $0
endsnippet
the option must be 'iwA'('iA' will not work).