Sublime Forum

Troubleshooting a package's indentation behavior

#1

Hi hackers,
I use the Processing build package for ST2 and am having a hard time troubleshooting a specific indentation behavior, and where I can modify this. This question isn’t specifically about the particular package, rather how to troubleshoot something like this. The behavior only happens with this particular package and not any other (say, the Java, language setting).

Here’s the behavior. I type:

if (foo) { //... }
With the cursor positioned immediately after the closing brace, as soon as I hit another key, the line with the closing brace becomes suddenly indented, resulting in this:

if (foo) { //... } e

Same behavior for a closing brace after an else if and a try, a function’s closing brace, and… any closing brace.

Lastly, the behavior only occurs if I have just typed the brace. After moving the cursor to another line and typing a character, then moving the cursor back to the position after the closing brace, the behavior doesn’t manifest itself once I start typing. In other words, I only see the behavior after a “freshly” created closing brace.

How might I troubleshoot what is causing the unnecessary auto-indent when the snippets menu appears? Where should I look? I have looked in the Syntax/*.tmLanguage file but… what might I be looking for?

Thanks for any insight.

0 Likes

#2

I found the issue, but it has also led to more questions.

The problematic package did not include a tmPreferences file that specified a decreaseIndentPattern and increaseIndentPattern rule. When I copy, say, the Java package’s Indentation Rules.tmPreferences file into the troublesome package, the bad behavior went away.

My question is: why? Does Sublime have some strange behavior that requires us to specify a decreaseIndentPattern?

An alternative solution I found was to rename the scopeName of the package, from source.pde to source.java.processing. Once I changed all occurrences of the original scopeName to source.java.processing, the issue went away.

My second question is: why? Is the is the “cascading” behavior of tmLanguage and tmPreferences I am seeing? In other words, by changing the package scopeName to source.java.foo, does this package now inherit everything from the Java package?

Thanks for clarifying things. I have read the package/syntax docs but this is the first time I’ve explored how this really works.

0 Likes