I’m not sure if this is a bug or a feature, perhaps someone can explain to me what is going on…
Say I create a new syntax definition as:
%YAML 1.2
---
name: NewSyntax
scope: source.newsyntax
contexts:
main:
- match: \!.*\n
scope: random.scope.newsyntax
With the following indentation rules:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key><string>Indentation Rules</string>
<key>scope</key><string>source.newsyntax</string>
<key>settings</key>
<dict>
<key>increaseIndentPattern</key>
<string>^\s*indent.*$</string>
<key>decreaseIndentPattern</key>
<string>^\s*unindent.*$</string>
</dict>
</dict>
</plist>
If I then use Sublime’s “Reindent” functionality on the following file:
indent
indent
inner text
unindent
indent ! text with scope random.scope.newsyntax
inner text
unindent
unindent
I get this indentation:
indent
indent
inner text
unindent
indent ! text with scope random.scope.newsyntax
inner text
unindent
unindent
when I would expect the following indentation:
indent
indent
inner text
unindent
indent ! text with scope random.scope.newsyntax
inner text
unindent
unindent
I can achieve the correct behaviour (the correct indentation, given in the second example) by removing the \n
from the regular expression in the sublime-syntax file. If I start with the “correct” indentation and then run Reindent with the \n
included in the regex, the indentation is not modified.
So it seems that somehow the scope capturing the newline character is causing the indentation engine to cancel the indentation, i.e. reset the indentation to zero. What is going on here? Is this the expected behaviour?