Honor major-mode-remap-alist in php-mode-maybe#816
Merged
Conversation
Emacs's built-in php-ts-mode registers
(add-to-list 'treesit-major-mode-remap-alist '(php-mode . php-ts-mode))
with the comment "To be able to toggle between an external package and
core ts-mode", and `treesit-enabled-modes' copies that entry into
`major-mode-remap-alist' when the user opts in. So a user who installs
this package and enables php-ts-mode is asking for php-ts-mode.
They did not get it for .php files. `set-auto-mode' applies the
remapping to whatever `auto-mode-alist' names, so entries pointing
straight at `php-mode' honored it, but ".php"/".phtml" go through
`php-mode-maybe', which is not itself a remap target and called the
derived mode directly. The same buffer therefore opened in different
modes depending on the extension:
a.stub auto-mode-alist=php-mode -> php-ts-mode (remapped)
a.php auto-mode-alist=php-mode-maybe -> php-mode (not remapped)
Resolve the derived mode through `major-mode-remap' so `php-mode-maybe'
behaves as if `auto-mode-alist' had named the mode directly. The
function is Emacs 30 or later, hence the `fboundp' guard; on older
Emacs the mode is used unchanged, as before.
Note that no adjustment is needed for `php-base-mode': php-ts-mode
declares `php-mode' as an extra parent via `derived-mode-add-parents',
and `php-mode' derives from `php-base-mode', so once this package is
loaded `derived-mode-all-parents' of php-ts-mode already resolves to
(php-ts-mode php-mode php-base-mode prog-mode).
zonuexe
force-pushed
the
fix/honor-major-mode-remap
branch
from
July 16, 2026 14:34
63422d6 to
82ab795
Compare
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.
Interop fix for Emacs's built-in
php-ts-mode(checked against Emacs 32.0.50).The bug
php-ts-mode registers this on load:
and
treesit-enabled-modescopies the entry intomajor-mode-remap-alistwhen the user opts in. So a user who installs this package and enables php-ts-mode is explicitly asking for php-ts-mode — Emacs core added that entry for our benefit.They didn't get it for
.phpfiles.set-auto-modeapplies the remapping to whateverauto-mode-alistnames; entries pointing straight atphp-modehonored it, but".php"/".phtml"go throughphp-mode-maybe, which is not itself a remap target and called the derived mode directly. The result was inconsistent within the same configuration:auto-mode-alista.stubphp-modea.phpphp-mode-maybeThe fix
Resolve the derived mode through
major-mode-remap, sophp-mode-maybebehaves as ifauto-mode-alisthad named the mode directly.major-mode-remapis Emacs 30+, hence thefboundpguard — on older Emacs the mode is used unchanged, exactly as before, so this is safe for the Emacs 27-supporting series.A regression test is included. It uses a stub mode rather than php-ts-mode itself, so it does not depend on the PHP tree-sitter grammar being installed, and it is skipped where
major-mode-remapdoes not exist. Verified that it fails before the fix and passes after.What needed no change
php-base-modeis fine as-is. php-ts-mode declaresphp-modean extra parent viaderived-mode-add-parents, and ourphp-modederives fromphp-base-mode, so once this package is loaded:(derived-mode-p 'php-base-mode)already works in php-ts-mode buffers, and thephp-base-modedocstring naming both modes is accurate. Note also that adding parents from our side would be actively harmful:derived-mode-add-parentsreplaces the extra-parents list, so it would clobber php-ts-mode's(php-mode)link.