Some people like it that when they type ‘(’, the bracket is automatically closed as well (useful to keep brackets balanced). This should work for a configurable set of brackets of course, and should probably a preference. Not everybody likes this feature, or so I hear.

Submitted by Zef Hemel on 26 February 2010 at 14:22

On 26 February 2010 at 14:25 Lennart Kats commented:

(see also Spoofax/29)

On 26 February 2010 at 14:30 Lennart Kats commented:

The basic functionality for this should be easy: IAutoEditStrategy allows us to capture text insertion events and change the document in response. We also have the Syntax.esv file which describes the bracket structures in the language.

The main technical challenge in this proposal is with string literals and comments:

a = "( <- no closing ) should be inserted here

Without a tokenizer we would have to parse the file to determine if the brackets are not part of a string literal or comment. Not hard, but I’m not sure if the parser/error recovery performance is always sufficient to do this. (Bit ironic since this feature makes it easier for the error recovery.)

On 2 March 2010 at 12:45 Lennart Kats commented:

Fixed r20653. Uses the “old” AST from the parser (which might lag behind a bit) to find out if we’re in a comment or string literal. Seems to work well.

On 3 March 2010 at 11:57 Zef Hemel commented:

If you want to make it better, it should also remove matching braces:

I type (| is cursor):
I get:
I do backspace end end up with:

I think the Java editor has something like this. I’m not sure if this should always happen, or only with empty brace pairs.

On 3 March 2010 at 12:05 Zef Hemel commented:

And by the way, in the stratego editor when I type "( it does insert the closing ), I don’t think it should, should it?

On 3 March 2010 at 12:15 Lennart Kats commented:

zefhemel: yeah I considered the backspace thing (it’s a TODO in the source code). But it’s a little more complicated (read: more work) when dealing with multi-char brackets.

If you type in:


Then 4 backspaces should remove all of it. In the end, maybe just hitting undo works just as well.

On 3 March 2010 at 12:16 Lennart Kats commented:

Also it shouldn’t do the "() thing, but it’s likely either an interaction with error recovery or you typing too fast for it to make an informed decision about it.

[edit]See also: Spoofax/41: Improve closing bracket insertion[/edit]

Log in to post comments