Question

How do I disable flymake when I'm working on Django templates?

Flymake is great for editing python files, but is really giving me problems with django templates. For instance, the following template throws no errors, though the syntax highlighting doesn't work for the template tags:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>{% block title %}Page title{% endblock %}</title>
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>

<body>
{% block content %}
  <p>… Your HTML content here …</p>
{% endblock %}
</body>
</html>

However, the following template is riddled with font-lock for flymake errors:

{% extends base.html %}

{% block content %}
<h1>Welcome!</h1>
{% endblock %}

Hovering over the errors with a mouse reveals that flymake is complaing about "Text not allowed".

I've followed each solution in this related question, but none of them disable flymake for html buffers. I even tried renaming all my template files to end in .djhtml instead of .html, but flymake was still active after re-visiting the files. I did change the auto-mode list to apply django-html-mode to .djhtml files, so maybe the issue lies there.

UPDATE: I've found that switching to html-mode doesn't have this issue, since I've implemented the previously mentioned solutions. However, if I switch to nxml-mode or django-html-mode (what I'd like to use), flymake starts up again and tells me it is:

Using schema /usr/local/Cellar/emacs/HEAD/share/emacs/24.0.93/etc/schema/xhtml.rnc

Emacs24 Carbon on Snow Leopard.

GNU Emacs 24.0.93.1 (i386-apple-darwin10.8.0, NS apple-appkit-1038.36) of 2012-02-21 on hook
Was it helpful?

Solution

The django wiki lists several options for working with emacs, but doesn't offer a whole lot of guidance on particular strengths and weaknesses of each mode.

The workaround I'm using at the moment involves using the django-html-mumamo-mode instead of django-mode. Here's what I've figured out on my quest to set up emacs with django.

Bear in mind, some of these observations might change as these packages are developed.

pony-mode

Looks promising, but the documentation isn't complete, and syntax highlighting in templates didn't work for me. This is what I was really after, but others might enjoy the other features that are baked-in.

django-html-mumamo-mode

This comes bundled with nXhtml. There aren't any snippets included, but snippets can be found with Google, or imported from a Textmate bundle with yasnippet. Speaking of which, this mode conflicts with the yasnippet-bundle provided through ELPA, so be sure to follow the development trunk to avoid having to restart emacs everytime you trigger a snippet. BTW, syntax highlight is great, and you might like the generic web development features that are a part of nXhtml.

django-mode

Syntax highighting and jumping to tags, some snippets included; however, django-mode doesn't play nice with flymake, which I think is because it is derived from nxml-mode. django-modeis no longer under development, nor is nxml-mode from what I can gather. django-html-mumamo-mode doesn't suffer from this flymake issue, since nXhtml includes really nice support for flymake out of the box.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top