For my job at Hulu this summer, I’ve been developing a RESTful web service and web based frontend using CherryPy and Mako Templates. Since Mako uses a mix of its own syntax, HTML and Python, syntax highlighting won’t work out of the box in Emacs. Enter MMM (Multiple Major Mode) Mode, which allows for multiple Emacs major modes within one buffer, and MMM-Mako Mode which provides support for Mako files using MMM. Getting these set up was somewhat problematic, so I’m going to document the process for anyone else trying to get these working.
(I assume python-mode is already working)
- Download and untar MMM Mode from http://sourceforge.net/projects/mmm-mode/files/. I’m using version 0.4.8.
- Make and install MMM Mode. You need to specify where your Emacs is installed. I use Gnu Emacs 23, which I have installed in the
EMACS='/Applications/Emacs.app/Contents/MacOS/Emacs' ./configure make sudo make install
The elisp files were installed to
/usr/local/share/emacs/site-lispin my case. You may need to add this directory to the Emacs load path. You will also need to tell Emacs to load the module. I added this to my .emacs:
(add-to-list 'load-path "/usr/local/share/emacs/site-lisp") (require 'mmm-auto) (setq mmm-global-mode 'maybe)
Make sure it installed correctly by opening up Emacs and typing
M-x mmm-modeto turn on MMM-Mode.
- Now you’ll want to download MMM-Mako from https://bitbucket.org/pjenvey/mmm-mako/downloads. Follow instructions as in the README, pointing Emacs to the
mmm-mako.elfile. I added to my
(add-to-list 'auto-mode-alist '("\\.mako\\'" . html-mode)) (mmm-add-mode-ext-class 'html-mode "\\.mako\\'" 'mako)
- At this point, everything is configured for MMM-Mako, and opening a
.makofile should enable MMM-Mode. If you open a file with both Python and HTML, however, you will probably see an error:
mmm-format-string: Wrong type argument: stringp, (sgml-xml-mode "XHTML" "HTML")
sudo patch /usr/local/share/emacs/site-lisp/mmm-utils.el fix_mmm-format-string.diff
You’ll want to byte-compile the modified file, so open up Emacs again and type
M-x byte-compile-fileand provide it with the location of your
mmm-utils.elfile. You may need to do this with root privileges depending on where you installed the MMM-Mode files.
At this point you should have a fully functioning MMM-Mako Mode.
All the additions to my
(add-to-list 'load-path "/usr/local/share/emacs/site-lisp") (require 'mmm-auto) (setq mmm-global-mode 'maybe) (load "src/mmm-mako.el") (add-to-list 'auto-mode-alist '("\\.mako\\'" . html-mode)) (mmm-add-mode-ext-class 'html-mode "\\.mako\\'" 'mako)