Thursday, September 2, 2010

Django Emacs Wiki

Django's Emacs Wiki page is horribly outdated -- many of the links to download the related scripts do not work. Furthermore, the documentation to get them installed requires digging through different parts of the web sites to find the right way to get them loaded. Furthermore, there's very little information about the pros/cons between the various Emacs helper scripts either.

In the order of the items listed, here is my experience with the ones listed on the page:
  • django-mode.el: download link is dead
  • django-html-mode.el: download link is dead
  • django-html-mumamo-mode: tells you to download the latest branch
  • Yasnippet: good for Django autocompletion only
In my previous blog posting, I wrote about some of the basic important Emacs helper programs. PyChecker and Uniqify are definite musts, but Yasnippets actually will conflict if you try to install django-html-mumamo-mode. In the interest of taking advantage of the django-html-mumamo-mode's ability to do Django block indents (the Django snippets for Yasnippet will not do this for you), I commented out the django-mode helpers from Yasnippet:
;(require 'django-html-mode)
;(require 'django-mode)
;(yas/load-directory "~/.emacs.d/plugins/django-mode/snippets")
The instructions on the Django page are to install the latest branch:
bzr branch lp:nxhtml
The problem is that you end up downloading the latest snapshot, which caused some problems for me when I tried into enter into django-html-mode. Instead, I downloaded the 4/25/10 release directly from the NXHTML page by visiting The release is hard to find on the main page but if you click on Download latest nXHTML (zip file)" you can retrieve the file.

I unzipped this file directly into ~/emacs.d, which creates an nxhtml/ directory.

Inside my .emacs file, I add three lines:
(load "~/.emacs.d/nxhtml/autostart.el")
(setq mumamo-background-colors nil)
(add-to-list 'auto-mode-alist '("\\.html$" . django-html-mumamo-mode))
The first line will invoke the NXHTML script to load. If you have Emacs v23, you shouldn't have to install the NXML library.

The second line deals with an issue of NXHTML changing the color background to blue. For more info, see

The third line will force .HTML files into django-html-mumamo-mode. You can also use django-xhtml-mumamo-mode, which will have a "Valid/Invalid" at the bottom of the Emacs screen to inform you whether your HTML code is presumably XHTML-compliant.

No comments:

Post a Comment