简体   繁体   English

方括号上的Sublime Text标识(JavaScript)

[英]Sublime Text identation on square brackets (Javascript)

so I use Sublime text 3 to code JS and I noticed a small but very annoying bug(?). 所以我用Sublime text 3编码JS,我注意到了一个小但很烦人的bug(?)。

I have this code 我有这个代码

var x = [
    "a",
    "b",
    "c"
]

And Sublime auto indents to: var x = [ "a", "b", "c" ] 并且Sublime自动缩进为: var x = [ "a", "b", "c" ]

This is bugging me alot (no pun intended) because I have big array declarations and nested arrays and I can't fold them or have a clear look at the hierarchy. 这让我很烦(没有双关语),因为我有大的数组声明和嵌套的数组,并且无法折叠它们或对层次结构有清晰的了解。

So I went and snooped around on sublime syntax dictionaries. 因此,我去窥探了高级语法词典。 (converted the hexas to ASCII chars) and found this: (将hexas转换为ASCII字符)并发现:

码

I guess that modifying the regex we can change the indentation rule. 我想修改正则表达式可以更改缩进规则。 But I suck at regex expressions, any help? 但是我很讨厌正则表达式,有什么帮助吗?

As you have seen, the JavaScript indentation rules can be found using https://packagecontrol.io/packages/PackageResourceViewer . 如您所见,可以使用https://packagecontrol.io/packages/PackageResourceViewer找到JavaScript缩进规则

Currently, the rules indent on { if not followed by a string or a closing } , and they unindent on } at the beginning of the line (optionally preceded by a closing block comment). 当前,规则在{后面没有字符串或结尾}缩进,并且在行的开头在}上缩进(可选地,在结尾处加上闭环注释)。 You can change them to also indent on [ if not followed by a closing square bracket, and unindent on } or ] - here are some regex patterns equally as crude albeit functional as the original: 您可以将它们更改为也缩进[如果没有紧跟方括号,则缩进,而在}]上缩进-这是一些正则表达式模式,尽管其功能与原始模式一样粗略:

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
    <key>name</key>
    <string>JavaScript Indent</string>
    <key>scope</key>
    <string>source.js</string>
    <key>settings</key>
    <dict>
        <key>decreaseIndentPattern</key>
        <string>^(.*\*/)?\s*[}\]].*$</string>
        <key>increaseIndentPattern</key>
        <string>^.*[{\[][^}"'\]]*$</string>

        <key>bracketIndentNextLinePattern</key>
        <string>(?x)
        ^ \s* \b(if|while|else)\b [^;]* $
        | ^ \s* \b(for)\b .* $
        </string>
    </dict>
</dict>
</plist>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM