Editing MJT code with Emacs – nXhtmlMode

If you don’t use Emacs to write MJT code then stop reading now.

nXhtmlMode will dramatically improve your productivity if you write MJT code in Emacs. It highlights invalid XHTML as you type so you never have strange MJT bugs due to unclosed DIVs. You can also add a MJT schema to avoid unnecessary warnings about proprietary attributes.

Step by step guide to installing nXhtml mode

Install nXhtml:

  • Download the latest version of nXhtml.zip
  • Unzip into a directory, for example: ~/.emacs.d
  • Edit your .emacs and add
    (load "~/.emacs.d/nxml/autostart.el")
  • Run emacs, open an HTML file and type M-x nxhtml-mode

Accept the default customization:

  • Click “remove this message”
  • Set Nxhtml Skip Welcome: “toggle” to on
  • Click “Save for future sessions”
  • Click “Finish”

Install the MJT schema
(At this stage, any errors in your HTML should be highlighted. Unfortunately all the special MJT attrbitues will be highlighted as errors too. We can fix this by overriding the XHTML schema with a MJT schema)

  1. Download mjt.rnc
  2. Move mjt.rnc to ~/.emacs.d/nxml/nxml-mode-20041004/schema/
  3. Edit mjt.rnc and change the first line from
    include "emacs/lisp/nxml-mode/schema/xhtml.rnc"
    to this: include "xhtml.rnc"
  4. Load a MJT html file and type M-x nxhtml-mode. Check the mjt.task attributes are now accepted

Make nxhtml-mode load automatically on opening .html files
Add the following to your .emacs

;; nXhtml-mode
(load "~/.emacs.d/nxml/autostart.el")
;;WILL: there should be a cleaner way to do this

(fset 'html-helper-mode 'nxhtml-mode)
(fset 'html-mode 'nxhtml-mode)


Now whenever you open an HTML file with Emacs you will automatically see any markup errors. This can save a lot of debug time!

TODO: make multiple modes work so that mjt.script appears as formatted javascript inside an HTML file.

Thanks to Nick for the pointer to nxml-mode and to Jessica for prompting me to write this doc.

Please leave a comment if you try these steps. I’d like to know if it works for other people (or if you know a better way)


3 Responses to Editing MJT code with Emacs – nXhtmlMode

  1. LeoB says:

    Please notice that the download link for nXhtml should be


    The latest released version can be found there (at the bottom of the page).

  2. LeoB says:

    Will, can you please contact me about the problems with MJT and syntax problems in nXhtml?

  3. Will Moffat says:

    Hi LeoB, thanks for pointing out the broken link. I’ve fixed the post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: