php-mode icon indicating copy to clipboard operation
php-mode copied to clipboard

Use `cc-mode` infrastructure throughout

Open haxney opened this issue 12 years ago • 9 comments

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.

haxney avatar Jan 28 '13 21:01 haxney

BTW, I've started working on this.

haxney avatar Jan 28 '13 21:01 haxney

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.

ejmr avatar Jan 28 '13 21:01 ejmr

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.

haxney avatar Feb 07 '13 00:02 haxney

Awesome, thanks for the work. :)

ejmr avatar Feb 07 '13 01:02 ejmr

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!

jorissteyn avatar Aug 28 '14 06:08 jorissteyn

Great submission :)

I pushed it in a new branch for people to test and mentioned that in the README.

Thanks for the effort!

ejmr avatar Aug 28 '14 17:08 ejmr

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 :)

jorissteyn avatar Aug 31 '14 20:08 jorissteyn

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.

ejmr avatar Aug 31 '14 21:08 ejmr

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

jorissteyn avatar Sep 02 '14 06:09 jorissteyn