Sublime Forum

Parenthesis & Line Break

#1

Running build 2117. I’m having issues with parenthesis, line breaks and indentation. Let’s go straight to some examples.

No indentation. Pressing return just after ‘(’:

This is what I would expect.

Now here’s the problem. Exactly the same as the above except that indentation is at 1 tab.

Oops! I’d expect to close the parenthesis on the same indentation level as line 2.

I’m almost positive there’s a simple way to fix this, but with documentation being pretty scarce, I’m having a hard time finding it.

0 Likes

#2

I’m very interested to have parenthesis act like a bracket, and have the indentation as you are describing. Hopefully somebody will give us some help!

0 Likes

#3

Been quite some time! Any update on this? Can it be done now?

Edit: found a fix on these forums:

[quote=“Ildefonse”]Thanks, that was useful. I added this code to the user keybindings:

{ "keys": "enter"], "command": "run_macro_file", "args": {"file": "Packages/User/Macros/Add Line in Braces.sublime-macro"}, "context":
		
			{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
			{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
			{ "key": "preceding_text", "operator": "regex_contains", "operand": "array\\($", "match_all": true },
			{ "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true }
		]
	}

But this still had one flaw: the closing parenthesis “)” was placed one tab too far indented to the right. I am not sure what does this, as it only happens with parentheses, and not with for example “” or square brackets ].

Anyway, I fixed this odd behavior by modifying the “Add Line in Braces” macro (after copying to user folder), changing it to:


    {"command": "insert", "args": {"characters": "\n\n"} },
    {"command": "left_delete", "args": null},
    {"command": "move", "args": {"by": "lines", "forward": false} },
    {"command": "move_to", "args": {"to": "hardeol", "extend": false} },
    {"command": "reindent", "args": {"single_line": true} }
]

I added in the second line, and now it works like a charm.
Thanks again for helping me find this, I hope someone else finds the solution useful as well, or maybe Sublime will implement it in their default packages and keybindings.[/quote]

1 Like