How to avoid automatic closing (, {, [in a custom Sublime Text 3 fragment?

I'm trying to write a pretty innocent looking snippet for ST3. To insert

\left<open-parens> \right<close-parens>

in a latex document, while in the field of mathematics.

Now I have the following:

<snippet>
    <content><![CDATA[\\left${1:(} $0 \\right${1/(\()|(\{)|(\[)/(?1:\))(?2:\})(?3:\])/}]]></content>
    <tabTrigger>lft</tabTrigger>
    <scope>text.tex.latex string.other.math.tex,meta.function.environment.math.latex</scope>
</snippet>

Use is understood as follows:

  • Enter lst, tab;
  • \left( \right)inserted with the selected (;
  • If the user wants (to tabland in the middle,
  • Else type {or [have matching closing parsers inserted after\right

I checked that the regex works as intended (by checking the versions of the fragment with ${1:(}replaced by ${1:{}and ${1:[}.

, , ST , a) parens b) , .

, , , . :

{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "$0{"}, "context": [
     {"key": "selector", "operator": "equal", "operand": "text.tex.latex string.other.math.tex, meta.function.environment.math.latex"},
     {"key": "preceding_text", "operator": "regex_contains", "operand": "\\\\left\\($", "match_all": true }] },

, ).

:

  • , "key": "preceding_text".
  • - (.. [ lst-).

?

+4
1

, , .

-, .

, : lft-snippet :

<content><![CDATA[\\left${1:$0\right}]]></content>

parens , - , . [] :

{ "keys": ["["], "command": "insert_snippet", "args": {"contents": "[ $0 $SELECTION]"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "text.tex.latex string.other.math.tex, meta.function.environment.math.latex"},
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\left\\\\right$", "match_all": true }
    ] 
},

lft- ( ).

, .

0

Source: https://habr.com/ru/post/1525874/


All Articles