I use php mode for .php files, but codeigniter uses .php for the template files which are mostly html, so I would like to use html-mode for those files.
Is there a way to say in the .emacs file "If the file path contains '/views/' use html-mode"?
If you want to use html-mode
for all files under a directory named views
and its sub-directories, you can add the following line at the end of .emacs
:
(add-to-list 'auto-mode-alist '("/views/" . html-mode))
Note that ("/views/" . html-mode)
should appear before an entry for .php
files when you check the value of auto-mode-alist
by C-hvauto-mode-alist.
Similarly, the following line at the end of .emacs
will make Emacs choose html-mode
for all .php
files under a directory named views
and its sub-directories:
(add-to-list 'auto-mode-alist '("/views/.*\\.php\\'" . html-mode))
From auto-mode-alist
's documentation:
auto-mode-alist
Alist of filename patterns vs corresponding major mode functions. Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL). ... Visiting a file whose name matches REGEXP specifies FUNCTION as the mode function to use. FUNCTION will be called, unless it is nil.