mirror of
https://github.com/amix/vimrc
synced 2025-07-18 17:44:59 +08:00
merge
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
" - general line splits (line ends in an operator)
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
@ -24,6 +24,17 @@ if exists("*GoIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
" use shiftwidth function only if it's available
|
||||
if exists('*shiftwidth')
|
||||
func s:sw()
|
||||
return shiftwidth()
|
||||
endfunc
|
||||
else
|
||||
func s:sw()
|
||||
return &sw
|
||||
endfunc
|
||||
endif
|
||||
|
||||
function! GoIndent(lnum)
|
||||
let prevlnum = prevnonblank(a:lnum-1)
|
||||
if prevlnum == 0
|
||||
@ -40,17 +51,17 @@ function! GoIndent(lnum)
|
||||
|
||||
if prevl =~ '[({]\s*$'
|
||||
" previous line opened a block
|
||||
let ind += &sw
|
||||
let ind += s:sw()
|
||||
endif
|
||||
if prevl =~# '^\s*\(case .*\|default\):$'
|
||||
" previous line is part of a switch statement
|
||||
let ind += &sw
|
||||
let ind += s:sw()
|
||||
endif
|
||||
" TODO: handle if the previous line is a label.
|
||||
|
||||
if thisl =~ '^\s*[)}]'
|
||||
" this line closed a block
|
||||
let ind -= &sw
|
||||
let ind -= s:sw()
|
||||
endif
|
||||
|
||||
" Colons are tricky.
|
||||
@ -58,8 +69,10 @@ function! GoIndent(lnum)
|
||||
" We ignore trying to deal with jump labels because (a) they're rare, and
|
||||
" (b) they're hard to disambiguate from a composite literal key.
|
||||
if thisl =~# '^\s*\(case .*\|default\):$'
|
||||
let ind -= &sw
|
||||
let ind -= s:sw()
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
" vim: sw=2 ts=2 et
|
||||
|
46
sources_non_forked/vim-go/indent/gohtmltmpl.vim
Normal file
46
sources_non_forked/vim-go/indent/gohtmltmpl.vim
Normal file
@ -0,0 +1,46 @@
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime! indent/html.vim
|
||||
|
||||
" Indent Golang HTML templates
|
||||
setlocal indentexpr=GetGoHTMLTmplIndent(v:lnum)
|
||||
setlocal indentkeys+==else,=end
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetGoHTMLTmplIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
function! GetGoHTMLTmplIndent(lnum)
|
||||
" Get HTML indent
|
||||
if exists('*HtmlIndent')
|
||||
let ind = HtmlIndent()
|
||||
else
|
||||
let ind = HtmlIndentGet(a:lnum)
|
||||
endif
|
||||
|
||||
" The value of a single shift-width
|
||||
if exists('*shiftwidth')
|
||||
let sw = shiftwidth()
|
||||
else
|
||||
let sw = &sw
|
||||
endif
|
||||
|
||||
" If need to indent based on last line
|
||||
let last_line = getline(a:lnum-1)
|
||||
if last_line =~ '^\s*{{-\=\s*\%(if\|else\|range\|with\|define\|block\).*}}'
|
||||
let ind += sw
|
||||
endif
|
||||
|
||||
" End of FuncMap block
|
||||
let current_line = getline(a:lnum)
|
||||
if current_line =~ '^\s*{{-\=\s*\%(else\|end\).*}}'
|
||||
let ind -= sw
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
" vim: sw=2 ts=2 et
|
Reference in New Issue
Block a user