mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2026-11-03 02:47:36 +08:00
Support shiftwidth=0 in indent and fold
With shiftwidth=0, Vim uses the value of tabstop, but &sw is 0. So multiline tags and brackets got wrong indent, and fold levels were wrong as indent was divided by 0. Use shiftwidth() instead, which is the same as &sw when it isn't 0.
This commit is contained in:
4 files changed
+50
-15
No files matched your search
@@ -88,7 +88,7 @@ endfunction
|
|||||||
|
|
||||||
function! s:IndentLevel(lnum)
|
function! s:IndentLevel(lnum)
|
||||||
" Add 1 to indentLevel, so start/end tags can fold properly
|
" Add 1 to indentLevel, so start/end tags can fold properly
|
||||||
return indent(a:lnum) / &shiftwidth + 1
|
return indent(a:lnum) / shiftwidth() + 1
|
||||||
endfunction
|
endfunction
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
|
|||||||
+14
-14
@@ -148,7 +148,7 @@ function! s:CheckInitialIndent(tag, syntax, ind)
|
|||||||
endif
|
endif
|
||||||
if add
|
if add
|
||||||
call vue#LogWithLnum('add initial indent')
|
call vue#LogWithLnum('add initial indent')
|
||||||
let ind = &sw
|
let ind = shiftwidth()
|
||||||
endif
|
endif
|
||||||
return ind
|
return ind
|
||||||
endfunction
|
endfunction
|
||||||
@@ -183,16 +183,16 @@ function! s:AdjustHTMLIndent(ind)
|
|||||||
|
|
||||||
if prevline =~? s:empty_tag
|
if prevline =~? s:empty_tag
|
||||||
call vue#LogWithLnum('previous line is an empty tag')
|
call vue#LogWithLnum('previous line is an empty tag')
|
||||||
let ind = ind - &sw
|
let ind = ind - shiftwidth()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Align '/>' and '>' with '<'
|
" Align '/>' and '>' with '<'
|
||||||
if curline =~? s:tag_end
|
if curline =~? s:tag_end
|
||||||
let ind = ind - &sw
|
let ind = ind - shiftwidth()
|
||||||
endif
|
endif
|
||||||
" Then correct the indentation of any element following '/>' or '>'.
|
" Then correct the indentation of any element following '/>' or '>'.
|
||||||
if prevline =~? s:tag_end
|
if prevline =~? s:tag_end
|
||||||
let ind = ind + &sw
|
let ind = ind + shiftwidth()
|
||||||
|
|
||||||
" Decrease indent if prevlines are a multiline empty tag
|
" Decrease indent if prevlines are a multiline empty tag
|
||||||
let [start, end] = s:PrevMultilineEmptyTag(v:lnum)
|
let [start, end] = s:PrevMultilineEmptyTag(v:lnum)
|
||||||
@@ -200,7 +200,7 @@ function! s:AdjustHTMLIndent(ind)
|
|||||||
call vue#LogWithLnum('previous line is a multiline empty tag')
|
call vue#LogWithLnum('previous line is a multiline empty tag')
|
||||||
let ind = indent(v:lnum - 1)
|
let ind = indent(v:lnum - 1)
|
||||||
if curline =~? s:full_tag_end
|
if curline =~? s:full_tag_end
|
||||||
let ind = ind - &sw
|
let ind = ind - shiftwidth()
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -210,17 +210,17 @@ function! s:AdjustHTMLIndent(ind)
|
|||||||
" ]
|
" ]
|
||||||
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) + shiftwidth()
|
||||||
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) - shiftwidth()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Multiline ternary 'a ? b : c' in attribute
|
" Multiline ternary 'a ? b : c' in attribute
|
||||||
if curline =~ s:ternary_q
|
if curline =~ s:ternary_q
|
||||||
call vue#LogWithLnum('current line is ?...')
|
call vue#LogWithLnum('current line is ?...')
|
||||||
let ind = indent(prevlnum) + &sw
|
let ind = indent(prevlnum) + shiftwidth()
|
||||||
endif
|
endif
|
||||||
if curline =~ s:ternary_e && prevline =~ s:ternary_q
|
if curline =~ s:ternary_e && prevline =~ s:ternary_q
|
||||||
call vue#LogWithLnum('current line is :...')
|
call vue#LogWithLnum('current line is :...')
|
||||||
@@ -228,13 +228,13 @@ function! s:AdjustHTMLIndent(ind)
|
|||||||
endif
|
endif
|
||||||
if prevline =~ s:ternary_e
|
if prevline =~ s:ternary_e
|
||||||
call vue#LogWithLnum('prevline line is :...')
|
call vue#LogWithLnum('prevline line is :...')
|
||||||
let ind = indent(prevlnum) - &sw
|
let ind = indent(prevlnum) - shiftwidth()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Angle bracket in attribute, like v-if="isEnabled('item.<name>')"
|
" Angle bracket in attribute, like v-if="isEnabled('item.<name>')"
|
||||||
if prevline =~ '="[^"]*<[^"]*>[^"]*"'
|
if prevline =~ '="[^"]*<[^"]*>[^"]*"'
|
||||||
call vue#LogWithLnum('prevline line is angle bracket in attribute')
|
call vue#LogWithLnum('prevline line is angle bracket in attribute')
|
||||||
let ind = ind - &sw
|
let ind = ind - shiftwidth()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ind
|
return ind
|
||||||
@@ -248,7 +248,7 @@ function! s:AdjustJavaScriptIndent(ind)
|
|||||||
|
|
||||||
if prevline =~ '^\s*\w.*$' && curline =~ '^\s*\.'
|
if prevline =~ '^\s*\w.*$' && curline =~ '^\s*\.'
|
||||||
call vue#LogWithLnum('current line is the first chain call')
|
call vue#LogWithLnum('current line is the first chain call')
|
||||||
let ind = indent(prevlnum) + &sw
|
let ind = indent(prevlnum) + shiftwidth()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if prevline =~ '\s=>\s.*,\s*$' && curline !~ '^\s*[]}])\?,\?\s*$'
|
if prevline =~ '\s=>\s.*,\s*$' && curline !~ '^\s*[]}])\?,\?\s*$'
|
||||||
@@ -257,7 +257,7 @@ function! s:AdjustJavaScriptIndent(ind)
|
|||||||
endif
|
endif
|
||||||
if prevline =~ '\s||\s*$'
|
if prevline =~ '\s||\s*$'
|
||||||
call vue#LogWithLnum('previous line ends with "||"')
|
call vue#LogWithLnum('previous line ends with "||"')
|
||||||
let ind = indent(prevlnum) + &sw
|
let ind = indent(prevlnum) + shiftwidth()
|
||||||
endif
|
endif
|
||||||
return ind
|
return ind
|
||||||
endfunction
|
endfunction
|
||||||
@@ -270,11 +270,11 @@ function! s:AdjustCSSIndent(ind)
|
|||||||
|
|
||||||
if prevline =~ ':\s.*,\s*$'
|
if prevline =~ ':\s.*,\s*$'
|
||||||
call vue#LogWithLnum('previous line is css function')
|
call vue#LogWithLnum('previous line is css function')
|
||||||
let ind = indent(prevlnum) + &sw
|
let ind = indent(prevlnum) + shiftwidth()
|
||||||
endif
|
endif
|
||||||
if curline =~ '^\s*);\?\s*$'
|
if curline =~ '^\s*);\?\s*$'
|
||||||
call vue#LogWithLnum('curline is closing round bracket')
|
call vue#LogWithLnum('curline is closing round bracket')
|
||||||
let ind = indent(prevlnum) - &sw
|
let ind = indent(prevlnum) - shiftwidth()
|
||||||
endif
|
endif
|
||||||
return ind
|
return ind
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
" shiftwidth=0 uses the value of tabstop, same as shiftwidth=4 here
|
||||||
|
set shiftwidth=0 tabstop=4
|
||||||
|
let g:vim_vue_plugin_config = {'foldexpr': 1}
|
||||||
|
let g:test_flatten = 1
|
||||||
|
|
||||||
|
function! Check()
|
||||||
|
let levels = [1, 2, 3, 2, 3, 4, 3, 3, 2, 1]
|
||||||
|
for lnum in range(1, len(levels))
|
||||||
|
call ExpectFoldlevel(lnum, levels[lnum - 1])
|
||||||
|
endfor
|
||||||
|
endfunction
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="a"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
>
|
||||||
|
<p :class="{ a: b }">x</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return { a: 1 }
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
p {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in new issue
Block a user