<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chicken Scratches &#187; xemacs</title>
	<atom:link href="http://www.chickenwingsw.com/scratches/category/xemacs/feed" rel="self" type="application/rss+xml" />
	<link>http://www.chickenwingsw.com</link>
	<description>Developing ideas on developing.</description>
	<lastBuildDate>Thu, 01 Apr 2010 17:24:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Auto-closing Django template tags in Emacs</title>
		<link>http://www.chickenwingsw.com/scratches/python/auto-closing-django-tags</link>
		<comments>http://www.chickenwingsw.com/scratches/python/auto-closing-django-tags#comments</comments>
		<pubDate>Mon, 07 Jul 2008 15:11:16 +0000</pubDate>
		<dc:creator>Eddie Sullivan</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[xemacs]]></category>

		<guid isPermaLink="false">http://www.chickenwingsoftware.com/scratches/?p=18</guid>
		<description><![CDATA[    
      I have written two previous articles about how I edit Django template files in Emacs and XEmacs.
      Here is
      How
      I edit Django templates. And here
     [...]]]></description>
			<content:encoded><![CDATA[    <p>
      I have written two previous articles about how I edit Django template files in Emacs and XEmacs.
      Here is
      <a href="http://www.chickenwingsoftware.com/scratches/python/how-i-edit-django-templates">How
      I edit Django templates</a>. And here
      is <a href="http://www.chickenwingsoftware.com/scratches/python/more-on-editing-django-templates-in-xemacs">More
	on editing Django templates in XEmacs</a>. Here today is another
      little tip that can be used in conjunction with those two other
      posts or independently.
    </p>
    <p>
      Django templates involve a lot of punctuation. Between the angle
      brackets and slashes of HTML and the curly braces and percent
      signs of the Django template language, it's enough to make your
      pinky fingers hurt just thinking about it. Therefore any little
      trick to reduce some of this typing burden can be
      helpful. Presented here is some Emacs Lisp code to provide
      auto-closing of Django template tags. So even if you still have
      to type things like <b>curly-brace percent-sign space ifequal blah
      blah2 percent-sign close-curly-brace</b>, you won't have to type the
      <b>{% endifequal %}</b>. (Of course, if you're using
      the <em>abbrev</em> tips I gave previously, you won't even need
      to type the opening tag very often, but sometimes you still do.)
    </p>
<span id="more-18"></span>
    <h4>The code</h4>
    <p>
      Ok, here it is. You should be able to copy and paste this into
      your .emacs file. Then anywhere in your template file, simply call
      the new function <b>django-close-tag</b> and it will find the
      last open tag and close it. In the sample code below, I have it
      bound to <em>C-c]</em>; that is, hold down the control key and
      press C, then let go of the control key and press the right
      square bracket. Of course, you can change the code to bind the
      function to any key combination you want.
    </p>
    <pre>
(<span class="keyword">defvar</span> <span class="variable-name">django-closable-tags</span>
  '("<span class="string">for</span>" "<span class="string">block</span>" "<span class="string">comment</span>" "<span class="string">filter</span>" "<span class="string">ifchanged</span>" "<span class="string">ifequal</span>"
    "<span class="string">ifnotequal</span>" "<span class="string">spaceless</span>" "<span class="string">if</span>"))

