Fall back on an HTML mode for Blade when web-mode is missing#817
Merged
Conversation
zonuexe
force-pushed
the
fix/blade-fallback
branch
from
July 16, 2026 14:43
7a7824e to
bf1a099
Compare
Opening a .blade.php file without web-mode installed did not warn and carry on -- it failed. php-derivation-major-mode warned but left MODE set to the unavailable web-mode, so php-mode-maybe went on to funcall it and signalled void-function. Every other template zeroed MODE and fell back on php-default-major-mode; Blade was the one case that could not open at all. Degrade instead. A Blade template is mostly HTML plus Blade's own directives -- it is not PHP, so php-mode cannot read it either -- and an HTML mode renders the bulk of it correctly. The new php-blade-template-major-mode-fallback names the modes to try (mhtml-mode then html-mode, both built in); set it to nil to opt out and get php-default-major-mode as before. The warning now says which mode was substituted rather than claiming Blade is unsupported. The fallback deliberately applies to Blade only. Other templates are PHP with HTML in them, which php-mode does read, and they share php-html-template-major-mode with the auto-detection path -- php-project-php-file-as-template defaults to `auto', so any .php file holding an HTML tag reaches it. Extending the fallback there would take most PHP files away from php-mode for everyone without web-mode. A test pins that behaviour down. Uses cl-loop, as php-leading-tokens already does; php.el requires cl-lib at compile time and cl-macs is loaded by the time it runs.
zonuexe
force-pushed
the
fix/blade-fallback
branch
from
July 16, 2026 14:45
bf1a099 to
d89e90d
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.
Answers "can we fall back on
html-modewhenweb-modeisn't installed?" — yes, and it also fixes a hard failure.The bug
Opening a
.blade.phpwithoutweb-modeinstalled didn't warn and carry on. It failed:php-derivation-major-modewarned but left MODE set to the unavailableweb-mode, sophp-mode-maybefuncalled it. Every other template zeroes MODE and falls back onphp-default-major-mode— Blade was the one case that couldn't open at all.The fix
Degrade instead. A Blade template is mostly HTML plus Blade's own directives — it isn't PHP, so
php-modecan't read it either — and an HTML mode renders the bulk of it correctly.New
php-blade-template-major-mode-fallback, default'(mhtml-mode html-mode)(both built in, no new dependency). The first available entry wins; set it to nil to opt out and getphp-default-major-modeas before. The warning now names the substitute rather than claiming Blade is unsupported:Scope: Blade only, deliberately
The fallback does not extend to
php-html-template-major-mode. That mode is shared with the auto-detection path, andphp-project-php-file-as-templatedefaults toauto— so any.phpfile containing an HTML tag reaches it. Routing those to an HTML mode would take most PHP files away fromphp-modefor everyone without web-mode. Those templates are PHP with HTML in them, whichphp-modedoes read, so they keep falling back onphp-default-major-mode.php-mode-test-html-template-fallback-unchangedpins that down — it passes both before and after this change.Verification
End-to-end, without web-mode installed:
welcome.blade.phpvoid-function web-modemhtml-modepage.php(has<div>)php-modephp-mode(unchanged)plain.phpphp-modephp-mode(unchanged)The Blade test fails before the fix and passes after; the HTML-template test passes both ways. Byte-compiles with no new warnings; full suite green.
seq-findis deliberately avoided sinceseqisn't preloaded on every supported Emacs, so this is safe for the Emacs 27-supporting series.For context: how Emacs's built-in php-ts-mode handles Blade
It doesn't — there is no mention of Blade anywhere in the Emacs tree.
.blade.phpends in.php, so it matches php-ts-mode'sauto-mode-alistpatterns and opens as plainphp-ts-mode, where@extendsand{{ }}are parse errors. This package routes Blade to web-mode and now degrades sensibly without it, so it stays ahead of core on that front either way.