Skip to content

Commit

Permalink
[#14] Deal with de/indenting if/else blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
nk9 committed Apr 24, 2023
1 parent 629fd57 commit 8438819
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ https://user-images.githubusercontent.com/3646730/208213422-1ceec5de-a9a0-418f-b
+ [Syntax definitions](https://www.sublimetext.com/docs/syntax.html)
+ [Scope naming](https://www.sublimetext.com/docs/scope_naming.html)
+ [Scope naming guidelines](https://github.com/SublimeText/ScopeNamingGuidelines)
+ [Default syntax definitions](https://github.com/sublimehq/Packages/blob/master/Python/Python.sublime-syntax) are available to view and copy
+ [Default syntax definitions](https://github.com/sublimehq/Packages/) are available to view and copy, for example [Python](https://github.com/sublimehq/Packages/blob/master/Python/Python.sublime-syntax) and [Makefile](https://github.com/sublimehq/Packages/blob/master/Makefile/Makefile.sublime-syntax)
- Sublime auto-indenting is covered in the [community docs](https://docs.sublimetext.io/reference/metadata.html#indentation-options) and this [extensive Forum post](https://forum.sublimetext.com/t/everything-you-n-ever-wanted-to-know-about-indentation-in-st3/26207).
- The [ScopeHunter package](https://packagecontrol.io/packages/ScopeHunter) is on PackageControl, and it is essential. With the Instant Scoper, you will get the scope under the cursor as you move around the file.
- This is a good blog post covering [Sublime syntax](https://haggainuchi.com/sublime.html)
- There is a really useful [thread on GitHub with tips and advice](https://github.com/sublimehq/Packages/issues/757) for building Sublime syntax definitions
Expand Down
43 changes: 39 additions & 4 deletions Preferences/Indentation Rules.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,54 @@
<plist version="1.0">
<dict>
<key>scope</key>
<string>source.just - string - comment - embedded</string>
<string>source.just - comment - embedded</string>
<key>settings</key>
<dict>
<key>increaseIndentPattern</key>
<string>^[^:]+:(?!=)</string>
<string><![CDATA[(?x)
# (if/else code borrowed from the JSON package)
# When an if or else block is opened, but not closed
(
^.*(if|else).*\{
(
# Consume strings
"(?:[^"\\]|\\.)*"
|
# Consume all chars that don't start a string, comment or
# end the block that was opened on this line
[^"\#}]
)*
# Stop matching at the end of the line, or once we hit a comment
($|\#)
)
|
# When a line contains a recipe definition, but not a variable assignment
(
^[^:]+:(?!=)
)
]]></string>
<key>decreaseIndentPattern</key>
<string>(?x)
<string><![CDATA[(?x)
# When an if block is closed, but not opened
(
^
(
# Consume strings
"(?:[^"\\]|\\.)*"
|
# Consume all chars that don't start a string, comment or
# open an object on this line
[^"\#{\n]
)*
\}.*$
)
|
# When an array or group is closed by itself on a line
# (interacts with indentParens and indentSquareBrackets)
(
^\s*(\]|\)).*$
)
</string>
]]></string>
<key>indentParens</key>
<true/>
<key>indentSquareBrackets</key>
Expand Down

0 comments on commit 8438819

Please sign in to comment.