From 8e2d4692b8c5688163905e18690caadfd27fdac5 Mon Sep 17 00:00:00 2001 From: Chris Hoeppler Date: Wed, 12 Oct 2022 13:17:03 +0200 Subject: [PATCH 1/4] add latex example --- examples/testing.latex.j2 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 examples/testing.latex.j2 diff --git a/examples/testing.latex.j2 b/examples/testing.latex.j2 new file mode 100644 index 0000000..00dfb92 --- /dev/null +++ b/examples/testing.latex.j2 @@ -0,0 +1,31 @@ +((* extends "base.latex" *)) + +((* include "other.latex" ignore missing without context *)) + +((* if test and ('a' ~ 'b') is not none *)) +((* macro func(arg1, arg2) *)) +((* for x in whatever *)) +((( x | fancy_filter ))) +((* set test = true *)) +((* endfor *)) +((* endmacro *)) +((* endif *)) + +((* import 'templates/something.j2' as sth *)) +((* from 'funcs.latex.j2' import func as foo, bar *)) + +((* block test *)) test ((* endblock *)) + +((* set reply | wordwrap *)) +Regarding your message: +((( message ))) +((* endset *)) + +((* block main *)) + ((* set who_is_it = 'world' *)) + hello ((( who_is_it | capitalize )))! + ((* raw -*)) + ((* set who_is_it = 'world' *)) + hello ((( who_is_it | capitalize )))! + ((* endraw *)) +((* endblock *)) From ace524cfec186c94166cb33aeeeef4167f72dadd Mon Sep 17 00:00:00 2001 From: Chris Hoeppler Date: Fri, 14 Oct 2022 21:38:37 +0200 Subject: [PATCH 2/4] add `*` and `#` to surroundingPairs add `*` and `#` to 'surroundingPairs`, so a selection can be surrounded with `((* *))` and `((# #))`. Previously the selection would be deleted as soon as `*` or `#` is typed after the two opening parentheses. --- language-configuration-latex.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/language-configuration-latex.json b/language-configuration-latex.json index 53a7b44..ba1537a 100644 --- a/language-configuration-latex.json +++ b/language-configuration-latex.json @@ -32,7 +32,9 @@ ["[", "]"], ["(", ")"], ["\"", "\""], - ["'", "'"] + ["'", "'"], + ["*", "*"], + ["#", "#"] ], "folding": { "markers": { From 0ee5d8e641125cccef8e313ed772f7a4ef3bbca3 Mon Sep 17 00:00:00 2001 From: Chris Hoeppler Date: Fri, 14 Oct 2022 21:41:35 +0200 Subject: [PATCH 3/4] update folding for jinja-latex - folding configuration in language-configuration-latex.json seems to take precedence over that in jinja-latex.tmLanguage.json --> remove from latter - add some additional keywords which can denote blocks to be folded. NB: Only enable folding for block assignments, i.e. exlude the code blocks with a "set" tag from being a folding start marker when a value is assigned to the variable within the code block. --- language-configuration-latex.json | 4 ++-- syntaxes/jinja-latex.tmLanguage.json | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/language-configuration-latex.json b/language-configuration-latex.json index ba1537a..86f3f98 100644 --- a/language-configuration-latex.json +++ b/language-configuration-latex.json @@ -38,8 +38,8 @@ ], "folding": { "markers": { - "start": "\\(\\(\\*\\s*(block|filter|for|if|macro|raw)", - "end": "\\(\\(\\*\\s*end(block|filter|for|if|macro|raw)\\s*\\*\\)\\)" + "start": "\\(\\(\\*\\s*(autoescape|block|call|filter|for|if|macro|raw|set(?!\\s+[a-zA-Z_][a-zA-Z0-9_]*\\s*=)|with)\\b", + "end": "\\(\\(\\*\\s*end(autoescape|block|call|filter|for|if|macro|raw|set|with)\\b" } } } diff --git a/syntaxes/jinja-latex.tmLanguage.json b/syntaxes/jinja-latex.tmLanguage.json index a3934f7..d0c2ece 100644 --- a/syntaxes/jinja-latex.tmLanguage.json +++ b/syntaxes/jinja-latex.tmLanguage.json @@ -3,8 +3,6 @@ "scopeName": "text.latex.jinja", "comment": "Jinja Latex Templates", "firstLineMatch": "^(\\(\\(\\* extends [\"'][^\"']+[\"'] \\*\\)\\)", - "foldingStartMarker": "(\\(\\(\\*\\s*(block|filter|for|if|macro|raw))", - "foldingStopMarker": "(\\(\\(\\*\\s*(endblock|endfilter|endfor|endif|endmacro|endraw)\\s*\\*\\)\\))", "patterns": [ { "include": "text.tex.latex" From c41fe74b2d6acbf3b2daff8b46816fb6b4f6650e Mon Sep 17 00:00:00 2001 From: Chris Hoeppler Date: Fri, 14 Oct 2022 21:44:36 +0200 Subject: [PATCH 4/4] improve jinja-latex - add some missing keywords / symbols - update scope names to improve highlighting --- syntaxes/jinja-latex.tmLanguage.json | 152 ++++++++++++++++++--------- 1 file changed, 103 insertions(+), 49 deletions(-) diff --git a/syntaxes/jinja-latex.tmLanguage.json b/syntaxes/jinja-latex.tmLanguage.json index d0c2ece..9df0611 100644 --- a/syntaxes/jinja-latex.tmLanguage.json +++ b/syntaxes/jinja-latex.tmLanguage.json @@ -8,39 +8,39 @@ "include": "text.tex.latex" }, { - "begin": "(\\(\\(\\*)\\s*(raw)\\s*(\\*\\)\\))", + "begin": "(\\(\\(\\*)\\s*(raw)\\s*(-?\\*\\)\\))", "captures": { "1": { - "name": "entity.other.jinja.delimiter.tag" + "name": "keyword.control.jinja.delimiter.statement" }, "2": { "name": "keyword.control.jinja" }, "3": { - "name": "entity.other.jinja.delimiter.tag" + "name": "keyword.control.jinja.delimiter.statement" } }, "end": "(\\(\\(\\*)\\s*(endraw)\\s*(\\*\\)\\))", - "name": "comment.block.jinja.raw" + "name": "markup.raw.jinja" }, { - "begin": "\\(\\(#-?", + "begin": "\\(\\(#[-+]?", "captures": [ { "name": "entity.other.jinja.delimiter.comment" } ], - "end": "-?#\\)\\)", + "end": "[-+]?#\\)\\)", "name": "comment.block.jinja" }, { - "begin": "\\(\\(\\(-?", + "begin": "\\(\\(\\([-+]?", "captures": [ { - "name": "variable.entity.other.jinja.delimiter" + "name": "keyword.control.jinja.delimiter.expression" } ], - "end": "-?\\)\\)\\)", + "end": "[-+]?\\)\\)\\)", "name": "variable.meta.scope.jinja", "patterns": [ { @@ -49,14 +49,14 @@ ] }, { - "begin": "\\(\\(\\*-?", + "begin": "\\(\\(\\*[-+]?", "captures": [ { - "name": "entity.other.jinja.delimiter.tag" + "name": "keyword.control.jinja.delimiter.statement" } ], - "end": "-?\\*\\)\\)", - "name": "meta.scope.jinja.tag", + "end": "[-+]?\\*\\)\\)", + "name": "meta.scope.jinja.statement", "patterns": [ { "include": "#expression" @@ -70,6 +70,7 @@ "name": "constant.character.escape.hex.jinja" }, "escaped_unicode_char": { + "match": "(\\\\U[0-9A-Fa-f]{8})|(\\\\u[0-9A-Fa-f]{4})|(\\\\N\\{[a-zA-Z ]+\\})", "captures": { "1": { "name": "constant.character.escape.unicode.16-bit-hex.jinja" @@ -80,56 +81,121 @@ "3": { "name": "constant.character.escape.unicode.name.jinja" } - }, - "match": "(\\\\U[0-9A-Fa-f]{8})|(\\\\u[0-9A-Fa-f]{4})|(\\\\N\\{[a-zA-Z ]+\\})" + } }, "expression": { "patterns": [ { + "match": "\\s*\\b(from)\\s+(([\"'])[^\"']+\\3)\\s+(import)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b", "captures": { "1": { - "name": "keyword.control.jinja" + "name": "keyword.control.import.jinja" }, "2": { - "name": "variable.other.jinja.block" + "name": "string.quoted.double.jinja" + }, + "4": { + "name": "keyword.control.import.jinja" + }, + "5": { + "name": "variable.other.jinja" } - }, - "match": "\\s*\\b(block)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b" + } }, { + "match": "\\s*\\b(import)\\s+(([\"'])[^\"']+\\3)", "captures": { "1": { - "name": "keyword.control.jinja" + "name": "keyword.control.import.jinja" }, "2": { - "name": "variable.other.jinja.filter" + "name": "string.quoted.double.jinja" } - }, - "match": "\\s*\\b(filter)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b" + } }, { + "match": "\\b(as)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b", "captures": { "1": { - "name": "keyword.control.jinja" + "name": "keyword.control.import.jinja" + }, + "2": { + "name": "variable.other.jinja" + } + } + }, + { + "match": "\\s*\\b(block)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "captures": { + "1": { + "name": "storage.type.block.jinja" }, "2": { - "name": "variable.other.jinja.test" + "name": "entity.name.block.jinja" } - }, - "match": "\\s*\\b(is)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b" + } }, { + "match": "\\s*\\b(macro)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "captures": { + "1": { + "name": "storage.type.macro.jinja" + }, + "2": { + "name": "entity.name.macro.jinja" + } + } + }, + { + "match": "\\s*\\b(set)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "captures": { + "1": { + "name": "storage.type.variable.jinja" + }, + "2": { + "name": "variable.other.jinja" + } + } + }, + { + "match": "\\b(end(block|macro|set))\\b", + "name": "storage.type.jinja" + }, + { + "match": "\\s*\\b(filter)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b", "captures": { "1": { "name": "keyword.control.jinja" + }, + "2": { + "name": "entity.name.filter.jinja" } - }, - "match": "(?<=\\(\\(\\%-|\\(\\(\\%)\\s*\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b(?!\\s*[,=])" + } }, { - "match": "\\b(and|else|if|in|import|not|or|recursive|with(out)?\\s+context)\\b", + "match": "\\b(with(out)?\\s+context|elif|else|endfilter|(end)?(autoescape|for|if|with)|extends|include|recursive|ignore missing)\\b", "name": "keyword.control.jinja" }, + { + "match": "(==|<=|=>|<|>|!=)", + "name": "keyword.operator.comparison.jinja" + }, + { + "match": "=", + "name": "keyword.operator.assignment.jinja" + }, + { + "match": "\\b(and|or|not)\\b", + "name": "keyword.operator.logical.jinja" + }, + { + "match": "(\\+|\\-|\\*\\*|\\*|//|/|%)", + "name": "keyword.operator.arithmetic.jinja" + }, + { + "match": "~|\\b(in|is)\\b", + "name": "keyword.operator.other.jinja" + }, { "match": "\\b(true|false|none)\\b", "name": "constant.language.jinja" @@ -143,30 +209,26 @@ "name": "variable.other.jinja" }, { - "match": "(\\+|\\-|\\*\\*|\\*|//|/|%)", - "name": "keyword.operator.arithmetic.jinja" - }, - { + "match": "(\\|)\\s*([a-zA-Z_][a-zA-Z0-9_]*)", "captures": { "1": { - "name": "punctuation.other.jinja" + "name": "keyword.operator.other.jinja" }, "2": { - "name": "variable.other.jinja.filter" + "name": "entity.name.filter.jinja" } - }, - "match": "(\\|)([a-zA-Z_][a-zA-Z0-9_]*)" + } }, { + "match": "(\\.)([a-zA-Z_][a-zA-Z0-9_]*)", "captures": { "1": { - "name": "punctuation.other.jinja" + "name": "keyword.operator.other.jinja" }, "2": { "name": "variable.other.jinja.attribute" } - }, - "match": "(\\.)([a-zA-Z_][a-zA-Z0-9_]*)" + } }, { "begin": "\\[", @@ -214,14 +276,6 @@ "match": "(\\.|:|\\||,)", "name": "punctuation.other.jinja" }, - { - "match": "(==|<=|=>|<|>|!=)", - "name": "keyword.operator.comparison.jinja" - }, - { - "match": "=", - "name": "keyword.operator.assignment.jinja" - }, { "begin": "\"", "beginCaptures": [