summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregory Anders <greg@gpanders.com>2024-09-17 20:12:47 +0200
committerChristian Brabandt <cb@256bit.org>2024-09-17 20:12:47 +0200
commit202c467bb37b894ada6377d3f2621c103f324757 (patch)
tree9c510de88005782ca1ad5531e857ced86092d30b
parentf21d28a5c72987d42d540290e5a77500ab1a4d7c (diff)
patch 9.1.0734: filetype: jinja files are not recognizedv9.1.0734
Problem: filetype: jinja files are not recognized Solution: detect '*.jinja' files a jinja filetype, include jinja syntax script (Gregory Anders) related: #15689 Signed-off-by: Gregory Anders <greg@gpanders.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
-rw-r--r--.github/MAINTAINERS1
-rw-r--r--runtime/filetype.vim3
-rw-r--r--runtime/syntax/jinja.vim86
-rw-r--r--src/testdir/test_filetype.vim1
-rw-r--r--src/version.c2
5 files changed, 93 insertions, 0 deletions
diff --git a/.github/MAINTAINERS b/.github/MAINTAINERS
index 02efe9301b..b63735d019 100644
--- a/.github/MAINTAINERS
+++ b/.github/MAINTAINERS
@@ -480,6 +480,7 @@ runtime/syntax/j.vim @glts
runtime/syntax/jargon.vim @h3xx
runtime/syntax/java.vim @zzzyxwvut
runtime/syntax/javascript.vim @fleiner
+runtime/syntax/jinja.vim @gpanders
runtime/syntax/jj.vim @gpanders
runtime/syntax/json.vim @vito-c
runtime/syntax/jsonc.vim @izhakjakov
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index 3441518e58..0f71bd74ae 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -1183,6 +1183,9 @@ au BufNewFile,BufRead *.clp setf jess
" Jgraph
au BufNewFile,BufRead *.jgr setf jgraph
+" Jinja
+au BufNewFile,BufRead *.jinja setf jinja
+
" Jujutsu
au BufNewFile,BufRead *.jjdescription setf jj
diff --git a/runtime/syntax/jinja.vim b/runtime/syntax/jinja.vim
new file mode 100644
index 0000000000..6000855ff7
--- /dev/null
+++ b/runtime/syntax/jinja.vim
@@ -0,0 +1,86 @@
+" Vim syntax file
+" Language: Jinja
+" Maintainer: Gregory Anders
+" Upstream: https://gitlab.com/HiPhish/jinja.vim
+
+if exists('b:current_syntax')
+ finish
+endif
+
+syntax case match
+syntax sync fromstart
+
+" Jinja template built-in tags and parameters (without filter, macro, is and raw, they
+" have special threatment)
+syn keyword jinjaStatement containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained and if else in not or recursive as import
+
+syn keyword jinjaStatement containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained is filter skipwhite nextgroup=jinjaFilter
+syn keyword jinjaStatement containedin=jinjaTagBlock contained macro skipwhite nextgroup=jinjaFunction
+syn keyword jinjaStatement containedin=jinjaTagBlock contained block skipwhite nextgroup=jinjaBlockName
+
+" Variable Names
+syn match jinjaVariable containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[a-zA-Z_][a-zA-Z0-9_]*/
+syn keyword jinjaSpecial containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained false true none False True None loop super caller varargs kwargs
+
+" Filters
+syn match jinjaOperator "|" containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained skipwhite nextgroup=jinjaFilter
+syn match jinjaFilter contained /[a-zA-Z_][a-zA-Z0-9_]*/
+syn match jinjaFunction contained /[a-zA-Z_][a-zA-Z0-9_]*/
+syn match jinjaBlockName contained /[a-zA-Z_][a-zA-Z0-9_]*/
+
+" Jinja template constants
+syn region jinjaString containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained start=/"/ skip=/\(\\\)\@<!\(\(\\\\\)\@>\)*\\"/ end=/"/
+syn region jinjaString containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained start=/'/ skip=/\(\\\)\@<!\(\(\\\\\)\@>\)*\\'/ end=/'/
+syn match jinjaNumber containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[0-9]\+\(\.[0-9]\+\)\?/
+
+" Operators
+syn match jinjaOperator containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[+\-*\/<>=!,:]/
+syn match jinjaPunctuation containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[()\[\]]/
+syn match jinjaOperator containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /\./ nextgroup=jinjaAttribute
+syn match jinjaAttribute contained /[a-zA-Z_][a-zA-Z0-9_]*/
+
+" Jinja template tag and variable blocks
+syn region jinjaNested matchgroup=jinjaOperator start="(" end=")" transparent display containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained
+syn region jinjaNested matchgroup=jinjaOperator start="\[" end="\]" transparent display containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained
+syn region jinjaNested matchgroup=jinjaOperator start="{" end="}" transparent display containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained
+syn region jinjaTagBlock matchgroup=jinjaTagDelim start=/{%-\?/ end=/-\?%}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment
+
+syn region jinjaVarBlock matchgroup=jinjaVarDelim start=/{{-\?/ end=/-\?}}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment
+
+" Jinja template 'raw' tag
+syn region jinjaRaw matchgroup=jinjaRawDelim start="{%\s*raw\s*%}" end="{%\s*endraw\s*%}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString,jinjaComment
+
+" Jinja comments
+syn region jinjaComment matchgroup=jinjaCommentDelim start="{#" end="#}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString
+
+" Block start keywords. A bit tricker. We only highlight at the start of a
+" tag block and only if the name is not followed by a comma or equals sign
+" which usually means that we have to deal with an assignment.
+syn match jinjaStatement containedin=jinjaTagBlock contained /\({%-\?\s*\)\@<=\<[a-zA-Z_][a-zA-Z0-9_]*\>\(\s*[,=]\)\@!/
+
+" and context modifiers
+syn match jinjaStatement containedin=jinjaTagBlock contained /\<with\(out\)\?\s\+context\>/
+
+hi def link jinjaPunctuation jinjaOperator
+hi def link jinjaAttribute jinjaVariable
+hi def link jinjaFunction jinjaFilter
+
+hi def link jinjaTagDelim jinjaTagBlock
+hi def link jinjaVarDelim jinjaVarBlock
+hi def link jinjaCommentDelim jinjaComment
+hi def link jinjaRawDelim jinja
+
+hi def link jinjaSpecial Special
+hi def link jinjaOperator Normal
+hi def link jinjaRaw Normal
+hi def link jinjaTagBlock PreProc
+hi def link jinjaVarBlock PreProc
+hi def link jinjaStatement Statement
+hi def link jinjaFilter Function
+hi def link jinjaBlockName Function
+hi def link jinjaVariable Identifier
+hi def link jinjaString Constant
+hi def link jinjaNumber Constant
+hi def link jinjaComment Comment
+
+let b:current_syntax = 'jinja'
diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim
index 45a5df2dc3..938eec750e 100644
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -366,6 +366,7 @@ def s:GetFilenameChecks(): dict<list<string>>
javascriptreact: ['file.jsx'],
jess: ['file.clp'],
jgraph: ['file.jgr'],
+ jinja: ['file.jinja'],
jj: ['file.jjdescription'],
jq: ['file.jq'],
jovial: ['file.jov', 'file.j73', 'file.jovial'],
diff --git a/src/version.c b/src/version.c
index f5bd1433cc..7558968a6d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 734,
+/**/
733,
/**/
732,