Skip to content
Myr

Automated merge with ssh://team@pocoo.org/jinja2-main

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parents 5dfbfc1, e709abe · Browse files · 1 file+212 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+212 added−0 removed

  • other:+212 added−0 removed

1 file+212 added−0 removed

added:ext/jinja.el+212 added
1;;; jinja.el --- Jinja mode highlighting2;;3;; Author: Georg Brandl4;; Last modified: 2008-05-22 23:04 by gbr5;;6;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;7;;8;;; Commentary:9;;10;; Mostly ripped off django-mode by Lennart Borgman.11;;12;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;13;;14;; This program is free software; you can redistribute it and/or15;; modify it under the terms of the GNU General Public License as16;; published by the Free Software Foundation; either version 2, or17;; (at your option) any later version.18;;19;; This program is distributed in the hope that it will be useful,20;; but WITHOUT ANY WARRANTY; without even the implied warranty of21;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU22;; General Public License for more details.23;;24;; You should have received a copy of the GNU General Public License25;; along with this program; see the file COPYING. If not, write to26;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth27;; Floor, Boston, MA 02110-1301, USA.28;;29;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;30;;31;;; Code:3233(defconst jinja-font-lock-keywords34 (list35; (cons (rx "{% comment %}" (submatch (0+ anything))36; "{% endcomment %}") (list 1 font-lock-comment-face))37 '("{# ?\\(.*?\\) ?#}" . (1 font-lock-comment-face))38 '("{%-?\\|-?%}\\|{{\\|}}" . font-lock-preprocessor-face)39 '("{#\\|#}" . font-lock-comment-delimiter-face)40 ;; first word in a block is a command41 '("{%-?[ \t\n]*\\([a-zA-Z_]+\\)" . (1 font-lock-keyword-face))42 ;; variables43 '("\\({{ ?\\)\\([^|]*?\\)\\(|.*?\\)? ?}}" . (1 font-lock-variable-name-face))44 ;; keywords and builtins45 (cons (rx word-start46 (or "in" "as" "reversed" "recursive" "not" "and" "or"47 "if" "else" "import" "with" "without" "context")48 word-end)49 font-lock-keyword-face)50 (cons (rx word-start51 (or "true" "false" "null" "loop" "block" "super" "forloop")52 word-end)53 font-lock-builtin-face)54 ;; tests55 '("\\(is\\)[ \t]*\\(not\\)[ \t]*\\([a-zA-Z_]+\\)"56 (1 font-lock-keyword-face) (2 font-lock-keyword-face)57 (3 font-lock-function-name-face))58 ;; builtin filters59 (cons (rx60 "|" (* space)61 (submatch62 (or "abs" "batch" "capitalize" "capture" "center" "count" "default"63 "dformat" "dictsort" "e" "escape" "filesizeformat" "first"64 "float" "format" "getattribute" "getitem" "groupby" "indent"65 "int" "join" "jsonencode" "last" "length" "lower" "markdown"66 "pprint" "random" "replace" "reverse" "round" "rst" "slice"67 "sort" "string" "striptags" "sum" "textile" "title" "trim"68 "truncate" "upper" "urlencode" "urlize" "wordcount" "wordwrap"69 "xmlattr")))70 (list 1 font-lock-builtin-face))71 )72 "Minimal highlighting expressions for Jinja mode")7374(define-derived-mode jinja-mode nil "Jinja"75 "Simple Jinja mode for use with `mumamo-mode'.76This mode only provides syntax highlighting."77 ;;(set (make-local-variable 'comment-start) "{#")78 ;;(set (make-local-variable 'comment-end) "#}")79 (setq font-lock-defaults '(jinja-font-lock-keywords)))8081;; mumamo stuff8283(when (require 'mumamo nil t)8485 (defun mumamo-chunk-jinja3(pos min max)86 "Find {# ... #}. Return range and `jinja-mode'.87See `mumamo-find-possible-chunk' for POS, MIN and MAX."88 (mumamo-find-possible-chunk pos min max89 'mumamo-search-bw-exc-start-jinja390 'mumamo-search-bw-exc-end-jinja391 'mumamo-search-fw-exc-start-jinja392 'mumamo-search-fw-exc-end-jinja3))9394 (defun mumamo-chunk-jinja2(pos min max)95 "Find {{ ... }}. Return range and `jinja-mode'.96See `mumamo-find-possible-chunk' for POS, MIN and MAX."97 (mumamo-find-possible-chunk pos min max98 'mumamo-search-bw-exc-start-jinja299 'mumamo-search-bw-exc-end-jinja2100 'mumamo-search-fw-exc-start-jinja2101 'mumamo-search-fw-exc-end-jinja2))102103 (defun mumamo-chunk-jinja (pos min max)104 "Find {% ... %}. Return range and `jinja-mode'.105See `mumamo-find-possible-chunk' for POS, MIN and MAX."106 (mumamo-find-possible-chunk pos min max107 'mumamo-search-bw-exc-start-jinja108 'mumamo-search-bw-exc-end-jinja109 'mumamo-search-fw-exc-start-jinja110 'mumamo-search-fw-exc-end-jinja))111112 (defun mumamo-search-bw-exc-start-jinja (pos min)113 "Helper for `mumamo-chunk-jinja'.114POS is where to start search and MIN is where to stop."115 (let ((exc-start (mumamo-chunk-start-bw-str-inc pos min "{%")))116 (and exc-start117 (<= exc-start pos)118 (cons exc-start 'jinja-mode))))119120 (defun mumamo-search-bw-exc-start-jinja2(pos min)121 "Helper for `mumamo-chunk-jinja2'.122POS is where to start search and MIN is where to stop."123 (let ((exc-start (mumamo-chunk-start-bw-str-inc pos min "{{")))124 (and exc-start125 (<= exc-start pos)126 (cons exc-start 'jinja-mode))))127128 (defun mumamo-search-bw-exc-start-jinja3(pos min)129 "Helper for `mumamo-chunk-jinja3'.130POS is where to start search and MIN is where to stop."131 (let ((exc-start (mumamo-chunk-start-bw-str-inc pos min "{#")))132 (and exc-start133 (<= exc-start pos)134 (cons exc-start 'jinja-mode))))135136 (defun mumamo-search-bw-exc-end-jinja (pos min)137 "Helper for `mumamo-chunk-jinja'.138POS is where to start search and MIN is where to stop."139 (mumamo-chunk-end-bw-str-inc pos min "%}"))140141 (defun mumamo-search-bw-exc-end-jinja2(pos min)142 "Helper for `mumamo-chunk-jinja2'.143POS is where to start search and MIN is where to stop."144 (mumamo-chunk-end-bw-str-inc pos min "}}"))145146 (defun mumamo-search-bw-exc-end-jinja3(pos min)147 "Helper for `mumamo-chunk-jinja3'.148POS is where to start search and MIN is where to stop."149 (mumamo-chunk-end-bw-str-inc pos min "#}"))150151 (defun mumamo-search-fw-exc-start-jinja (pos max)152 "Helper for `mumamo-chunk-jinja'.153POS is where to start search and MAX is where to stop."154 (mumamo-chunk-start-fw-str-inc pos max "{%"))155156 (defun mumamo-search-fw-exc-start-jinja2(pos max)157 "Helper for `mumamo-chunk-jinja2'.158POS is where to start search and MAX is where to stop."159 (mumamo-chunk-start-fw-str-inc pos max "{{"))160161 (defun mumamo-search-fw-exc-start-jinja3(pos max)162 "Helper for `mumamo-chunk-jinja3'.163POS is where to start search and MAX is where to stop."164 (mumamo-chunk-start-fw-str-inc pos max "{#"))165166 (defun mumamo-search-fw-exc-end-jinja (pos max)167 "Helper for `mumamo-chunk-jinja'.168POS is where to start search and MAX is where to stop."169 (mumamo-chunk-end-fw-str-inc pos max "%}"))170171 (defun mumamo-search-fw-exc-end-jinja2(pos max)172 "Helper for `mumamo-chunk-jinja2'.173POS is where to start search and MAX is where to stop."174 (mumamo-chunk-end-fw-str-inc pos max "}}"))175176 (defun mumamo-search-fw-exc-end-jinja3(pos max)177 "Helper for `mumamo-chunk-jinja3'.178POS is where to start search and MAX is where to stop."179 (mumamo-chunk-end-fw-str-inc pos max "#}"))180181;;;###autoload182 (define-mumamo-multi-major-mode jinja-html-mumamo183 "Turn on multiple major modes for Jinja with main mode `html-mode'.184This also covers inlined style and javascript."185 ("Jinja HTML Family" html-mode186 (mumamo-chunk-jinja187 mumamo-chunk-jinja2188 mumamo-chunk-jinja3189 mumamo-chunk-inlined-style190 mumamo-chunk-inlined-script191 mumamo-chunk-style=192 mumamo-chunk-onjs=193 )))194195;;;###autoload196 (define-mumamo-multi-major-mode jinja-nxhtml-mumamo197 "Turn on multiple major modes for Jinja with main mode `nxhtml-mode'.198This also covers inlined style and javascript."199 ("Jinja nXhtml Family" nxhtml-mode200 (mumamo-chunk-jinja201 mumamo-chunk-jinja2202 mumamo-chunk-jinja3203 mumamo-chunk-inlined-style204 mumamo-chunk-inlined-script205 mumamo-chunk-style=206 mumamo-chunk-onjs=207 )))208 )209210(provide 'jinja)211;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;212;;; jinja.el ends here