Sublime Forum

Scope including newline interferes with indentation rules

#1

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?

5 Likes

#2

I’ve seen problems before where an “until end of line” comment (which also include the newline) after an indent pattern would match are not indented, so I too would like to know the answer to this!

0 Likes

#3

It might be worth logging an issue at https://github.com/SublimeTextIssues/Core/issues because it is almost certainly a bug

0 Likes

#4

I’ve logged an issue and found a solution for my problem with comments not reindenting as expected, although there are still some bugs: https://github.com/SublimeTextIssues/Core/issues/1271

0 Likes

#5

hmm, maybe I’m going crazy, but the example in the OP now seems to be working for me in build 3118, and I just tried in 3114 and 3103 portable editions as well (no customizations or packages at all except for the sublime-syntax file and tmPreferences file in the Packages/User folder) and it also worked…

0 Likes

#6

I can confirm it seems to work for me with build 3118. Maybe my initial report was wrong or something has changed.

0 Likes