Sublime Forum

Why is my snippet outdenting itself?

#1

I have a snippet, guard ${1:/* condition */} else { ${2:/* exit statements */} },
and when I use it, the snippet places itself one tab to the left of where I triggered it.
This does not happen when the snippet is guard ${1:/* condition */} else { ${2:exit statements} }.
This could be related to indent_to_bracket though I have it disabled or with auto_indent which is enabled.


Device: MacBook Pro (13-inch, Early 2011)
macOS Version: 10.12.2
Sublime Text: Build 3126

0 Likes

#2

which language syntax are you using this snippet in?

0 Likes

#3

I’m using Swift.

0 Likes

#4

can you link to the package you’re using please for syntax highlighting Swift? It will help to reproduce the problem and suggest a fix :slight_smile:

0 Likes

#5
0 Likes

#6

the reason for this is because the package you are using doesn’t include any indentation rules, so the Default indentation rules are used.

The Default indentation rules contains the following regex pattern to decrease the indentation level: ^(.*\*/)?\s*\}[;\s]*$
I believe it is supposed to handle when a block comment was opened on a previous line and closed on this line, but it doesn’t check that, only that the block comment closed before the }.

So, as we can see, your first snippet matches the regex due to ending in */ }, but the second one doesn’t due to the */ not being followed by } and the end of the line. You should probably log an issue on the package’s repo to request that they add proper indentation rules.

2 Likes