Wednesday, January 9, 2013

web mode for Emacs

Emacs for editing code is wonderful. It does syntax coloring, magical re-indenting of erratic code, and will highlight sketchy bits.  It gets confused with web programming, as you generally have HTML, CSS, JavaScript and Django template text in the same document.

Here's how to install "multi web mode", which will switch the Emacs mode depending on what type of code is being edited.

cd ~/.emacs.d/

git clone git@github.com:fgallina/multi-web-mode.git


Add this to your ~/.emacs.d/init.el:


(when t
  (add-to-list 'load-path "~/.emacs.d/multi-web-mode/")
  (require 'multi-web-mode)
  (setq mweb-default-major-mode 'html-mode)
  (setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
   (js-mode "")
   (css-mode "")))
  (setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
  (multi-web-global-mode 1))

Exit emacs, then fire it up again to enable the mode.