1 ;;; jinja.el --- Jinja mode highlighting
3 ;; Author: Georg Brandl
4 ;; Copyright: (c) 2009 by the Jinja Team
5 ;; Last modified: 2008-05-22 23:04 by gbr
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 ;; Mostly ripped off django-mode by Lennart Borgman.
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15 ;; This program is free software; you can redistribute it and/or
16 ;; modify it under the terms of the GNU General Public License as
17 ;; published by the Free Software Foundation; either version 2, or
18 ;; (at your option) any later version.
20 ;; This program is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with this program; see the file COPYING. If not, write to
27 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
28 ;; Floor, Boston, MA 02110-1301, USA.
30 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (defconst jinja-font-lock-keywords
36 ; (cons (rx "{% comment %}" (submatch (0+ anything))
37 ; "{% endcomment %}") (list 1 font-lock-comment-face))
38 '("{# ?\\(.*?\\) ?#}" . (1 font-lock-comment-face))
39 '("{%-?\\|-?%}\\|{{\\|}}" . font-lock-preprocessor-face)
40 '("{#\\|#}" . font-lock-comment-delimiter-face)
41 ;; first word in a block is a command
42 '("{%-?[ \t\n]*\\([a-zA-Z_]+\\)" . (1 font-lock-keyword-face))
44 '("\\({{ ?\\)\\([^|]*?\\)\\(|.*?\\)? ?}}" . (1 font-lock-variable-name-face))
45 ;; keywords and builtins
47 (or "in" "as" "recursive" "not" "and" "or" "if" "else"
48 "import" "with" "without" "context")
50 font-lock-keyword-face)
52 (or "true" "false" "none" "loop" "self" "super")
54 font-lock-builtin-face)
56 '("\\(is\\)[ \t]*\\(not\\)[ \t]*\\([a-zA-Z_]+\\)"
57 (1 font-lock-keyword-face) (2 font-lock-keyword-face)
58 (3 font-lock-function-name-face))
63 (or "abs" "batch" "capitalize" "capture" "center" "count" "default"
64 "dformat" "dictsort" "e" "escape" "filesizeformat" "first"
65 "float" "format" "getattribute" "getitem" "groupby" "indent"
66 "int" "join" "jsonencode" "last" "length" "lower" "markdown"
67 "pprint" "random" "replace" "reverse" "round" "rst" "slice"
68 "sort" "string" "striptags" "sum" "textile" "title" "trim"
69 "truncate" "upper" "urlencode" "urlize" "wordcount" "wordwrap"
71 (list 1 font-lock-builtin-face))
73 "Minimal highlighting expressions for Jinja mode")
75 (define-derived-mode jinja-mode nil "Jinja"
76 "Simple Jinja mode for use with `mumamo-mode'.
77 This mode only provides syntax highlighting."
78 ;;(set (make-local-variable 'comment-start) "{#")
79 ;;(set (make-local-variable 'comment-end) "#}")
80 (setq font-lock-defaults '(jinja-font-lock-keywords)))
83 (when (require 'mumamo nil t)
85 (defun mumamo-chunk-jinja3 (pos max)
87 (mumamo-quick-chunk-forward pos max "{#" "#}" 'borders 'jinja-mode))
89 (defun mumamo-chunk-jinja2 (pos max)
91 (mumamo-quick-chunk-forward pos max "{{" "}}" 'borders 'jinja-mode))
93 (defun mumamo-chunk-jinja (pos max)
95 (mumamo-quick-chunk-forward pos max "{%" "%}" 'borders 'jinja-mode))
98 (define-mumamo-multi-major-mode jinja-html-mumamo
99 "Turn on multiple major modes for Jinja with main mode `html-mode'.
100 This also covers inlined style and javascript."
101 ("Jinja HTML Family" html-mode
105 mumamo-chunk-inlined-style
106 mumamo-chunk-inlined-script
112 (define-mumamo-multi-major-mode jinja-nxhtml-mumamo
113 "Turn on multiple major modes for Jinja with main mode `nxhtml-mode'.
114 This also covers inlined style and javascript."
115 ("Jinja nXhtml Family" nxhtml-mode
119 mumamo-chunk-inlined-style
120 mumamo-chunk-inlined-script
127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
128 ;;; jinja.el ends here