Skip to content

Add php-indent.el and php-keywords.el (extracted from #812)#814

Merged
zonuexe merged 3 commits into
masterfrom
feat/php-indent-keywords
Jul 16, 2026
Merged

Add php-indent.el and php-keywords.el (extracted from #812)#814
zonuexe merged 3 commits into
masterfrom
feat/php-indent-keywords

Conversation

@zonuexe

@zonuexe zonuexe commented Jul 16, 2026

Copy link
Copy Markdown
Member

Split out of #812, which is blocked until the August release by the Emacs 28.1 requirement (#811). These two files are the part of that branch that is purely additive, so they can be reviewed and land now.

What this adds

  • lisp/php-keywords.el — the PHP vocabulary (control structures, declarations/modifiers, statements, primitive types, constants, magic constants, magic methods) as plain defconst tables plus a symbol-bounded regexp-opt for each. The provenance of every entry is documented in the commentary: derived from the c-lang-defconst tables of the CC Mode based implementation, supplemented where PHP has gained keywords since.
  • lisp/php-indent.el — the indentation engine ported from the syntax-ppss based indenter of js.el in GNU Emacs (attributed in the file header). The JavaScript specific handling (JSX, C preprocessor macros, array comprehensions, regexp literals) is removed; PHP specifics are added: ->/?->/:: chains, . concatenation aligned to the assignment, statement continuations, switch/case, the alternative syntax (endif &c.) and heredoc/nowdoc bodies. Entry points are php-indent-line / php-indent-region.
  • Both files are registered in Eask's (files ...) so CI byte-compiles them.

Why this is compatibility-safe

  • Nothing requires either file. No require, no autoload, nothing sets php-indent-line as indent-line-function. The current CC Mode based php-mode keeps indenting through cc-engine, unchanged. The engine is inert until the cc-mode independent mode lands.
  • No symbol collisions with the current tree (php-indent-*, php-keywords--* are all new names).
  • Emacs 27 safe — no Emacs 28+ functions are used, so this does not front-run Drop Emacs 27 Support #811. php-indent.el requires php.el only for the php customization group; php-keywords.el requires nothing.
  • Byte-compiles with no new warnings, and the existing test suite is unaffected (62 tests, unchanged).

Not included (deliberately)

The rest of #812 cannot be separated this cleanly:

  • php-style.el needs php-mode-coding-style moved from php-mode.el into php.el, which comes with the default change pearper and the removal of symfony2 — a breaking change.
  • The php.el CC Mode removal reimplements php-leading-tokens' token scanner and reworks php--analysis-syntax-table, so it is behaviour-affecting rather than additive.
  • The new php-mode.el / the php-cc-mode.el rename and the Emacs 28.1 bump are the core of Rewrite php-mode as a CC Mode independent major mode #812 and stay there.

Follow-up: keyword tables trimmed

php-keywords--magic-constants mirrored php.el's php-magical-constants plus "PHP_EOL", and the file's own commentary conceded the cost — "keep the two lists in sync if php-magical-constants ever changes". Nothing read it (both major modes build their php-magical-constant font-lock rule straight from php.el's list), so it is gone and php.el stays the single source of truth.

The two lists were never interchangeable, which is why they are not simply unified: PHP_EOL is a predefined runtime constant, not a magic constant, so collapsing them under one name would have started fontifying PHP_EOL as a magic constant.

php-keywords--magic-methods had no reader either, and was supplemented wholesale from the PHP manual rather than derived from php-cc-mode.el, so it is not needed to reproduce the current fontification. Dropped until something wants it.

Moving php.el's php-magical-constants into this module (so that the "single source of truth for PHP keywords" claim becomes literally true) is deliberately not done here: it is a public-symbol move that needs an obsolete alias, and it belongs with the php.el rework in #812 rather than in a PR whose selling point is being inert and additive. php-re-token-symbols stays in php.el as well — its only consumer is php.el's own token scanner, and it has no list form to fit this file's NAME / NAME-re convention.

zonuexe added 3 commits July 16, 2026 21:24
Extracted from the cc-mode independent php-mode work (#812) so that it
can be reviewed and land independently of the Emacs 28.1 requirement
that blocks that branch until the August release (#811).

The file holds the PHP vocabulary (control structures, declarations and
modifiers, statements, primitive types, constants, magic constants and
magic methods) as plain defconst tables plus a symbol-bounded regexp-opt
for each.  The provenance of every entry is documented in the
commentary: they were derived from the c-lang-defconst tables of the CC
Mode based implementation, supplemented where PHP has gained keywords
since.

This is purely additive: nothing requires php-keywords.el yet, so the
tables have no effect on php-mode until the cc-mode independent mode
lands.
Extracted from the cc-mode independent php-mode work (#812) so that it
can be reviewed and land independently of the Emacs 28.1 requirement
that blocks that branch until the August release (#811).

The engine is ported from the syntax-ppss based indenter of js.el in GNU
Emacs (attributed in the file header); the JavaScript specific handling
(JSX, C preprocessor macros, array comprehensions and regexp literals)
is removed, and PHP specifics are added: -> / ?-> / :: method and
property chains, the . concatenation operator aligned to the assignment,
statement continuations, switch/case, the alternative syntax (endif and
friends) and heredoc/nowdoc bodies.  Its entry points are php-indent-line
and php-indent-region.

The file is self-contained: it only requires php.el for the php
customization group, and defines no symbol that collides with the
current php-mode.

This is purely additive: nothing sets php-indent-line as
indent-line-function yet, so the engine is inert -- the current CC Mode
based php-mode keeps indenting through cc-engine.  Registering both new
files in Eask so they are byte-compiled by CI.
php-keywords--magic-constants mirrored php.el's php-magical-constants
plus "PHP_EOL", and the file's own commentary conceded the cost: "keep
the two lists in sync if php-magical-constants ever changes".  Nothing
reads it -- both major modes build their php-magical-constant font-lock
rule straight from php.el's list -- so remove it and leave php.el as the
single source of truth.

Note that the two lists were never interchangeable: PHP_EOL is a
predefined runtime constant rather than a magic constant, so unifying
them under one name would have started fontifying PHP_EOL as a magic
constant.  Predefined library constants stay out of this module; the
commentary now says so.

php-keywords--magic-methods has no reader either.  It was supplemented
wholesale from the PHP manual rather than derived from php-cc-mode.el,
so it is not needed to reproduce the current fontification; drop it
until something actually wants it.

Also correct the commentary, which claimed php-mode.el was "not yet
written": it exists, still fontifies through CC Mode, and does not
require this file yet.
@zonuexe
zonuexe merged commit 22e5c80 into master Jul 16, 2026
14 checks passed
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

Successfully merging this pull request may close these issues.

1 participant