1
0
Fork 0
mirror of synced 2024-11-01 00:08:57 -04:00
ultimate-vim/sources_non_forked/vim-pug/indent/pug.vim

71 lines
1.7 KiB
VimL
Raw Normal View History

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