2016-05-02 05:52:54 -04:00
|
|
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'pug') == -1
|
2015-07-18 17:05:45 -04:00
|
|
|
|
2013-09-14 05:38:54 -04:00
|
|
|
" Vim indent file
|
2016-05-02 04:42:37 -04:00
|
|
|
" Language: Pug
|
2013-09-14 05:38:54 -04:00
|
|
|
" Maintainer: Joshua Borton
|
2016-05-02 04:42:37 -04:00
|
|
|
" Credits: Tim Pope (vim-pug)
|
2013-09-14 05:38:54 -04:00
|
|
|
" Last Change: 2010 Sep 22
|
|
|
|
|
|
|
|
if exists("b:did_indent")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
unlet! b:did_indent
|
|
|
|
let b:did_indent = 1
|
|
|
|
|
|
|
|
setlocal autoindent
|
2016-05-02 04:42:37 -04:00
|
|
|
setlocal indentexpr=GetPugIndent()
|
2013-09-14 05:38:54 -04:00
|
|
|
setlocal indentkeys=o,O,*<Return>,},],0),!^F
|
|
|
|
|
|
|
|
" Only define the function once.
|
2016-05-02 04:42:37 -04:00
|
|
|
if exists("*GetPugIndent")
|
2013-09-14 05:38:54 -04:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
let s:attributes = '\%((.\{-\})\)'
|
|
|
|
let s:tag = '\([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'
|
|
|
|
|
2016-05-02 04:42:37 -04:00
|
|
|
if !exists('g:pug_self_closing_tags')
|
|
|
|
let g:pug_self_closing_tags = 'meta|link|img|hr|br|input'
|
2013-09-14 05:38:54 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
setlocal formatoptions+=r
|
|
|
|
setlocal comments+=n:\|
|
|
|
|
|
2016-05-02 04:42:37 -04:00
|
|
|
function! GetPugIndent()
|
2013-09-14 05:38:54 -04:00
|
|
|
let lnum = prevnonblank(v:lnum-1)
|
|
|
|
if lnum == 0
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
let line = substitute(getline(lnum),'\s\+$','','')
|
|
|
|
let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','')
|
|
|
|
let lastcol = strlen(line)
|
|
|
|
let line = substitute(line,'^\s\+','','')
|
|
|
|
let indent = indent(lnum)
|
|
|
|
let cindent = indent(v:lnum)
|
|
|
|
let increase = indent + &sw
|
|
|
|
if indent == indent(lnum)
|
|
|
|
let indent = cindent <= indent ? -1 : increase
|
|
|
|
endif
|
|
|
|
|
|
|
|
let group = synIDattr(synID(lnum,lastcol,1),'name')
|
|
|
|
|
|
|
|
if line =~ '^!!!'
|
|
|
|
return indent
|
|
|
|
elseif line =~ '^/\%(\[[^]]*\]\)\=$'
|
|
|
|
return increase
|
|
|
|
elseif line =~ '^\%(if\|else\|unless\|for\|each\|block\|mixin\|append\|case\|when\)'
|
|
|
|
return increase
|
|
|
|
elseif line =~ '^'.s:tag.'[&!]\=[=~-].*,\s*$'
|
|
|
|
return increase
|
|
|
|
elseif line == '-#'
|
|
|
|
return increase
|
2016-05-02 04:42:37 -04:00
|
|
|
elseif line =~? '^\v%('.g:pug_self_closing_tags.')>'
|
2013-09-14 05:38:54 -04:00
|
|
|
return indent
|
2016-05-02 04:42:37 -04:00
|
|
|
elseif group =~? '\v^%(pugAttributesDelimiter|pugClass|pugId|htmlTagName|htmlSpecialTagName|pugFilter|pugTagBlockChar)$'
|
2013-09-14 05:38:54 -04:00
|
|
|
return increase
|
|
|
|
else
|
|
|
|
return indent
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" vim:set sw=2:
|
2015-07-18 17:05:45 -04:00
|
|
|
|
|
|
|
endif
|