3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: Sun Nov 18 18:29:41 2007
6 ;; Last-Updated: 2008-08-08T13:22:19+0200 Fri
11 ;; Features that might be required by this library:
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 ;; Simple highlighting for Django for use with mumamo.
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;; This program is free software; you can redistribute it and/or
29 ;; modify it under the terms of the GNU General Public License as
30 ;; published by the Free Software Foundation; either version 2, or
31 ;; (at your option) any later version.
33 ;; This program is distributed in the hope that it will be useful,
34 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
35 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36 ;; General Public License for more details.
38 ;; You should have received a copy of the GNU General Public License
39 ;; along with this program; see the file COPYING. If not, write to
40 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
41 ;; Floor, Boston, MA 02110-1301, USA.
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
47 ;; Maybe there are something to get here?
48 ;; http://github.com/cosmin/emacs-utils/tree/85cc1d2bd447cb9b2fc98e27b5f8780453e5b978/django-html-mode.el
50 (defconst django-indenting-keywords
51 '("block" "comment" "else"
52 "filter" "for" "if" "ifchanged" "ifequal"
53 "ifnotequal" "spaceless" "with"))
55 ;; (append '(or) django-indenting-keywords)
56 (defconst django-font-lock-keywords
61 (or "as" "autoescape" "csrf_token" "cycle" "debug" "extends"
62 "firstof" "in" "include" "load" "now" "regroup" "ssi"
63 "templatetag" "url" "widthratio"
66 ;; (or "autoescape" "block" "comment" "cycle" "debug" "else"
67 ;; "extends" "filter" "firstof" "for" "if" "ifchanged" "ifequal"
68 ;; "ifnotequal" "include" "load" "now" "regroup"
69 ;; "spaceless" "ssi" "templatetag" "url" "widthratio"
71 ,(append '(or) django-indenting-keywords)
74 font-lock-keyword-face)
76 "Minimal highlighting expressions for Django mode")
78 (defcustom django-indent-width 2
79 "Indentation width for Django."
83 (defun django-indent-line ()
84 "Indent current line as Django code.
85 Indent like the examples on URL
86 `http://docs.djangoproject.com/en/1.1/ref/templates/builtins/'."
88 (let* ((indent-re (rx-to-string `(and word-start
89 ,(append '(or "else") django-indenting-keywords))))
90 (deindent-re (rx-to-string `(and word-start
94 ,(append '(or) django-indenting-keywords))))))
96 (this-indentation (current-indentation))
97 (this-line-start (progn (beginning-of-line) (point)))
98 (prev-line-start (progn (skip-chars-backward " \t\n\r\f")
100 (when (< (point) this-line-start)
102 (prev-indentation (if prev-line-start (current-indentation) 0))
103 (shift-in (if (and prev-line-start
104 (re-search-forward indent-re (point-at-eol) t))
105 django-indent-width 0))
107 (goto-char this-line-start)
108 (if (re-search-forward deindent-re (point-at-eol) t)
109 (- django-indent-width) 0)))
110 (new-indentation (max 0 (+ prev-indentation shift-in shift-out)))
112 (goto-char this-line-start)
114 ((> new-indentation this-indentation)
115 (skip-chars-forward " \t")
116 (indent-to new-indentation))
117 ((< new-indentation this-indentation)
118 (back-to-indentation)
119 (delete-region this-line-start (point))
120 (indent-to new-indentation)))
124 (define-derived-mode django-mode nil "Django"
125 "Simple Django mode for use with mumamo.
126 This mode only provides syntax highlighting."
127 (set (make-local-variable 'indent-line-function) 'django-indent-line)
128 (setq font-lock-defaults '(django-font-lock-keywords)))
131 ;; (defconst django-comment-font-lock-keywords
133 ;; (cons "\\(.*\\)" (list 1 font-lock-comment-face))
136 ;; (defvar django-comment-font-lock-defaults
137 ;; '(django-comment-font-lock-keywords t t))
139 ;; (define-derived-mode django-comment-mode nil "Django comment"
140 ;; "For django comment blocks."
141 ;; (set (make-local-variable 'font-lock-defaults) django-comment-font-lock-defaults))
145 (defconst django-variable-font-lock-keywords
151 (or "add" "addslashes" "capfirst" "center" "cut"
152 "date" "default" "default_if_none"
153 "dictsort" "dictsortreversed"
164 "linebreaks" "linebreaksbr" "linenumbers"
174 "safe" "slice" "slugify" "stringformat" "striptags"
175 "time" "timesince" "timeuntil"
176 "title" "truncatewords" "truncatewords_html"
178 "upper" "urlencode" "urlize" "urlizetrunc"
179 "wordcount" "wordwrap" "yesno")))
180 (list 1 font-lock-builtin-face))
185 (list 1 font-lock-function-name-face))
186 (cons "\\([^|]*\\)" (list 1 font-lock-variable-name-face))
189 (defvar django-variable-font-lock-defaults
190 '(django-variable-font-lock-keywords
192 ;; This still gives teh syntax symbol to |, why?
196 (define-derived-mode django-variable-mode nil "Django variable"
197 "For django comment blocks."
198 ;;(modify-syntax-entry ?| ?.)
199 (set (make-local-variable 'font-lock-defaults) django-variable-font-lock-defaults))
202 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
203 ;;; django.el ends here