Sublime Forum

Greedy scope causing snippet to trigger too often

#1

Hello,

My problem is that one snippet triggers too often.
I don’t know if the problems comes from an error in the language definition, the snippet, or from ST2 itself.
The language definition comes from ST2 (LaTeX) and the snippet comes from LaTeXTools.

The scope that my snippet triggers in is meta.function.environment.list.latex

This scope is defined by

<dict>
	<key>begin</key>
	<string>(?:\s*)((\\)begin)(\{)(itemize|enumerate|description|list)(\})</string>
	<key>captures</key>
	<dict>
		<key>1</key>
		<dict>
			<key>name</key>
			<string>support.function.be.latex</string>
		</dict>
		<key>2</key>
		<dict>
			<key>name</key>
			<string>punctuation.definition.function.latex</string>
		</dict>
		<key>3</key>
		<dict>
			<key>name</key>
			<string>punctuation.definition.arguments.latex</string>
		</dict>
		<key>4</key>
		<dict>
			<key>name</key>
			<string>variable.parameter.function.latex</string>
		</dict>
		<key>5</key>
		<dict>
			<key>name</key>
			<string>punctuation.definition.arguments.latex</string>
		</dict>
	</dict>
	<key>end</key>
	<string>((\\)end)(\{)(\4)(\})(?:\s*\n)?</string>
	<key>name</key>
	<string>meta.function.environment.list.latex</string>
	<key>patterns</key>
	<array>
		<dict>
			<key>include</key>
			<string>$base</string>
		</dict>
	</array>
</dict>

A typical example of a scope like this is:

\begin{itemize}
	\item item 1
	\item item 2
	\item item 3
\end{itemize} 

The problem I have is that the snippet will trigger when the carret is in front of “\begin{itemize}” or on the same line as \end{itemize} (even with spaces).
What is expected is to trigger only between the end of “\begin{itemize}” and the beginning of “\end{itemize}”

I tried to remove the not captured spaces (?:\s*) at the start and end, but of course then it does not match indented lists.
I also read docs.sublimetext.info/en/latest/ … -end-rules and tried to move the “name” key into the “patterns” key, but when I do this the snippet never triggers

Thank you for your help

0 Likes