Sublime Forum

Parentheses - expected behavior?

#1

Say I’m editing a document and I enter an opening bracket and hit enter. The closing bracket will show up automagically on the line below my cursor with proper indentation. If I do the same with an open parentheses, the closing parentheses will show up but at my cursor, not on the next line with proper indentation. Is this the expected behavior or is it a bug?

The pipe shows my cursor:

myfunction() { | }

$foo = array( |)

0 Likes

#2

That’s the expected behaviour, yeah.

0 Likes

#3

It would be great if it would act more like a bracket. Is there a way that we can make the parenthesis act like a bracket?

0 Likes

#4

+1

0 Likes

#5

Hey, this was annoying me, so I’ve hacked together this key binding to achieve this. It activates when you hit enter, if the preceding character is an opening parentheses.

  // Treat (<enter>) like {<enter>}, indentation wise
  { "keys": "enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
    
      { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
      { "key": "setting.command_mode", "operand": false },
      { "key": "preceding_text", "operator": "regex_contains", "operand": "\\($", "match_all": true }
    ]
  }

I’ve not used it in anger yet, so might need tweaking, but it seems to be working.

0 Likes