nanch / phpfmt_stable

This is a stable snapshot (version 6125cf9) of the phpfmt plugin for Sublime Text
143 stars 34 forks source link

How to stop forcing cuddled else? #38

Open remorse opened 6 years ago

remorse commented 6 years ago

Hi! I like to write code with else (and elseif) keywords starting their own line:

if ($foo) {
   ;
}
else {
   ;
}

Is there a way to make fmt.phar stop forcing the elses to be cuddled?

Thanks, Ricky

MKCG commented 6 years ago

You can either disable the ResizeSpaces pass but you will lose some of its functionalities.

Otherwise you should probably consider adding your own pass that will extends the ResizeSpaces but differently manage spaces around those tokens "T_ELSE" and "T_ELSEIF".

To do so you will have to first extract the "fmt.phar" file to have access to the "fmt.stub.php" file which contains the source code and then rebuild the PHAR.

You can find an example in many forks of this repository to learn how to do so. You might want to look at this file : https://github.com/MKCG/phpfmt_7-1/blob/master/fix-fmt.php

eddiriarte commented 6 years ago

@remorse did you tried this in your config?:

{
   ...
   "smart_linebreak_after_curly": true,
   ...
}
remorse commented 6 years ago

Hi! I don't have a config file -- I'm using this as a text filter in BBEdit, so I have to pass everything from the command line. I did try adding --smart_linebreak_after_curly to the command line, but that didn't seem to have any impact. I've also tried adding the SplitCurlyCloseAndTokens pass, but that also didn't seem to affect anything. I haven't had a chance to try @MKCG's suggestion.