Search code examples
emacstemplate-toolkit

Adding a submode to nXhtml


Having made the jump just recently from XEmacs to GNU Emacs, I'm really loving nXhtml mode for writing web code. I'd like to be able to add a sub mode to it, though, and I'm not sure how. There doesn't seem to be a good reference to do so.

I have a mode for Perl's Template Toolkit, loaded as tt-mode and the default for .tmpl files, and I'd like to use nXhtml for my .tmpl files, with tt-mode taking over only between the [% %] tags.


Solution

  • Well, it appears (after some digging), that modes are defined in util/mumamo-fun.el, and there is already a Template Toolkit mode defined.

    EDIT: Took out my original notes about having a problem with automatically loading it, because I was doing something dumb. :P)

    Setting it up automatically was pretty simple:

    (require 'mumamo-fun)
    (setq auto-mode-alist (append '(("\\.tmpl$" . tt-html-mumamo)) auto-mode-alist))
    

    Voila!

    It looks like setting up other new modes is a fairly simple process. util/mumamo-fun.el contains the templates for all of the submodes. Following that format, it defines functions for finding chunks of the buffer that define a certain submode, and then builds them with other chunks (like the inline css and javascript, etc) into something that mumamo understands. I haven't actually tried to build a different mode, though, so I'm not sure if there is any additional work that needs to be done, but once defined, they seem to be registered with mumamo automatically.