Commit 82ab795
committed
Honor major-mode-remap-alist in php-mode-maybe
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).1 parent a357bc8 commit 82ab795
2 files changed
Lines changed: 44 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
646 | 646 | | |
647 | 647 | | |
648 | 648 | | |
649 | | - | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
650 | 656 | | |
651 | 657 | | |
652 | | - | |
| 658 | + | |
| 659 | + | |
653 | 660 | | |
654 | 661 | | |
655 | 662 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
699 | 699 | | |
700 | 700 | | |
701 | 701 | | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
702 | 737 | | |
703 | 738 | | |
704 | 739 | | |
| |||
0 commit comments