mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-08 21:54:46 +08:00
Fix various indent issues
This commit is contained in:
@@ -19,12 +19,14 @@ function! s:Init()
|
|||||||
" To adjust HTML
|
" To adjust HTML
|
||||||
let s:empty_tagname = '(area|base|br|col|embed|hr|input|img|'
|
let s:empty_tagname = '(area|base|br|col|embed|hr|input|img|'
|
||||||
\.'keygen|link|meta|param|source|track|wbr)'
|
\.'keygen|link|meta|param|source|track|wbr)'
|
||||||
let s:empty_tag = '\v\<'.s:empty_tagname.'[^/]*\>'
|
let s:empty_tag = '\v\<'.s:empty_tagname.'.*(/)@<!\>'
|
||||||
let s:empty_tag_start = '\v\<'.s:empty_tagname.'[^\>]*$'
|
let s:empty_tag_start = '\v\<'.s:empty_tagname.'[^>]*$'
|
||||||
let s:empty_tag_end = '\v^\s*[^\<\>\/]*\/?\>\s*'
|
let s:empty_tag_end = '\v^\s*[^<>/]*\/?\>\s*'
|
||||||
let s:tag_start = '\v^\s*\<\w*' " <
|
let s:tag_start = '\v^\s*\<\w*' " <
|
||||||
let s:tag_end = '\v^\s*\/?\>\s*' " />
|
let s:tag_end = '\v^\s*\/?\>\s*' " />
|
||||||
let s:full_tag_end = '\v^\s*\<\/' " </...>
|
let s:full_tag_end = '\v^\s*\<\/' " </...>
|
||||||
|
let s:ternary_q = '^\s\+?'
|
||||||
|
let s:ternary_e = '^\s\+:.*,\s*$'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:SetVueIndent()
|
function! s:SetVueIndent()
|
||||||
@@ -122,6 +124,8 @@ function! s:AdjustBlockIndent(syntax, ind)
|
|||||||
let ind = s:AdjustHTMLIndent(ind)
|
let ind = s:AdjustHTMLIndent(ind)
|
||||||
elseif syntax == 'javascript'
|
elseif syntax == 'javascript'
|
||||||
let ind = s:AdjustJavaScriptIndent(ind)
|
let ind = s:AdjustJavaScriptIndent(ind)
|
||||||
|
elseif syntax == 'css'
|
||||||
|
let ind = s:AdjustCSSIndent(ind)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ind
|
return ind
|
||||||
@@ -194,18 +198,38 @@ function! s:AdjustHTMLIndent(ind)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Indent for multiline array/object in attribute like v-*="[
|
" Multiline array/object in attribute like v-*="[
|
||||||
" ...
|
" ...
|
||||||
" ]
|
" ]
|
||||||
if prevline =~ '"[[{]\s*$'
|
if prevline =~ '[[{]\s*$'
|
||||||
call vue#LogWithLnum('previous line is an open bracket')
|
call vue#LogWithLnum('previous line is an open bracket')
|
||||||
let ind = indent(prevlnum) + &sw
|
let ind = indent(prevlnum) + &sw
|
||||||
endif
|
endif
|
||||||
if curline =~ '^\s*[]}][^"]*"\s*$'
|
if curline =~ '^\s*[]}][^"]*"\?\s*$'
|
||||||
call vue#LogWithLnum('current line is a closing bracket')
|
call vue#LogWithLnum('current line is a closing bracket')
|
||||||
let ind = indent(prevlnum) - &sw
|
let ind = indent(prevlnum) - &sw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Multiline ternary 'a ? b : c' in attribute
|
||||||
|
if curline =~ s:ternary_q
|
||||||
|
call vue#LogWithLnum('current line is ?...')
|
||||||
|
let ind = indent(prevlnum) + &sw
|
||||||
|
endif
|
||||||
|
if curline =~ s:ternary_e && prevline =~ s:ternary_q
|
||||||
|
call vue#LogWithLnum('current line is :...')
|
||||||
|
let ind = indent(prevlnum)
|
||||||
|
endif
|
||||||
|
if prevline =~ s:ternary_e
|
||||||
|
call vue#LogWithLnum('prevline line is :...')
|
||||||
|
let ind = indent(prevlnum) - &sw
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Angle bracket in attribute, like v-if="isEnabled('item.<name>')"
|
||||||
|
if prevline =~ '="[^"]*<[^"]*>[^"]*"'
|
||||||
|
call vue#LogWithLnum('prevline line is angle bracket in attribute')
|
||||||
|
let ind = ind - &sw
|
||||||
|
endif
|
||||||
|
|
||||||
return ind
|
return ind
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -220,10 +244,31 @@ function! s:AdjustJavaScriptIndent(ind)
|
|||||||
let ind = indent(prevlnum) + &sw
|
let ind = indent(prevlnum) + &sw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if prevline =~ ':.*\s=>\s.*,\s*$' && curline !~ '^\s*}\s*$'
|
if prevline =~ '\s=>\s.*,\s*$' && curline !~ '^\s*[]}])\?,\?\s*$'
|
||||||
call vue#LogWithLnum('previous line is arrow function property')
|
call vue#LogWithLnum('previous line is arrow function property')
|
||||||
let ind = indent(prevlnum)
|
let ind = indent(prevlnum)
|
||||||
endif
|
endif
|
||||||
|
if prevline =~ '\s||\s*$'
|
||||||
|
call vue#LogWithLnum('previous line ends with "||"')
|
||||||
|
let ind = indent(prevlnum) + &sw
|
||||||
|
endif
|
||||||
|
return ind
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:AdjustCSSIndent(ind)
|
||||||
|
let ind = a:ind
|
||||||
|
let prevlnum = prevnonblank(v:lnum - 1)
|
||||||
|
let prevline = getline(prevlnum)
|
||||||
|
let curline = getline(v:lnum)
|
||||||
|
|
||||||
|
if prevline =~ ':\s.*,\s*$'
|
||||||
|
call vue#LogWithLnum('previous line is css function')
|
||||||
|
let ind = indent(prevlnum) + &sw
|
||||||
|
endif
|
||||||
|
if curline =~ '^\s*);\?\s*$'
|
||||||
|
call vue#LogWithLnum('curline is closing round bracket')
|
||||||
|
let ind = indent(prevlnum) - &sw
|
||||||
|
endif
|
||||||
return ind
|
return ind
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ let s:msl_exclude_regex = '++'
|
|||||||
|
|
||||||
let s:one_line_scope_regex = '\<\%(if\|else\|for\|while\)\>[^{;]*' . s:line_term
|
let s:one_line_scope_regex = '\<\%(if\|else\|for\|while\)\>[^{;]*' . s:line_term
|
||||||
let s:one_line_scope_exclue_regex = '\<return\>'
|
let s:one_line_scope_exclue_regex = '\<return\>'
|
||||||
|
let s:closing_bracket = '[]}],\?\s*$'
|
||||||
|
|
||||||
" Regex that defines blocks.
|
" Regex that defines blocks.
|
||||||
let s:block_regex = '\%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
|
let s:block_regex = '\%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
|
||||||
@@ -124,6 +125,10 @@ endfunction
|
|||||||
function s:GetMSL(lnum, in_one_line_scope)
|
function s:GetMSL(lnum, in_one_line_scope)
|
||||||
" Start on the line we're at and use its indent.
|
" Start on the line we're at and use its indent.
|
||||||
let msl = a:lnum
|
let msl = a:lnum
|
||||||
|
if s:Match(msl, s:closing_bracket)
|
||||||
|
return msl
|
||||||
|
endif
|
||||||
|
|
||||||
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
||||||
while lnum > 0
|
while lnum > 0
|
||||||
" If we have a continuation line, or we're in a string, use line as MSL.
|
" If we have a continuation line, or we're in a string, use line as MSL.
|
||||||
|
|||||||
@@ -64,7 +64,9 @@ syntax match VueKey contained '\vwx[^\=]+'
|
|||||||
syntax match VueCustomTag containedin=htmlTagN '\v<(view|text|block|image)>'
|
syntax match VueCustomTag containedin=htmlTagN '\v<(view|text|block|image)>'
|
||||||
|
|
||||||
syntax cluster simpleJavascriptExpression
|
syntax cluster simpleJavascriptExpression
|
||||||
\ contains=javaScriptStringS,javaScriptStringD,javaScriptTemplateString,javascriptNumber,javaScriptOperator
|
\ contains=javaScriptStringS,javaScriptStringD
|
||||||
|
\,javaScriptTemplateString,javascriptNumber
|
||||||
|
\,javaScriptOperator,htmlJavaScriptOperator
|
||||||
|
|
||||||
" JavaScript syntax
|
" JavaScript syntax
|
||||||
syntax region javaScriptStringS
|
syntax region javaScriptStringS
|
||||||
@@ -80,9 +82,9 @@ syntax region javaScriptTemplateExpression
|
|||||||
\ contains=@simpleJavascriptExpression
|
\ contains=@simpleJavascriptExpression
|
||||||
|
|
||||||
syntax match javaScriptNumber '\v<-?\d+L?>|0[xX][0-9a-fA-F]+>' contained
|
syntax match javaScriptNumber '\v<-?\d+L?>|0[xX][0-9a-fA-F]+>' contained
|
||||||
syntax match javaScriptOperator '[-!|&+<>=%*~^]' contained
|
syntax match htmlJavaScriptOperator '[-!|&+<>=%*~^]' contained
|
||||||
syntax match javaScriptOperator '\v(*)@<!/(/|*)@!' contained
|
syntax match htmlJavaScriptOperator '\v(*)@<!/(/|*)@!' contained
|
||||||
syntax keyword javaScriptOperator delete instanceof typeof void new in of contained
|
syntax keyword htmlJavaScriptOperator delete instanceof typeof void new in of contained
|
||||||
|
|
||||||
highlight default link VueAttr htmlTag
|
highlight default link VueAttr htmlTag
|
||||||
if s:attribute
|
if s:attribute
|
||||||
@@ -105,6 +107,6 @@ highlight default link javaScriptStringS String
|
|||||||
highlight default link javaScriptStringD String
|
highlight default link javaScriptStringD String
|
||||||
highlight default link javaScriptTemplateString String
|
highlight default link javaScriptTemplateString String
|
||||||
highlight default link javaScriptNumber Constant
|
highlight default link javaScriptNumber Constant
|
||||||
highlight default link javaScriptOperator Operator
|
highlight default link htmlJavaScriptOperator Operator
|
||||||
"}}}
|
"}}}
|
||||||
" vim: fdm=marker
|
" vim: fdm=marker
|
||||||
|
|||||||
Reference in New Issue
Block a user