(<span class="keyword">defvar</span> <span class="variable-name">django-tag-re</span>
  (concat "<span class="string">{%\\s *\\(end\\)?\\(</span>"
          (mapconcat 'identity django-closable-tags "<span class="string">\\|</span>")
          "<span class="string">\\)[^%]*%}</span>"))

(<span class="keyword">defun</span> <span class="function-name">django-find-open-tag</span> ()
  (<span class="keyword">if</span> (search-backward-regexp django-tag-re nil t)
      (<span class="keyword">if</span> (match-string 1) <span class="comment">; If it's an end tag
</span>          (<span class="keyword">if</span> (not (string= (match-string 2) (django-find-open-tag)))
              (error "<span class="string">Unmatched Django tag</span>")
            (django-find-open-tag))
        (match-string 2)) <span class="comment">; Otherwise, return the match
</span>    nil))

(<span class="keyword">defun</span> <span class="function-name">django-close-tag</span> ()
  (interactive)
  (<span class="keyword">let</span> ((open-tag (<span class="keyword">save-excursion</span> (django-find-open-tag))))
    (<span class="keyword">if</span> open-tag
        (insert "<span class="string">{% end</span>" open-tag "<span class="string"> %}</span>")
      (error "<span class="string">Nothing to close</span>"))))

    
(<span class="keyword">define-key</span> <span class="variable-name">html-mode-map</span> "<span class="doc-string">\C-c]</span>" 'django-close-tag)


    </pre>            

    <h4>How it works</h4>
    <p>
      The
      variable <span class="function-name">django-closable-tags</span> is
      a list of all the Django tags that require closing. As more tags
      get added, this list can be expanded.
    </p>
    <p>
      The meat of the work is done
      in <span class="function-name">django-find-open-tag</span>. The
      first thing it does is search backwards through the buffer for
      the last Django tag. If the last tag is an end-tag, the function
      calls itself recursively to skip over that block. This continues
      until it finds an unclosed tag, which it then returns as a string.
    </p>
    <p>
      The function you actually call
      is <span class="function-name">django-close-tag</span>. This
      calls <span class="function-name">django-find-open-tag</span> to
      find a tag to close, then inserts the appropriate end-tag text.
    </p>
    <p>
      Hopefully that is pretty straightforward. The only tricky part
      for a Lisp newbie could be the use of recursion. For a situation
      like this, recursion is the perfect approach. In a sense, the
      function calls build a list of closed tags on the call-stack,
      which then unravels one at a time until an unmatched tag is
      found.
    </p>
    <p>
      Other than that, there is some pretty
      straightforward <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Regexps.html">regular
      expression matching</a>. These are extremely powerful, and you
      should read up on them if you haven't already.
    </p>
]]></content:encoded>
			<wfw:commentRss>http://www.chickenwingsw.com/scratches/python/auto-closing-django-tags/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>More on editing Django templates in XEmacs</title>
		<link>http://www.chickenwingsw.com/scratches/python/more-on-editing-django-templates-in-xemacs</link>
		<comments>http://www.chickenwingsw.com/scratches/python/more-on-editing-django-templates-in-xemacs#comments</comments>
		<pubDate>Thu, 27 Mar 2008 13:58:32 +0000</pubDate>
		<dc:creator>Eddie Sullivan</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[xemacs]]></category>

		<guid isPermaLink="false">http://www.chickenwingsoftware.com/scratches/python/more-on-editing-django-templates-in-xemacs</guid>
		<description><![CDATA[This post addresses the age old question, "If (X)Emacs is so good, why can't it do the typing for me?" Well, the answer, of course, is it can. You just have to write a few lines of Lisp first. Or you can copy and paste the Lisp code off of sites like this one.]]></description>
			<content:encoded><![CDATA[    <p>
      Previously, I wrote about<a href="http://www.chickenwingsoftware.com/scratches/python/how-i-edit-django-templates"> how I set up syntax-highlighting for
      Django template files using MMM (multiple major modes) in
      XEmacs</a>. This entry builds on the previous one, so if you haven't
      read that one, I suggest doing so now.
    </p>
    <p>
      This post addresses the age old question, "If (X)Emacs is so
      good, why can't it do the typing for me?" Well, the answer, of
      course, is it can. You just have to write a few lines of Lisp
      first. Or you can copy and paste the Lisp code off of sites like
      this one. ;)
    </p>
    <h4>Introducing dynamic abbreviations</h4>
    <p>
      Pressing M-/, (that is, holding down the <b>Alt</b> key and
      pressing the forward slash key), runs the command
      <b>dabbrev-expand</b>, which tries to finish whatever word you
      are in the middle of typing. For example, if as I'm typing this
      entry, I type the letter <b>d</b>, then press <b>M-/</b>,
      "dabbrev-expand" shows up, because that was the last word I
      typed that started with <b>d</b>. If I then type <b>M-/</b>
      again, "dabbrev-expand" changes to "down". If I keep pressing
      it, the word cycles through different guesses for what I'm going
      for. If you've ever used VisualStudio, you may see some
      similarities to the Intellisense feature. I find I almost never
      type a whole word anymore, I've become so dependent on dynamic
      completion.
    </p>
    <h4>Templates and more abbreviations</h4>
    <p>
      <b>dabbrev-expand</b> is useful to avoid having to type long
      words over and over, but there are also longer patterns that
      seem to need typing frequently. Thats where the <b>tempo</b>
      package comes in handy, especially when combined with the
      <b>abbrev</b> library. Here is some <a href="http://www.emacswiki.org/cgi-bin/emacs-en/TempoMode">documentation for
      tempo</a>. Here is some <a href="http://www.cs.cmu.edu/cgi-bin/info2www?(emacs)Abbrevs">documentation for abbrev</a>.
    </p>
    <p>
      Essentially, <b>tempo</b> allows you to specify "templates," or
      blocks of standard text that can be parameterized as they are
      filled in: the same concept as Django templates, but meant for
      interactive use. From now on, I will say "tempo template" or
      "Django template" to avoid confusing the two types.
    </p>
    <p>
      <b>abbrev</b> lets you define your own pre-set abbreviations,
      which can be filled in automatically as you type or upon
      request. This can be combined with <b>tempo</b> to do some
      pretty powerful stuff very easily.
    </p>
    <p>
      I have a few Django-specific tempo templates and abbrevs set up
      in my XEmacs initialization file. For example, as soon as I type
      "{% block" followed by a space, the entire framework of a Django
      template block is filled in for me. I've also added a special
      menu to the menu bar for tempo templates I use frequently.
    </p>
    <p>
      HTML and templates can be very repetitive, so I've found this
      saves me a <em>lot</em> of typing.
    </p>
    <h4>My initialization file</h4>
    <p>
      Here is the subset of my ~/.xemacs/init.el file. This includes
      the <b>mmm-mode</b> stuff I discussed last time, as well as the
      tempo templates and abbrevs. I haven't put a tempo template for
      every possible Django template tag, just the ones I use most
      frequently. I'll leave further extension as an exercise for the
      reader.
    </p>
    <p>
      Also, some people don't like the expansion to happen
      automatically as they are typing. To turn this off, comment out
      the line that says "(setq abbrev-mode t)" by putting a semicolon
      (<span class="comment">;</span>) in front of it. Then you can
      manually expand tempo templates by pressing <b>C-\</b>
      (control-backslash).
    </p>
    <p>
      Once again, this is known to work in XEmacs version 21.4 on
      Windows XP. It will most likely work in other versions of
      XEmacs, and possibly in GNU Emacs.
    </p>
    <pre>
<span class="comment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CSS-Mode
</span>(<span class="keyword">autoload</span> 'css-mode "<span class="doc-string">css-mode</span>" "<span class="doc-string">Mode for editing CSS files</span>" t)
(add-to-list 'auto-mode-alist '("<span class="string">\\.css\\'</span>" . css-mode))
(setq cssm-indent-function #'cssm-c-style-indenter)
(setq cssm-indent-level '2)

<span class="comment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Use hm--html-mode for files that end in .tmpl (Django templates)
</span>(add-to-list 'auto-mode-alist '("<span class="string">\\.tmpl\\'</span>" . hm--html-mode))

<span class="comment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Multiple Major Modes.
</span>(<span class="keyword">require</span> '<span class="reference">mmm-vars</span>)
(<span class="keyword">require</span> '<span class="reference">mmm-mode</span>)
(<span class="keyword">require</span> '<span class="reference">mmm-sample</span>)
(setq mmm-global-mode 'maybe)

<span class="comment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Custom MMM classes for Django templates
</span>(mmm-add-classes
 '((my-django-expr
    <span class="reference">:submode</span> python-mode
    <span class="reference">:face</span> mmm-declaration-submode-face
    <span class="reference">:front</span> "<span class="string">{%</span>"
    <span class="reference">:back</span> "<span class="string">%}</span>"
    <span class="reference">:include-front</span> t
    <span class="reference">:include-back</span> t)))

(mmm-add-classes
 '((my-django-var
    <span class="reference">:submode</span> python
    <span class="reference">:face</span> mmm-output-submode-face
    <span class="reference">:front</span> "<span class="string">{{</span>"
    <span class="reference">:back</span> "<span class="string">}}</span>"
    <span class="reference">:include-front</span> t
    <span class="reference">:include-back</span> t)))

(mmm-add-mode-ext-class nil "<span class="doc-string">\\.tmpl\\'</span>" 'embedded-css)
(mmm-add-mode-ext-class nil "<span class="doc-string">\\.tmpl\\'</span>" 'my-django-var)
(mmm-add-mode-ext-class nil "<span class="doc-string">\\.tmpl\\'</span>" 'my-django-expr)
(mmm-add-mode-ext-class nil "<span class="doc-string">\\.tmpl\\'</span>" 'html-js)

<span class="comment">;; Use different colors for different sub-modes.
</span>(setq mmm-submode-decoration-level 2)
<span class="comment">;; Make the code submode a little more readable.
</span>(set-face-background 'mmm-code-submode-face "<span class="doc-string">#EEEEFF</span>")


<span class="comment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Tempo templates and abbrevs
</span>
<span class="comment">;; Control-backslash to expand a tempo template manually.
</span>(global-set-key "<span class="doc-string">\C-\\</span>" 'tempo-complete-tag)

(<span class="keyword">require</span> '<span class="reference">adapt</span>) <span class="comment">; Must be done before hm--html for some reason.
</span>(<span class="keyword">require</span> '<span class="reference">hm--html-mode</span>) <span class="comment">; Needed for hm--html-mode-abbrev-table
</span>(<span class="keyword">require</span> '<span class="reference">tempo</span>) <span class="comment">; Tempo templates.
</span>

<span class="comment">;; Expands &lt;span into an HTML span with a class defined.
</span>(tempo-define-template "<span class="doc-string">span</span>"
                       '("<span class="string">&lt;span class=\"</span>" (p "<span class="string">Class? </span>") "<span class="string">\"&gt;</span>" r "<span class="string">&lt;/span&gt;</span>" &gt;)
                       "<span class="doc-string">&lt;span </span>"
                       "<span class="doc-string">Insert a template for a span with a class</span>")
(<span class="keyword">define-abbrev</span> <span class="function-name">hm--html-mode-abbrev-table</span>
  "<span class="doc-string">&lt;span</span>" "" 'tempo-template-span)

<span class="comment">;; Expands &lt;script into an HTML javascript block.
</span>(tempo-define-template "<span class="doc-string">script</span>"
                       '(&gt; "<span class="string">&lt;script type=\"text/javascript\"&gt;</span>" r "<span class="string">&lt;/script&gt;</span>" &gt; %)
                       "<span class="doc-string">&lt;script </span>"
                       "")
(<span class="keyword">define-abbrev</span> <span class="function-name">hm--html-mode-abbrev-table</span>
  "<span class="doc-string">&lt;script</span>" "" 'tempo-template-script)

<span class="comment">;; Expands a Django template block.
</span>(tempo-define-template "<span class="doc-string">block</span>"
                       '("<span class="string">{% block </span>" (p "<span class="string">Block name? </span>") "<span class="string"> %}</span>" p "<span class="string">{% endblock %}</span>")
                       "<span class="doc-string">{% block </span>"
                       "")
(<span class="keyword">define-abbrev</span> <span class="function-name">hm--html-mode-abbrev-table</span>
  "<span class="doc-string">{% block</span>" "" 'tempo-template-block)

<span class="comment">;; Expands a Django template if tag.
</span>(tempo-define-template "<span class="doc-string">django-if</span>"
                       '("<span class="string">{% if </span>" (p "<span class="string">Conditional? </span>") "<span class="string"> %}</span>" p "<span class="string">{% endif %}</span>")
                       "<span class="doc-string">{% if </span>"
                       "")
(<span class="keyword">define-abbrev</span> <span class="function-name">hm--html-mode-abbrev-table</span>
  "<span class="doc-string">{% if</span>" "" 'tempo-template-django-if)

<span class="comment">;; Expands a Django template for tag.
</span>(tempo-define-template "<span class="doc-string">django-for</span>"
                       '("<span class="string">{% for </span>"
                         (p "<span class="string">Variable? </span>") "<span class="string"> in </span>"
                         (p "<span class="string">List? </span>") "<span class="string"> %}</span>" p
                         "<span class="string">{% endfor %}</span>")
                       "<span class="doc-string">{% for </span>"
                       "")
(<span class="keyword">define-abbrev</span> <span class="function-name">hm--html-mode-abbrev-table</span>
  "<span class="doc-string">{% for</span>" "" 'tempo-template-django-for)

<span class="comment">;; Create a menu for inserting these templates.
</span>(<span class="keyword">defun</span> <span class="function-name">add-templates-menu</span> ()
  (interactive)
  (add-submenu nil '("<span class="string">Tem%_plates</span>"
                     ["<span class="string">{%% %_block %%}</span>" tempo-template-block]
                     ["<span class="string">{%% %_if %%}</span>" tempo-template-django-if]
                     ["<span class="string">{%% %_for %%}</span>" tempo-template-django-for]
                     ["<span class="string">&lt;%_span&gt;</span>" tempo-template-span]
                     ["<span class="string">&lt;s%_cript&gt;</span>" tempo-template-script])))

<span class="comment">;; When entering hm--html-mode, turn on abbrevs and add the template menu.
</span>(add-hook 'hm--html-mode-hook
          (<span class="keyword">lambda</span> ()
            (setq abbrev-mode t)
            (add-templates-menu)))
            
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chickenwingsw.com/scratches/python/more-on-editing-django-templates-in-xemacs/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How I edit Django templates</title>
		<link>http://www.chickenwingsw.com/scratches/python/how-i-edit-django-templates</link>
		<comments>http://www.chickenwingsw.com/scratches/python/how-i-edit-django-templates#comments</comments>
		<pubDate>Fri, 21 Mar 2008 20:09:56 +0000</pubDate>
		<dc:creator>Eddie Sullivan</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[xemacs]]></category>

		<guid isPermaLink="false">http://www.chickenwingsoftware.com/scratches/python/how-i-edit-django-templates</guid>
		<description><![CDATA[ Every programmer has their favorite editor and mode of working. Some people have more than one. For example, I use Microsoft Visual Studio when editing .NET code, DrScheme for editing Scheme code, and XEmacs for pretty much everything else.

This post is about how I use XEmacs for editing Django template files, in the hopes that others may find this useful. ]]></description>
			<content:encoded><![CDATA[<p>
<i>NOTE: This post is pretty old, and I no longer use mmm-mode for Django template editing.
<a href="http://www.chickenwingsoftware.com/scratches/python/auto-closing-django-tags">This post</a> and <a href="http://www.chickenwingsoftware.com/scratches/python/more-on-editing-django-templates-in-xemacs">this post</a> are still accurate, though.</i>
</p> 
    <p>
      Every programmer has their favorite editor and mode of
      working. Some people have more than one. For example, I use
      Microsoft Visual Studio when editing .NET code, <a href="http://download.plt-scheme.org/drscheme/">DrScheme</a> for editing
      Scheme code, and <a href="http://xemacs.org">XEmacs</a> for pretty much everything else.
    </p>
    <p>
      This post is about how I use XEmacs for editing <a href="http://www.djangoproject.com">Django</a> template
      files, in the hopes that others may find this useful.
    </p>
    <h4>
      The "Other" One True Editor
    </h4>
    <p>
      It's rare that people will get passionate about something as
      pedestrian as a way of editing plain text, but the brief history
      of the internet is awash with flamewars and heated discussions
      with titles like "Emacs vs. XEmacs," "Emacs vs vi," and so
      on. I'm not about to go into the relative merits, but the fact
      that certain editors pop up time and time again in these debates
      must mean there is something special about them.
    </p>
    <p>
      Early on in my college education I started using Emacs because
      it was all that was available on the school's servers. (Well,
      that or vi, but vi was and still is black-magic to me.) I got
      over the learning curve, and now I'm hooked.
    </p>
    <p>
      At some point, I switched from Emacs to XEmacs, for reasons I
      can't remember. At the time, it had some feature which was to me
      essential. That reason no longer applies, but neither have I had
      a reason to switch back. These tips may apply even if you use
      GNU Emacs, but they've only been tested in XEmacs.
    </p>
    <p>
      My current setup is Xemacs 21.4 (patch 20), running on Windows
      XP. *gasp!* Yes, I use Windows for Django development. Shocking,
      I know. I have my reasons. In any case, these tips should work
      equally well with XEmacs on other platforms.
    </p>
    <h4>
      Multiple Major Modes
    </h4>
    <p>
      I won't include a full XEmacs tutorial here, since there is
      already plenty of info on the web about it. The key point
      is that there is a "major mode" for each programming
      environment. There is a Python mode, a Java mode, and so
      on. Django templates tend to combine more than one language in a
      file, so that's when the <i>mmm</i> library comes in handy. It
      stands for "multiple major modes," and it turns out to be just
      exactly what we need. We can have html-mode for the HTML parts,
      JavaScript-mode for the JavaScript parts, css-mode for embedded
      CSS, and python-mode for the Django template filters and tags.
    </p>
    <h4>
      Which HTML mode?
    </h4>
    <p>
      As often happens in the world of Free Software, there are
      several options to choose from when setting up HTML editing in
      XEmacs.
    </p>
    <ul>
      <li><b>html-mode</b>. This has the fullest support for HTML
      parsing and validation. The problem is, when dealing with
      templates, the HTMl will often not validate, so all kinds of
      error messages show up.
      </li>
      <li>
	<b>sgml-mode</b>. This is a more general mode for SGML (of
	which XML and HTML 4 are subsets).
      </li>
      <li>
	<b>xml-mode</b>. SGML mode specialized for XML.
      </li>
      <li>
	<b>hm--html-mode</b>. I have no idea what the HM stands for,
	but this is a lightweight HTML mode, with basic syntax
	highlighting and indentation.
      </li>
    </ul>
    <p>
      I use <b>html-mode</b> for full-fledged HTML documents, and
      <b>hm--html-mode</b> for templates. So that XEMacs can tell the difference,
      I use the suffix ".tmpl" for template files.
    </p>
    <h4>One problem</h4>
    <p>
      I did run into some problems getting mmm-mode to work with
      XEmacs. It turns out the version of mmm-mode that is distributed
      with the XEmacs package system is ancient - from 2001. I had to
      download the <a href="http://mmm-mode.sourceforge.net/">newer version of mmm-mode</a> and unzip it into my site-packages directory.
    </p>
    <h4>How it looks</h4>
    <p>
      Here's a screenshot of me editing an example Django template
      (borrowed from my beta-registration Django app). I've chosen
      fairly bright colors to make the syntax highlighting more
      obvious, but that's all customizable. Notice how the Django tags
      and variables are easy to find in the file. (Click on the image
      for a larger size.)
    </p>
    <p>
      <a href="http://www.chickenwingsoftware.com/media/xemacs screenshot.png">
	<img src="http://www.chickenwingsoftware.com/media/xemacs screenshot small.png".>
      </a>
    </p>
    <h4>My initialization file</h4>
    <p>
      Here is the subset of my ~/.xemacs/init.el file dealing with
      setting up mmm-mode for XEmacs. I hope someone finds this
      useful. Let me know if you do, or if you encounter problems.
    </p>
    <pre>
<span class="comment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CSS-Mode
</span>(<span class="keyword">autoload</span> 'css-mode "<span class="doc-string">css-mode</span>" "<span class="doc-string">Mode for editing CSS files</span>" t)
(add-to-list 'auto-mode-alist '("<span class="string">\\.css\\'</span>" . css-mode))
(setq cssm-indent-function #'cssm-c-style-indenter)
(setq cssm-indent-level '2)

<span class="comment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Use hm--html-mode for files that end in .tmpl (Django templates)
</span>(add-to-list 'auto-mode-alist '("<span class="string">\\.tmpl\\'</span>" . hm--html-mode))

<span class="comment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Multiple Major Modes.
</span>(<span class="keyword">require</span> '<span class="reference">mmm-vars</span>)
(<span class="keyword">require</span> '<span class="reference">mmm-mode</span>)
(<span class="keyword">require</span> '<span class="reference">mmm-sample</span>)
(setq mmm-global-mode 'maybe)

<span class="comment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Custom MMM classes for Django templates
</span>(mmm-add-classes
 '((my-django-expr
    <span class="reference">:submode</span> python-mode
    <span class="reference">:face</span> mmm-declaration-submode-face
    <span class="reference">:front</span> "<span class="string">{%</span>"
    <span class="reference">:back</span> "<span class="string">%}</span>"
    <span class="reference">:include-front</span> t
    <span class="reference">:include-back</span> t)))

(mmm-add-classes
 '((my-django-var
    <span class="reference">:submode</span> python
    <span class="reference">:face</span> mmm-output-submode-face
    <span class="reference">:front</span> "<span class="string">{{</span>"
    <span class="reference">:back</span> "<span class="string">}}</span>"
    <span class="reference">:include-front</span> t
    <span class="reference">:include-back</span> t)))

(mmm-add-mode-ext-class nil "<span class="doc-string">\\.tmpl\\'</span>" 'embedded-css)
(mmm-add-mode-ext-class nil "<span class="doc-string">\\.tmpl\\'</span>" 'my-django-var)
(mmm-add-mode-ext-class nil "<span class="doc-string">\\.tmpl\\'</span>" 'my-django-expr)
(mmm-add-mode-ext-class nil "<span class="doc-string">\\.tmpl\\'</span>" 'html-js)

<span class="comment">;; Use different colors for different sub-modes.
</span>(setq mmm-submode-decoration-level 2)
<span class="comment">;; Make the code submode a little more readable.
</span>(set-face-background 'mmm-code-submode-face "<span class="doc-string">#EEEEFF</span>")
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chickenwingsw.com/scratches/python/how-i-edit-django-templates/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
