Skip to content
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

editorconfig-indentation-alist: php-mode #116

Closed
ghost opened this issue Dec 11, 2016 · 5 comments
Closed

editorconfig-indentation-alist: php-mode #116

ghost opened this issue Dec 11, 2016 · 5 comments

Comments

@ghost
Copy link

ghost commented Dec 11, 2016

Any reason why PHP isn't in the indentation mode list?

Here's what it should look like if you want to add it:
(php-mode c-basic-offset)

As per: http://php-mode.sourceforge.net/html-manual/Indentation.html

You would normally also need to override php-mode-coding-style and set it to Default (instead of PEAR) whenever you want your own indentation to take effect: emacs-php/php-mode#226. But because you're injecting via a hook after the style has already been applied, you're free to override c-basic-offset without touching the php style parameter.

@10sr
Copy link
Member

10sr commented Dec 11, 2016

Any reason why PHP isn't in the indentation mode list?

It is because php-mode is a child mode of c-mode!
When editorconfig.el cannot find the indentation definition exactly for current mode, editorconfig.el "goes up" and tries to find definition for one of its parent modes, in this case, c-mode.
And editorconfig.el has a definition of (c-mode c-basic-offset), I think there is no problem in working with php-mode.

You would normally also need to override php-mode-coding-style...

Thanks for this helpful information! I did not know about that.

My understanding: we should be aware of that, but luckily it does not cause any problems with current editorconfig empl, right?

@ghost
Copy link
Author

ghost commented Dec 11, 2016

@10sr: Oh, that's a clever implementation. So that is why EditorConfig works with PHP files anyway. I was wondering how it achieved that.

As for the php-mode-coding-style: It causes no problems with EditorConfig, since you inject later. They basically do this at mode startup: "if php-mode-coding-style is 'pear' (which it is by default), add a c-style called 'pear' and switch to it", and that style contains a c-basic-offset value. But since you're hooking later than that, you're welcome to override c-basic-offset without any risk.

Note that php-mode suggests manually typing "nxml-mode" and "js2-mode" and "web-mode" and then "php-mode" etc, to switch editing styles if you have a document with multiple types of content (which is common in .php files). And every time you type php-mode, it runs that style injection again and resets c-basic-offset.

But the good news is, editorconfig runs as a hook when the major mode changes, so it still re-applies the correct offset every time that happens.

Maybe you want to write down these 2 facts somewhere in the project (a brief code comment perhaps) for your own usage, since it could help with future bugtracking. Or just memorize the existence of this ticket, if php-mode ever comes back to bite. ;-)

PS: Lots of modes that (also derive from c-mode?) and use c-basic-offset are listed independently. Why not add (php-mode c-basic-offset) to the list to make it obvious to people that that popular mode is supported? Its apparent lack of that mode confused me. And it would help all contributors see that the mode is supported and has been figured out. There are 8 matches for c-basic-offset, so let's add a 9th?: https://github.com/editorconfig/editorconfig-emacs/blob/master/editorconfig.el ;-)

10sr pushed a commit that referenced this issue Dec 12, 2016
About `php-mode-coding-style'.

They basically do this at mode startup: "if php-mode-coding-style is
'pear' (which it is by default), add a c-style called 'pear' and
switch to it", and that style contains a c-basic-offset value. But
since we're hooking later than that, we're welcome to override
c-basic-offset without any risk.

Also, php-mode suggests manually typing "nxml-mode" and "js2-mode" and
"web-mode" and then "php-mode" etc, to switch editing styles if you
have a document with multiple types of content (which is common in
.php files), and every time you type php-mode, it runs that style
injection again and resets c-basic-offset.
However, editorconfig runs as a hook when the major mode changes,
so it still re-applies the correct offset every time that happens.

See #116 for more details.
@10sr
Copy link
Member

10sr commented Dec 12, 2016

Good point!
I think there is no reason that php-mode should not be added, I just added it 👍

Also I added a brief code comment, and wrote a bit more to the commit comment, which we can find via git-blame ;-)

@xuhdev
Copy link
Member

xuhdev commented Dec 12, 2016

Shall we close this issue?

@ghost
Copy link
Author

ghost commented Dec 12, 2016

@10sr @xuhdev

Looks good to me! Let's close the issue. :-)

@ghost ghost closed this as completed Dec 12, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants