Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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"?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
That worked like a charm. Thank you! –  RobKohr Sep 27 '12 at 13:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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