aboutsummaryrefslogtreecommitdiff
path: root/dotfiles
diff options
context:
space:
mode:
authorYaroslav <contact@yaroslavps.com>2020-03-28 00:57:27 +0300
committerYaroslav <contact@yaroslavps.com>2020-03-28 00:57:27 +0300
commit9a3aa7b20a67c1b7991da1da9508ad5f78f76352 (patch)
treee3e797dd0d0f3fefe86b25c80177a0cbcc3b98af /dotfiles
parent2a934f9718516762085b010112850aa2208570cb (diff)
downloadvimrice-9a3aa7b20a67c1b7991da1da9508ad5f78f76352.tar.gz
vimrice-9a3aa7b20a67c1b7991da1da9508ad5f78f76352.zip
proper jinja indentation and file detection
Diffstat (limited to 'dotfiles')
-rw-r--r--dotfiles/.vim/ftdetect/jinja.vim14
-rw-r--r--dotfiles/.vim/indent/jinja.vim80
-rw-r--r--dotfiles/.vim/syntax/html.vim90
-rw-r--r--dotfiles/.vim/syntax/jinja.vim86
4 files changed, 270 insertions, 0 deletions
diff --git a/dotfiles/.vim/ftdetect/jinja.vim b/dotfiles/.vim/ftdetect/jinja.vim
new file mode 100644
index 0000000..d700140
--- /dev/null
+++ b/dotfiles/.vim/ftdetect/jinja.vim
@@ -0,0 +1,14 @@
+" Figure out which type of hilighting to use for html.
+fun! s:SelectHTML()
+ let n = 1
+ while n < 50 && n <= line("$")
+ " check for jinja
+ if getline(n) =~ '{{.*}}\|{%-\?\s*\(end.*\|extends\|block\|macro\|set\|if\|for\|include\|trans\)\>'
+ set ft=jinja.html
+ return
+ endif
+ let n = n + 1
+ endwhile
+endfun
+autocmd BufNewFile,BufRead *.html,*.htm call s:SelectHTML()
+autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja
diff --git a/dotfiles/.vim/indent/jinja.vim b/dotfiles/.vim/indent/jinja.vim
new file mode 100644
index 0000000..25e8f66
--- /dev/null
+++ b/dotfiles/.vim/indent/jinja.vim
@@ -0,0 +1,80 @@
+" 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
diff --git a/dotfiles/.vim/syntax/html.vim b/dotfiles/.vim/syntax/html.vim
new file mode 100644
index 0000000..9e1111b
--- /dev/null
+++ b/dotfiles/.vim/syntax/html.vim
@@ -0,0 +1,90 @@
+" 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\|\)\>"
diff --git a/dotfiles/.vim/syntax/jinja.vim b/dotfiles/.vim/syntax/jinja.vim
new file mode 100644
index 0000000..829cdc6
--- /dev/null
+++ b/dotfiles/.vim/syntax/jinja.vim
@@ -0,0 +1,86 @@
+" 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"