forked from vim-scripts/smarty.vim
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsmarty.vim
68 lines (55 loc) · 1.75 KB
/
smarty.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
" Inspired by: http://github.com/kchmck/vim-coffee-script
if exists('b:did_indent')
finish
endif
if !exists('g:smarty_indent_verbose')
let g:smarty_indent_verbose = 0
endif
let s:indentexprs = {}
" NOTE: Javascript does not use indentexpr, but gets handled by html.vim.
" CoffeeScript injects itself via after/indent/html.vim.
let s:pairs = {
\ 'php': ['{php[^>]*}', '', '{/php}', 'bWn'],
\ }
for ft in keys(s:pairs)
silent! unlet b:did_indent
exec 'runtime indent/'.ft.'.vim'
let s:indentexprs[ft] = &l:indentexpr
endfor
" Load html last so it can overwrite other settings.
silent! unlet b:did_indent
runtime indent/html.vim
let s:indentexprs['html'] = &l:indentexpr
let b:did_indent = 1
" Inject our wrapper indent function.
setlocal indentexpr=GetSmartyHtmlIndent(v:lnum)
function! s:handle(lnum, ft, searchpairargs)
" See if we're inside a subblock.
let save_cursor = getcurpos()
exec a:lnum
let scriptlnum = call('searchpair', a:searchpairargs)
let prevlnum = prevnonblank(a:lnum)
call setpos('.', save_cursor)
" If we're in a subblock and the previous line isn't the starting tag
" itself, use its indenting.
if scriptlnum && scriptlnum != prevlnum
exec 'return ' s:indentexprs[a:ft]
endif
return ""
endfun
function! GetSmartyHtmlIndent(lnum)
for [ft, args] in items(s:pairs)
let r = call('s:handle', [a:lnum, ft, args])
if type(r) == type(0)
if g:smarty_indent_verbose
echom "Line ".a:lnum.": using ".ft." indenting via ".s:indentexprs[ft].": ".r."."
endif
return r
endif
endfor
" Fallback to HTML.
if g:smarty_indent_verbose
echom "Line ".a:lnum.": using HTML indenting via ".s:indentexprs['html']."."
endif
exec 'return ' s:indentexprs['html']
endfunction