It looks a quite magic that the web-mode could mix with php mode. A major mode could contain another major mode. This seems amazing.

(add-to-list 'auto-mode-alist '("\\.php\\'" . php-mode))
(add-to-list 'auto-mode-alist '("\\.blade\\.php\\'" . web-mode))

If I have a file named "portal.blade.php", how does web-mode recognize the internal php code?

  • 1
    One question per customer . . . consider editing to frame just one (1) specific question. Consider also specifying what is meant by "recognize the internal php code" -- i.e., what is it that the original poster expects to see happen? Has the original poster tried using the library yet --- and if so, what happened and why is it now a question?
    – lawlist
    Commented Jul 31, 2015 at 1:06

1 Answer 1


I'm no expert in this, but taking a quick look at the code I say it's regular expressions. Web-mode seems to use regexes to search for <?|<?php tags, then it knows what comes further is php code. The same goes for html, asp, javascript and other languages. I think you should look at the code yourself (M-x describe-function web-mode). And if you're really interested, you could try writing a simple major mode to better understand how major modes work, then you should be able to know better what web-mode does under the hood.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.