Add jinja support, closes #269

This commit is contained in:
Adam Stankiewicz 2019-03-04 09:52:59 +01:00
parent 92f779dc77
commit ec5884b1d0
7 changed files with 280 additions and 2 deletions

View File

@ -8,7 +8,7 @@ A collection of language packs for Vim.
> One to rule them all, one to find them, one to bring them all and in the darkness bind them. > One to rule them all, one to find them, one to bring them all and in the darkness bind them.
- It **won't affect your startup time**, as scripts are loaded only on demand\*. - It **won't affect your startup time**, as scripts are loaded only on demand\*.
- It **installs and updates 100+ times faster** than the <!--Package Count-->119<!--/Package Count--> packages it consists of. - It **installs and updates 100+ times faster** than the <!--Package Count-->120<!--/Package Count--> packages it consists of.
- Solid syntax and indentation support (other features skipped). Only the best language packs. - Solid syntax and indentation support (other features skipped). Only the best language packs.
- All unnecessary files are ignored (like enormous documentation from php support). - All unnecessary files are ignored (like enormous documentation from php support).
- No support for esoteric languages, only most popular ones (modern too, like `slim`). - No support for esoteric languages, only most popular ones (modern too, like `slim`).
@ -91,6 +91,7 @@ If you need full functionality of any plugin, please use it directly with your p
- [jasmine](https://github.com/glanotte/vim-jasmine) (syntax) - [jasmine](https://github.com/glanotte/vim-jasmine) (syntax)
- [javascript](https://github.com/pangloss/vim-javascript) (syntax, indent, compiler, ftplugin, extras) - [javascript](https://github.com/pangloss/vim-javascript) (syntax, indent, compiler, ftplugin, extras)
- [jenkins](https://github.com/martinda/Jenkinsfile-vim-syntax) (syntax, indent) - [jenkins](https://github.com/martinda/Jenkinsfile-vim-syntax) (syntax, indent)
- [jinja](https://github.com/lepture/vim-jinja) (syntax, indent)
- [json5](https://github.com/GutenYe/json5.vim) (syntax) - [json5](https://github.com/GutenYe/json5.vim) (syntax)
- [json](https://github.com/elzr/vim-json) (syntax, indent, ftplugin) - [json](https://github.com/elzr/vim-json) (syntax, indent, ftplugin)
- [jst](https://github.com/briancollins/vim-jst) (syntax, indent) - [jst](https://github.com/briancollins/vim-jst) (syntax, indent)

3
build
View File

@ -63,7 +63,7 @@ extract() {
output "${subdirs##, })"$'\n' output "${subdirs##, })"$'\n'
if (echo "julia coffee-script elixir fish git plantuml scala swift" | grep -qF "$name"); then if (echo "julia coffee-script elixir fish git plantuml scala swift jinja" | grep -qF "$name"); then
echo "Skipping ftdetect installation of $name" >&2 echo "Skipping ftdetect installation of $name" >&2
continue continue
fi fi
@ -199,6 +199,7 @@ PACKS="
jasmine:glanotte/vim-jasmine jasmine:glanotte/vim-jasmine
javascript:pangloss/vim-javascript:_JAVASCRIPT javascript:pangloss/vim-javascript:_JAVASCRIPT
jenkins:martinda/Jenkinsfile-vim-syntax jenkins:martinda/Jenkinsfile-vim-syntax
jinja:lepture/vim-jinja
json5:GutenYe/json5.vim json5:GutenYe/json5.vim
json:elzr/vim-json json:elzr/vim-json
jst:briancollins/vim-jst jst:briancollins/vim-jst

View File

@ -67,6 +67,10 @@ augroup filetypedetect
" swift " swift
autocmd BufNewFile,BufRead *.swift set filetype=swift autocmd BufNewFile,BufRead *.swift set filetype=swift
"jinja
autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja
augroup END augroup END
" Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954 " Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954

View File

@ -67,6 +67,10 @@ augroup filetypedetect
" swift " swift
autocmd BufNewFile,BufRead *.swift set filetype=swift autocmd BufNewFile,BufRead *.swift set filetype=swift
"jinja
autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja
augroup END augroup END
" Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954 " Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954

84
indent/jinja.vim Normal file
View File

@ -0,0 +1,84 @@
if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'jinja') != -1
finish
endif
" Vim indent file
" Language: Jinja HTML template
" Maintainer: Evan Hammer <evan@evanhammer.com>
" Last Change: 2013 Jan 26
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
" Use HTML formatting rules.
setl indentkeys=o,O,<Return>,<>>,!^F
runtime! indent/html.vim +setl nosmartindent
let b:did_indent = 1
" Indent within the jinja tags
" Made by Steve Losh <steve@stevelosh.com>
if &l:indentexpr == ''
if &l:cindent
let &l:indentexpr = 'cindent(v:lnum)'
else
let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'
endif
endif
let b:html_indentexpr = &l:indentexpr
let b:did_indent = 1
setlocal indentexpr=GetDjangoIndent()
setlocal indentkeys=o,O,*<Return>,{,},o,O,!^F,<>>
" Only define the function once.
if exists("*GetDjangoIndent")
finish
endif
function! GetDjangoIndent(...)
if a:0 && a:1 == '.'
let v:lnum = line('.')
elseif a:0 && a:1 =~ '^\d'
let v:lnum = a:1
endif
let vcol = col('.')
call cursor(v:lnum,vcol)
exe "let ind = ".b:html_indentexpr
let lnum = prevnonblank(v:lnum-1)
let pnb = getline(lnum)
let cur = getline(v:lnum)
let tagstart = '.*' . '{%\s*'
let tagend = '.*%}' . '.*'
let blocktags = '\(block\|for\|if\|with\|autoescape\|comment\|filter\|spaceless\)'
let midtags = '\(empty\|else\|elif\)'
let pnb_blockstart = pnb =~# tagstart . blocktags . tagend
let pnb_blockend = pnb =~# tagstart . 'end' . blocktags . tagend
let pnb_blockmid = pnb =~# tagstart . midtags . tagend
let cur_blockstart = cur =~# tagstart . blocktags . tagend
let cur_blockend = cur =~# tagstart . 'end' . blocktags . tagend
let cur_blockmid = cur =~# tagstart . midtags . tagend
if pnb_blockstart && !pnb_blockend
let ind = ind + &sw
elseif pnb_blockmid && !pnb_blockend
let ind = ind + &sw
endif
if cur_blockend && !cur_blockstart
let ind = ind - &sw
elseif cur_blockmid
let ind = ind - &sw
endif
return ind
endfunction

View File

@ -192,3 +192,97 @@ syn keyword htmlArg contained scriptlevel scriptminsize scriptsize scriptsizemul
syn keyword htmlArg contained stretchy subscriptshift superscriptshift symmetric thickmathspace thinmathspace type valign verythickmathspace verythinmathspace syn keyword htmlArg contained stretchy subscriptshift superscriptshift symmetric thickmathspace thinmathspace type valign verythickmathspace verythinmathspace
syn keyword htmlArg contained veryverythickmathspace veryverythinmathspace voffset width xref syn keyword htmlArg contained veryverythickmathspace veryverythinmathspace voffset width xref
if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'jinja') != -1
finish
endif
" Vim syntax file
" Language: HTML (version 5)
" Maintainer: Rodrigo Machado <rcmachado@gmail.com>
" URL: http://rm.blog.br/vim/syntax/html.vim
" Last Change: 2009 Aug 19
" License: Public domain
" (but let me know if you like :) )
"
" Note: This file just adds the new tags from HTML 5
" and don't replace default html.vim syntax file
"
" Modified: othree <othree@gmail.com>
" Changes: update to Draft 28 August 2010
" add complete new attributes
" add wai-aria attributes
" add microdata attributes
" add rdfa attributes
syn keyword htmlTagName contained script
" HTML 5 tags
syn keyword htmlTagName contained article aside audio canvas command
syn keyword htmlTagName contained datalist details dialog embed figcaption figure footer
syn keyword htmlTagName contained header hgroup keygen mark meter menu nav output
syn keyword htmlTagName contained progress time ruby rt rp section source summary time track video wbr
" HTML 5 arguments
" Core Attributes
syn keyword htmlArg contained accesskey class contenteditable contextmenu dir
syn keyword htmlArg contained draggable hidden id lang spellcheck style tabindex title
" Event-handler Attributes
syn keyword htmlArg contained onabort onblur oncanplay oncanplaythrough onchange
syn keyword htmlArg contained onclick oncontextmenu ondblclick ondrag ondragend ondragenter ondragleave ondragover
syn keyword htmlArg contained ondragstart ondrop ondurationchange onemptied onended onerror onfocus onformchange
syn keyword htmlArg contained onforminput oninput oninvalid onkeydown onkeypress onkeyup onload onloadeddata
syn keyword htmlArg contained onloadedmetadata onloadstart onmousedown onmousemove onmouseout onmouseover onmouseup
syn keyword htmlArg contained onmousewheel onpause onplay onplaying onprogress onratechange onreadystatechange
syn keyword htmlArg contained onscroll onseeked onseeking onselect onshow onstalled onsubmit onsuspend ontimeupdate
syn keyword htmlArg contained onvolumechange onwaiting
" XML Attributes
syn keyword htmlArg contained xml:lang xml:space xml:base
" new features
" <body>
syn keyword htmlArg contained onafterprint onbeforeprint onbeforeunload onblur onerror onfocus onhashchange onload
syn keyword htmlArg contained onmessage onoffline ononline onpopstate onredo onresize onstorage onundo onunload
" <video>, <audio>, <source>, <track>
syn keyword htmlArg contained autoplay preload controls loop poster media kind charset srclang track
" <form>, <input>, <button>
syn keyword htmlArg contained form autocomplete autofocus list min max step
syn keyword htmlArg contained formaction autofocus formenctype formmethod formtarget formnovalidate
" <command>, <details>, <time>
syn keyword htmlArg contained label icon open datetime pubdate
" Custom Data Attributes
" http://dev.w3.org/html5/spec/Overview.html#custom-data-attribute
syn match htmlArg "\<\(data(\-[a-z]\+)\+\)=" contained
" Microdata
" http://dev.w3.org/html5/md/
syn keyword htmlArg contained item itemid itemscope itemtype itemprop
" RDFa
" http://www.w3.org/TR/rdfa-syntax/#a_xhtmlrdfa_dtd
syn keyword htmlArg contained about typeof property resource content datatype rel rev
" WAI-ARIA States and Properties
" http://www.w3.org/TR/wai-aria/states_and_properties
syn keyword htmlArg contained role
" Global States and Properties
syn match htmlArg contained "\<aria-\(atomic\|busy\|controls\|describedby\)\>"
syn match htmlArg contained "\<aria-\(disabled\|dropeffect\|flowto\|grabbed\)\>"
syn match htmlArg contained "\<aria-\(haspopup\|hidden\|invalid\|label\)\>"
syn match htmlArg contained "\<aria-\(labelledby\|live\|owns\|relevant\)\>"
" Widget Attributes
syn match htmlArg contained "\<aria-\(autocomplete\|checked\|disabled\|expanded\)\>"
syn match htmlArg contained "\<aria-\(haspopup\|hidden\|invalid\|label\)\>"
syn match htmlArg contained "\<aria-\(level\|multiline\|multiselectable\|orientation\)\>"
syn match htmlArg contained "\<aria-\(pressed\|readonly\|required\|selected\)\>"
syn match htmlArg contained "\<aria-\(sort\|valuemax\|valuemin\|valuenow\|valuetext\|\)\>"
" Live Region Attributes
syn match htmlArg contained "\<aria-\(atomic\|busy\|live\|relevant\|\)\>"
" Drag-and-Drop attributes
syn match htmlArg contained "\<aria-\(dropeffect\|grabbed\)\>"
" Relationship Attributes
syn match htmlArg contained "\<aria-\(activedescendant\|controls\|describedby\|flowto\|\)\>"
syn match htmlArg contained "\<aria-\(labelledby\|owns\|posinset\|setsize\|\)\>"

90
syntax/jinja.vim Normal file
View File

@ -0,0 +1,90 @@
if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'jinja') != -1
finish
endif
" jinja syntax file
" Language: Jinja HTML template
" Maintainer: Hsiaoming Yang <lepture@me.com>
" Last Change: Sep 13, 2012
" only support 6.x+
if exists("b:current_syntax")
finish
endif
if !exists("main_syntax")
let main_syntax = 'html'
endif
runtime! syntax/html.vim
unlet b:current_syntax
syntax case match
" jinja template built-in tags and parameters
" 'comment' doesn't appear here because it gets special treatment
syn keyword jinjaStatement contained if else elif endif is not
syn keyword jinjaStatement contained for in recursive endfor
syn keyword jinjaStatement contained raw endraw
syn keyword jinjaStatement contained block endblock extends super scoped
syn keyword jinjaStatement contained macro endmacro call endcall
syn keyword jinjaStatement contained from import as do continue break
syn keyword jinjaStatement contained filter endfilter set
syn keyword jinjaStatement contained include ignore missing
syn keyword jinjaStatement contained with without context endwith
syn keyword jinjaStatement contained trans endtrans pluralize
syn keyword jinjaStatement contained autoescape endautoescape
" jinja templete built-in filters
syn keyword jinjaFilter contained abs attr batch capitalize center default
syn keyword jinjaFilter contained dictsort escape filesizeformat first
syn keyword jinjaFilter contained float forceescape format groupby indent
syn keyword jinjaFilter contained int join last length list lower pprint
syn keyword jinjaFilter contained random replace reverse round safe slice
syn keyword jinjaFilter contained sort string striptags sum
syn keyword jinjaFilter contained title trim truncate upper urlize
syn keyword jinjaFilter contained wordcount wordwrap
" jinja template built-in tests
syn keyword jinjaTest contained callable defined divisibleby escaped
syn keyword jinjaTest contained even iterable lower mapping none number
syn keyword jinjaTest contained odd sameas sequence string undefined upper
syn keyword jinjaFunction contained range lipsum dict cycler joiner
" Keywords to highlight within comments
syn keyword jinjaTodo contained TODO FIXME XXX
" jinja template constants (always surrounded by double quotes)
syn region jinjaArgument contained start=/"/ skip=/\\"/ end=/"/
syn region jinjaArgument contained start=/'/ skip=/\\'/ end=/'/
syn keyword jinjaArgument contained true false
" Mark illegal characters within tag and variables blocks
syn match jinjaTagError contained "#}\|{{\|[^%]}}\|[&#]"
syn match jinjaVarError contained "#}\|{%\|%}\|[<>!&#%]"
syn cluster jinjaBlocks add=jinjaTagBlock,jinjaVarBlock,jinjaComBlock,jinjaComment
" jinja template tag and variable blocks
syn region jinjaTagBlock start="{%" end="%}" contains=jinjaStatement,jinjaFilter,jinjaArgument,jinjaFilter,jinjaTest,jinjaTagError display containedin=ALLBUT,@jinjaBlocks
syn region jinjaVarBlock start="{{" end="}}" contains=jinjaFilter,jinjaArgument,jinjaVarError display containedin=ALLBUT,@jinjaBlocks
syn region jinjaComBlock start="{#" end="#}" contains=jinjaTodo containedin=ALLBUT,@jinjaBlocks
hi def link jinjaTagBlock PreProc
hi def link jinjaVarBlock PreProc
hi def link jinjaStatement Statement
hi def link jinjaFunction Function
hi def link jinjaTest Type
hi def link jinjaFilter Identifier
hi def link jinjaArgument Constant
hi def link jinjaTagError Error
hi def link jinjaVarError Error
hi def link jinjaError Error
hi def link jinjaComment Comment
hi def link jinjaComBlock Comment
hi def link jinjaTodo Todo
let b:current_syntax = "jinja"