Add php-indent.el and php-keywords.el (extracted from #812)#814
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 plaindefconsttables plus a symbol-boundedregexp-optfor each. The provenance of every entry is documented in the commentary: derived from thec-lang-defconsttables of the CC Mode based implementation, supplemented where PHP has gained keywords since.lisp/php-indent.el— the indentation engine ported from thesyntax-ppssbased 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 arephp-indent-line/php-indent-region.Eask's(files ...)so CI byte-compiles them.Why this is compatibility-safe
require, no autoload, nothing setsphp-indent-lineasindent-line-function. The current CC Mode basedphp-modekeeps indenting through cc-engine, unchanged. The engine is inert until the cc-mode independent mode lands.php-indent-*,php-keywords--*are all new names).php-indent.elrequiresphp.elonly for thephpcustomization group;php-keywords.elrequires nothing.Not included (deliberately)
The rest of #812 cannot be separated this cleanly:
php-style.elneedsphp-mode-coding-stylemoved fromphp-mode.elintophp.el, which comes with the default changepear→perand the removal ofsymfony2— a breaking change.php.elCC Mode removal reimplementsphp-leading-tokens' token scanner and reworksphp--analysis-syntax-table, so it is behaviour-affecting rather than additive.php-mode.el/ thephp-cc-mode.elrename 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-constantsmirrored php.el'sphp-magical-constantsplus"PHP_EOL", and the file's own commentary conceded the cost — "keep the two lists in sync ifphp-magical-constantsever changes". Nothing read it (both major modes build theirphp-magical-constantfont-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_EOLis a predefined runtime constant, not a magic constant, so collapsing them under one name would have started fontifyingPHP_EOLas a magic constant.php-keywords--magic-methodshad 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-constantsinto 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-symbolsstays 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'sNAME/NAME-reconvention.