2016-01-05 18:18:45 +00:00
|
|
|
" Vim indent file
|
2016-02-20 13:13:10 +00:00
|
|
|
" Language: Pug
|
2016-01-05 18:18:45 +00:00
|
|
|
" Maintainer: Joshua Borton
|
2016-02-20 13:13:10 +00:00
|
|
|
" Credits: Tim Pope (vim-pug)
|
2016-01-05 18:18:45 +00: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-02-20 13:13:10 +00:00
|
|
|
setlocal indentexpr=GetPugIndent()
|
2016-01-05 18:18:45 +00:00
|
|
|
setlocal indentkeys=o,O,*<Return>,},],0),!^F
|
|
|
|
|
|
|
|
" Only define the function once.
|
2016-02-20 13:13:10 +00:00
|
|
|
if exists("*GetPugIndent")
|
2016-01-05 18:18:45 +00:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
let s:attributes = '\%((.\{-\})\)'
|
|
|
|
let s:tag = '\([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'
|
|
|
|
|
2016-02-20 13:13:10 +00:00
|
|
|
if !exists('g:pug_self_closing_tags')
|
|
|
|
let g:pug_self_closing_tags = 'meta|link|img|hr|br|input'
|
2016-01-05 18:18:45 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
setlocal formatoptions+=r
|
|
|
|
setlocal comments+=n:\|
|
|
|
|
|
2016-02-20 13:13:10 +00:00
|
|
|
function! GetPugIndent()
|
2016-01-05 18:18:45 +00: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-02-20 13:13:10 +00:00
|
|
|
elseif line =~? '^\v%('.g:pug_self_closing_tags.')>'
|
2016-01-05 18:18:45 +00:00
|
|
|
return indent
|
2016-02-20 13:13:10 +00:00
|
|
|
elseif group =~? '\v^%(pugAttributesDelimiter|pugClass|pugId|htmlTagName|htmlSpecialTagName|pugFilter|pugTagBlockChar)$'
|
2016-01-05 18:18:45 +00:00
|
|
|
return increase
|
|
|
|
else
|
|
|
|
return indent
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" vim:set sw=2:
|