Fork me on GitHub

Unfortunately, I often find myself editing files that are mixed PHP and HTML, and ending with a “.php” extension. For most smaller projects/tasks, I use emacs at the command line (nox) and my .emacs settings for php-mode will latch onto the “.php” extension and open it with PHP mode. Unfortunately, PHP mode really doesn’t like embedded HTML (let alone mostly HTML with some inline PHP), and the indentation gets very messy, among other problems.

The simple solution is to add the following (XHTML 1.0 Transitional-compliant) comment to the first line of the file, which tells emacs to load html-mode:

<!-- -*- mode: html; -*- -->

You can also get emacs to do this for you, as per the Specifying File Variables documentation page. Once in html-mode, simply M-x add-file-local-variable-prop-line, enter “mode” for the variable name and use the default of the current mode.


Comments

comments powered by Disqus