Home Download Buy Blog Forum Support

Bug: array parentheses indentation (build 2200)

Bug: array parentheses indentation (build 2200)

Postby Ildefonse on Tue Jun 19, 2012 9:03 am

Upon typing:

Code: Select all
$var = array(


Sublime automatically adds the closing parenthesis:

Code: Select all
$var = array()


Your cursor will still be between both parentheses.
Now, if you hit enter at this point, Sublime makes:

Code: Select all
$var = array(
   <cursor>)


This is wrong. It should put the closing parenthesis on another new line, at the same indentation as the original line. E.g.:

Code: Select all
$var = array(
   <cursor>
)


In other words, it should behave pretty much the same like it does with curly brackets (as for an if-statement for example).
Since I have to make a lot of associative arrays like this, it's really a pain to have to re-indent it manually every time:

Code: Select all
$var = array(
      'blah'      =>   'blah',
      'blah'      =>   'blah',
      'blah'      =>   'blah',
      'blah'      =>   'blah',
);
Ildefonse
 
Posts: 15
Joined: Tue Jun 19, 2012 8:48 am

Re: Bug: array parentheses indentation (build 2200)

Postby Ildefonse on Thu Jun 21, 2012 10:18 am

Does anyone have a work around to "fix" this? Maybe via a custom plugin?
Is there anyone that knows where to find the code responsible for this behavior?

Since it already works correctly for curly brackets, it shouldn't be too hard to fix it for regular brackets as well.
Ildefonse
 
Posts: 15
Joined: Tue Jun 19, 2012 8:48 am

Re: Bug: array parentheses indentation (build 2200)

Postby agibsonsw on Thu Jun 21, 2012 12:55 pm

If you search for 'enter' in your Default Key-Bindings, it's probably this:
Code: Select all
   { "keys": ["enter"], "command": "run_macro_file", "args": {"file": "Packages/Default/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": "\\{$", "match_all": true },
         { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }


If you copy this section to Key-Bindings User, and modify "\\{$" to "\\($" and "^\\}" to "^\\)" it might work.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Bug: array parentheses indentation (build 2200)

Postby Ildefonse on Fri Jun 22, 2012 3:50 am

Thanks, that was useful. I added this code to the user keybindings:

Code: Select all
{ "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:

Code: Select all
[
    {"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.
Ildefonse
 
Posts: 15
Joined: Tue Jun 19, 2012 8:48 am

Re: Bug: array parentheses indentation (build 2200)

Postby skunkbad on Sat Sep 29, 2012 5:24 pm

Although this may be a solution, it should still be the default. Why no love for php?
skunkbad
 
Posts: 13
Joined: Wed Oct 26, 2011 5:30 pm

Re: Bug: array parentheses indentation (build 2200)

Postby adfaklsdjf on Tue Oct 16, 2012 6:06 pm

bumping again :-x

Yes for to be making this default behavior

skunkbad wrote:Although this may be a solution, it should still be the default. Why no love for php?
adfaklsdjf
 
Posts: 1
Joined: Tue Oct 16, 2012 6:04 pm

Re: Bug: array parentheses indentation (build 2200)

Postby Eduan on Tue Oct 16, 2012 6:23 pm

Bump, I would love this feature, I too am a PHP developer, and I am used to this behavior. :(

Hope John notices this and fixes it.
Check out my blog and website: EduanTech.com (currently undergoing some facial and organs makeover...)
Also check out my profiles: GitHub - Greduan | BitBucket - Greduan
Eduan
 
Posts: 140
Joined: Sun Oct 14, 2012 4:05 pm

Re: Bug: array parentheses indentation (build 2200)

Postby derp on Mon Apr 29, 2013 12:47 pm

Bump. This is still not fixed in 2217 and really needs to be.
derp
 
Posts: 4
Joined: Wed Sep 14, 2011 11:53 am

Re: Bug: array parentheses indentation (build 2200)

Postby bradleyflood on Fri Jan 17, 2014 5:23 am

Bump. This issue is so annoying.
bradleyflood
 
Posts: 3
Joined: Tue Dec 10, 2013 5:38 am

Re: Bug: array parentheses indentation (build 2200)

Postby bsteere on Mon Feb 10, 2014 6:52 pm

I would also like to see this as the default.
bsteere
 
Posts: 1
Joined: Mon Feb 10, 2014 6:18 pm

Next

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], mwb1100 and 29 guests