annotate .elisp/django-html-mode.el @ 318:4fa9c5ee08d2

zshenv: default timezone should be America/New_York now
author Augie Fackler <raf@durin42.com>
date Thu, 04 Jul 2013 19:40:33 -0400
parents 16b57e1fc23d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
107
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 ;; This django-html-mode is mainly derived from html mode
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2 (require 'sgml-mode)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4 (defvar django-html-mode-hook nil)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6 (defvar django-html-mode-map
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7 (let ((django-html-mode-map (make-keymap)))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8 (define-key django-html-mode-map "\C-j" 'newline-and-indent)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
9 django-html-mode-map)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
10 "Keymap for Django major mode")
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
11
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
12 ;; if : if, if not, if A or B, if not A or B, if not A and B
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
13 ;; for : for a in alist reversed
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
14 ;; forloop.counter The current iteration of the loop (1-indexed)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
15 ;; forloop.counter0 The current iteration of the loop (0-indexed)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
16 ;; forloop.revcounter The number of iterations from the end of the loop (1-indexed)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
17 ;; forloop.revcounter0 The number of iterations from the end of the loop (0-indexed)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18 ;; forloop.first True if this is the first time through the loop
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 ;; forloop.last True if this is the last time through the loop
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
20 ;; forloop.parentloop For nested loops, this is the loop "above" the current one
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
22 ;; ifequal : ifequal A B
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
23 ;; comment : {% This is comment %}
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
24 ;; filter : {{ name | lower }}
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
26 ;; keyword-end : if, for, ifequal, block, ifnotequal, spaceless
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
27 ;; keyword-3 : regroup
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
28 ;; keyword-2 : for, ifequal
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
29 ;; keyword-1 : if, block, extends, include, ifchanged, load, now, ssi, withratio
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
30 ;; keyword-0 : else, spaceless
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
31
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
32 ;; start and end keyword for block/comment/variable
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
33 (defconst django-html-open-block "{%")
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
34 (defconst django-html-close-block "%}")
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
35 (defconst django-html-open-comment "{#")
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
36 (defconst django-html-close-comment "#}")
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
37 (defconst django-html-open-variable "{{")
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
38 (defconst django-html-close-variable "}}")
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
39
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
40 (defconst django-html-font-lock-keywords-1
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
41 (append
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
42 ;; html-mode keyword
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
43 sgml-font-lock-keywords-1)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
44
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
45 "First level keyword highlighting")
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
46
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
47 (defconst django-html-font-lock-keywords-2
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
48 (append
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
49 django-html-font-lock-keywords-1
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 sgml-font-lock-keywords-2))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
51
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
52 (defconst django-html-font-lock-keywords-3
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
53 (append
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
54 django-html-font-lock-keywords-1
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
55 django-html-font-lock-keywords-2
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
56
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
57 `(;; comment
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
58 (,(rx (eval django-html-open-comment)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
59 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
60 (0+ (not (any "#")))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
61 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
62 (eval django-html-close-comment))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
63 . font-lock-comment-face)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
64
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
65 ;; variable font lock
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
66 (,(rx (eval django-html-open-variable)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
67 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
68 (group (0+ (not (any "}"))))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
69 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
70 (eval django-html-close-variable))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
71 (1 font-lock-variable-name-face))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
72
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
73 ;; start, end keyword font lock
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
74 (,(rx (group (or (eval django-html-open-block)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
75 (eval django-html-close-block)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
76 (eval django-html-open-comment)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
77 (eval django-html-close-comment)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
78 (eval django-html-open-variable)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
79 (eval django-html-close-variable))))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
80 (1 font-lock-builtin-face))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
81
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
82 ;; end prefix keyword font lock
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
83 (,(rx (eval django-html-open-block)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85 (group (and "end"
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86 ;; end prefix keywords
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87 (or "if" "for" "ifequal" "block" "ifnotequal" "spaceless" "filter")))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
88 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
89 (eval django-html-close-block))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
90 (1 font-lock-keyword-face))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
91
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
92 ;; more words after keyword
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
93 (,(rx (eval django-html-open-block)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
94 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
95 (group (or "extends" "for" "cycle" "filter" "if not" "else"
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
96 "firstof" "debug" "if" "ifchanged" "ifequal" "ifnotequal"
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
97 "include" "load" "now" "regroup" "spaceless" "ssi"
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
98 "templatetag" "widthratio" "block"))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
99
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
100 ;; TODO: is there a more beautiful way?
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
101 (0+ (not (any "}")))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
102
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
103 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
104 (eval django-html-close-block))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
105 (1 font-lock-keyword-face))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
106
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
107 ;; TODO: if specific cases for supporting "or", "not", and "and"
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
108
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
109 ;; for sepcific cases for supporting in
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
110 (,(rx (eval django-html-open-block)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
111 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
112 "for"
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
113 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
114
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
115 (group (1+ (or word ?_ ?.)))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
116
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
117 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
118 (group "in")
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
119 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
120
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
121 (group (1+ (or word ?_ ?.)))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
122
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
123 (group (? (1+ space) "reverse"))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
124
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
125 (1+ space)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
126 (eval django-html-close-block))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
127 (1 font-lock-variable-name-face) (2 font-lock-keyword-face)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
128 (3 font-lock-variable-name-face) (4 font-lock-keyword-face)))))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
129
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
130 (defvar django-html-font-lock-keywords
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
131 django-html-font-lock-keywords-1)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
132
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
133 (defvar django-html-mode-syntax-table
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
134 (let ((django-html-mode-syntax-table (make-syntax-table)))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
135 django-html-mode-syntax-table)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
136 "Syntax table for django-html-mode")
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
137
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
138 ;;;###autoload
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
139 (define-derived-mode django-html-mode html-mode "django-html"
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
140 "Major mode for editing django html files(.djhtml)"
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
141 :group 'django-html
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
142
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
143 ;; it mainly from sgml-mode font lock setting
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
144 (set (make-local-variable 'font-lock-defaults)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
145 '((django-html-font-lock-keywords
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
146 django-html-font-lock-keywords-1
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
147 django-html-font-lock-keywords-2
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
148 django-html-font-lock-keywords-3)
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
149 nil t nil nil
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
150 (font-lock-syntactic-keywords
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
151 . sgml-font-lock-syntactic-keywords))))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
152
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
153 (add-to-list 'auto-mode-alist '("\\.djhtml$'" . django-html-mode))
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
154
16b57e1fc23d Add django-html-mode.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
155 (provide 'django-html-mode)