root/hacks/trunk/django-mode.el

Revision 107, 1.8 kB (checked in by verbosus, 9 months ago)

django-mode.el: Added Patrick Quinn's patch for enabling HTML font-lock in django mode

Line 
1; A (rather minimal) major mode for Emacs to edit Django templates
2; by Antonio Cavedoni <http://cavedoni.com/>
3;
4; Hacked together following instructions from the awesome:
5; http://two-wugs.net/emacs/mode-tutorial.html
6;
7; Acknowledgements:
8;
9;   - Patrick Quinn <http://www.patrickquinn.net/>
10;     for the font-locking patch for HTML syntax
11;
12
13(defvar django-mode-hook nil)
14
15(defvar django-mode-map
16  (let ((django-mode-map (make-keymap)))
17    (define-key django-mode-map "\C-j" 'newline-and-indent)
18    django-mode-map)
19  "Keymap for Django major mode")
20
21(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . django-mode))
22
23(defconst django-font-lock-keywords-1
24  (list
25   '("{% ?comment ?%}\\(\n?.*?\\)+?{% ?endcomment ?%}" . font-lock-comment-face)
26   '("{% ?\\(\\(end\\)?\\(extends\\|for\\|cycle\\|filter\\|firstof\\|debug\\|if\\|ifchanged\\|ifequal\\|ifnotequal\\|include\\|load\\|now\\|regroup\\|spaceless\\|ssi\\|templatetag\\|widthratio\\|block\\)\\) ?.*? ?%}" . 1)
27   '("{{ ?\\(.*?\\) ?}}" . (1 font-lock-variable-name-face))
28   '("{%\\|\\%}\\|{{\\|}}" . font-lock-builtin-face)
29   "Minimal highlighting expressions for Django mode"))
30
31(defvar django-font-lock-keywords
32  (append html-font-lock-keywords django-font-lock-keywords-1)
33  "Default highlighting expressions for Django mode")
34
35(defvar django-mode-syntax-table
36  (let ((django-mode-syntax-table (make-syntax-table)))
37    django-mode-syntax-table)
38  "Syntax table for django-mode")
39
40(defun django-mode ()
41  "Major mode for editing Django templates"
42  (interactive)
43  (kill-all-local-variables)
44  (set-syntax-table django-mode-syntax-table)
45  (use-local-map django-mode-map)
46  (html-mode)
47  (set (make-local-variable 'font-lock-defaults) '(django-font-lock-keywords))
48  (setq major-mode 'django-mode)
49  (setq mode-name "Django")
50  (run-hooks 'django-mode-hook))
51
52(provide 'django-mode)
Note: See TracBrowser for help on using the browser.