
r-シュタインドキュメント クラス (例: ビーマーまたは記事) に固有のコンテキストに基づいてキーバインディングを定義する方法について説明しました。スニペットに対して同じことを行うにはどうすればよいでしょうか。
MWE:
<snippet>
<content><![CDATA[
\alert{$1} $0
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>test</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>latextools.documentclass.article</scope>
</snippet>
答え1
スニペットには任意のコンテキストを記述することはできず、スコープのみ記述できます。したがって、そのためのスニペットを作成することはできません。ただし、tab
キャレットの前のテキストが の場合にのみトリガーされる キーのキーバインディングを作成することで、スニペットtest
の動作をエミュレートできます。このキーバインディングは、その前の単語を削除し、スニペットを挿入する必要があります。「Chain Of Command」パッケージをインストールすると、次のキーバインディングを使用できます。
{
"keys": ["tab"],
"command": "chain",
"args": {"commands": [
["delete_word", {"forward": false}],
["insert_snippet", {"contents": "\\alert{$1} "}],
]},
"context":
[
{ "key": "selector", "operand": "text.tex.latex" },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\btest$", "match_all": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "latextools.documentclass", "operand": "article" },
]
},
"operand": "\\btest$",
正規表現を次のように変更することで適応できます。"operand": "\\byour_trigger$",