php-mode
php-mode copied to clipboard
Use `cc-mode` infrastructure throughout
Much of the existing functionality can be implemented in terms of c-lang-defconst
calls at the top-level. These seem to have the advantage of handling both indentation and font-locking within the same declarations. This also allows more complete leverage of the powerful cc-mode
libraries.
This supersedes ejmr/php-mode#64.
BTW, I've started working on this.
Good idea. Redefining the core of php-mode, particularly how we inform Emacs about the structure of the language, will make it easier to take advantage of things like customizable lineup functions in cc-mode. It also feels like a good direction to go in terms of making the codebase more consistent in structure. After all, php-mode is going on fourteen years now, and lots of people have worked on it, and we certainly haven't all been consistent in the way we've implemented things. And in all those years Elisp and standard libraries have improved as well, like ERT, things we ought to leverage in our favor. So I like this idea a lot, using more of cc-mode.
I'm getting closer! It seems like most fontification can be done with trivial
definitions of php-font-lock-keywords-*
, which means the cc-mode
machinery
is doing something right.
On my current branch, here are the definitions of the php-font-lock-keywords-*
variables:
(defconst php-font-lock-keywords-1 (c-lang-const c-matchers-1 php)
"Basic highlighting for PHP mode.")
(defconst php-font-lock-keywords-2 (c-lang-const c-matchers-2 php)
"Medium level highlighting for PHP mode.")
(defconst php-font-lock-keywords-3 (c-lang-const c-matchers-3 php)
"Detailed highlighting for PHP mode.")
(defvar php-font-lock-keywords php-font-lock-keywords-3
"Default expressions to highlight in PHP mode.")
Indentation still needs some work, but is mostly there.
Awesome, thanks for the work. :)
After playing around with haxneys changes, I believe this is an excellent course of direction. I rerolled the original changes on current php-mode and made some fixes to make it pass the test suite.
In case anyone's interested: https://github.com/jorissteyn/php-mode/tree/work/ccmode
It seems to work really well, but I still have some fixes upcoming -- if only PHP had chosen :: as namespace separator :). Feedback is very welcome!
Great submission :)
I pushed it in a new branch for people to test and mentioned that in the README.
Thanks for the effort!
Great idea to mention this experiment in the README, but if it's not on master, the only people who will read it are the people that already know about it :)
Great point. I'm in such a habit of looking at all the different branches that people not doing that honestly didn't cross my mind at the time. I've copied the mention into the README on the master
branch.
As discussed in PR #168, the hard require 'cl I added to get this branch pass CI is bogus. It should work with:
(unless (require 'cl-lib nil t)
(require 'cl))
But I don't know what difference between master and the cc-mode branch causes this, I'm not calling set-difference anywhere in php-mode/php-mode-test.
Error output: https://travis-ci.org/jorissteyn/php-mode/jobs/34121887