-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split inline if
statements.
#67
Comments
Also interested in this for JavaScript, but in this case turning
into (note the braces):
|
This is not going to be difficult, but I'm a bit worried about the curly brackets. I guess that, in both languages, both formats are acceptable: if (something)
doSomething();
if (something) {
doSomething();
} And then there's the other way around, when you join them: if (something) doSomething();
if (something) { doSomething(); } Personally, I prefer always putting the curly brackets, but I can see how some people would prefer, for example, not to put brackets on the single-line case, but to put brackets on the multiline case. I think I'm probably going to have to put some settings to control this feature. @MeanEYE, @af, what are your preferred styles for multiline and single-line if clauses? I'd like to figure out a way to customize this without going too far in terms of options. For instance, I could do this: let g:splitjoin_js_if_clause_curly_brackets = 1
let g:splitjoin_php_if_clause_curly_brackets = 1 And that would always split and join into something that doesn't have curly brackets. So, with if (something) doSomething();
// splits into
if (something)
doSomething();
if (something) { doSomething(); }
// also splits into
if (something)
doSomething(); Alternatively, I could have 4 options, with Maybe there are other ways to do this, but for starters, I'd like to hear what both of you have to say about how you prefer the code. |
Well, in my code I use something similar to what Linux Kernel coding style suggests. If there's a single line in if (something)
doSomething(); else
doOtherThing(); However if any of these has multiple lines, I wrap both of them: if (something) {
doSomething();
} else {
doOtherThing();
andSometingElse();
} Now granted, people have different coding styles, so having flexible option is a good thing. Perhaps instead of having simple Boolean value you could create option list like Vim does with
Or something to that nature given that it's not too complicated to make. Notably, joining in this case is pretty much unnecessary unless you are removing braces, otherwise it's the same as Vim's built-in join. |
My preference would definitely be to have an option to control this. The JavaScript world has a wide variety of style guides and formatting preferences, so configurability would be great. I personally only use the conventions from my original comment, but if there's a documented option I can put in my vimrc to get that, I don't really care what the default is. |
@MeanEYE The idea for the options sounds great! I hadn't thought of that at all. I hope people aren't confused by it, but I think it won't be a big deal.
@af: Yeah, I think I should just add an option as well. I've created a branch called |
@AndrewRadev cool, thanks! I set |
Oops, my bad. Should be fixed now. |
Works great now, thank you! 👍 |
Documentation should be updated with this in mind. :) |
Oh, doesn't seem to work for |
I always use them when splitting so I didn't notice, sorry! |
All cool. :) Thanks |
@MeanEYE, are you sure that you're setting the right variable? There are two of them, one for PHP and one for javascript: let g:splitjoin_php_if_clause_curly_braces = 'sj'
let g:splitjoin_javascript_if_clause_curly_braces = 'sj' What are you setting the variable(s) to and what is the result? It could be that the combination of settings somehow doesn't work right, or that there's a Vim setting that somehow affects this. |
This is from my config: " configure splitjoin
let g:splitjoin_javascript_if_clause_curly_braces = "sj" Regardless of my config they behave the same. |
Hi, I was wondering if it would be possible to add support for splitting inline
if
statements.For example:
To be split into:
Right now what happens is this:
At least in PHP does. Thanks in advance!
The text was updated successfully, but these errors were encountered: