Document How to Customize Indentation
As mentioned in #237, it would be useful for PHP Mode to come with some documentation explaining how users can tweak the various c-styles we provide.
Can we include an example on how to get it back to the GNU style C indentation that earlier versions of php-mode used to use?
I recently swapped from an older el-get install of php-mode which used GNU style C indentation to the latest MELPA install and it completely changed the indentation defaults (for reference, GNU style is like this:
if (some_call () == TRUE)
{
// Do something
}
function some_call ()
{
// Only the IF statements use that staggered indentation
}
Can we include an example on how to get it back to the GNU style C indentation that earlier versions of php-mode used to use?
Good idea. It can be done in a PHP Mode buffer via C-c . to change the "c-style", from which you can select "gnu". You can also have (setq c-default-style "gnu") in your Emacs config. If that doesn't have the intended effect then I would consider that a bug.
Thanks @ejmr that is close to what I needed. It seems older php-mode was essentially GNU indentation style with some slight adjustments.
I've created the following 2 new indent styles which are nearly identical (placed in ~/.emacs and evaled, then set with C-c . as you describe (also C-c C-s is great for finding out what is the indentation being applied, as I recently found out).
(c-add-style
"gnuphp"
'("gnu"
(c-basic-offset . 2)
(c-doc-comment-style . javadoc)
(c-offsets-alist . ((inlambda . 0)
(arglist-intro . php-lineup-arglist-intro)
(inline-open . 0)))))
(c-add-style
"phpgnu"
'("php"
(c-basic-offset . 2)
(c-offsets-alist . ((substatement-open . +)))))
It seems older php-mode was essentially GNU indentation style with some slight adjustments.
I never used the "gnu" style so I honestly wasn't aware that PHP Mode originally made any small tweaks to it. Thanks for pointing that out---I'll look back through the oldest versions of the code and see if there's anything we should re-introduce similar to your two examples.
...also C-c C-s is great for finding out what is the indentation...
Likewise I find C-c C-o helpful when deciding exactly how to tweak indentation, so you may find that useful as well.
I actually discovered the GNU style indentation thanks to php-mode's old defaults, and it definitely grew on me!