+4

Smarter, Context-Sensitive Auto-Bracket Insertion

Aaron Wright 12 aastat tagasi uuendatud 12 aastat tagasi 0
I write a *lot* of JavaScript. Mostly in MooTools, but even jQuery and "vanilla" writers would benefit from the following, I think:

If I type out the following (the | is my cursor):

window.addEvent ('domready', function () {|

Sublime will somewhat dumbly do the following when I press return:

window.addEvent ('domready', function () {

|
}

Now, I'm grateful that it's trying, but in cases like this, it's actually more of a nuisance. What I would love for it to do, instead:

window.addEvent ('domready', function () {

|
});

Yeah. Getting shivers? How awesome would that be? It would add the semi-colon and the closing round bracket. It could even be super smart and put an invisible insertion marker between the } and ) in the event this function has more arguments, and I could just tab past it to the right of the semi-colon if it didn't.

There is another instance in which the current auto-bracket closing is frustrating:

var App = new Class ({

'initialize': function (options) {|
'method': function () {
// some stuff here
}
});

Pressing return with my insertion point where it is above would yield:

var App = new Class ({

'initialize': function (options) {
|
} // <-- SYNTAX ERROR HERE
'method': function () {
// some stuff here
}
});

See the syntax error? It would have to place a comma after the automatically-inserted bracket. Now, that's probably asking a lot, but even if it added the comma EVERY time in this context, it'd be a lot easier for developers to remove the superfluous comma than to continually go in and add one every. single. time.

I think that about covers my most frequently-encountered quirks with the bracket-closing magic of Sublime. I am 100% oblivious to the complexity of implementing such improvements, but I do feel like Sublime, which is scopes and such, is probably in the best position of all editors to make it happen.

Thank you for reading!

- Aaron Wright