mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-08 21:54:46 +08:00
Add new 'initial indent' option
This commit is contained in:
@@ -24,7 +24,7 @@ function! s:MergeDefaultWithConfig(user)
|
|||||||
\'attribute': 0,
|
\'attribute': 0,
|
||||||
\'keyword': 0,
|
\'keyword': 0,
|
||||||
\'foldexpr': 0,
|
\'foldexpr': 0,
|
||||||
\'init_indent': expand('%:e') == 'wpy',
|
\'initial_indent': [],
|
||||||
\'debug': 0,
|
\'debug': 0,
|
||||||
\}
|
\}
|
||||||
|
|
||||||
@@ -131,7 +131,9 @@ endfunction
|
|||||||
|
|
||||||
function! s:SyntaxAtEnd(lnum)
|
function! s:SyntaxAtEnd(lnum)
|
||||||
let syns = s:SyntaxListAtEnd(a:lnum)
|
let syns = s:SyntaxListAtEnd(a:lnum)
|
||||||
return empty(syns) ? '' : get(syns, 0, '')
|
let syntax_name = empty(syns) ? '' : get(syns, 0, '')
|
||||||
|
let syntax_name = s:RemoveCssPrefix(syntax_name)
|
||||||
|
return syntax_name
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! vue#SyntaxSecondAtEnd(lnum)
|
function! vue#SyntaxSecondAtEnd(lnum)
|
||||||
@@ -141,7 +143,9 @@ endfunction
|
|||||||
|
|
||||||
function! s:GetBlockTag(lnum)
|
function! s:GetBlockTag(lnum)
|
||||||
let syntax_name = s:SyntaxAtEnd(a:lnum)
|
let syntax_name = s:SyntaxAtEnd(a:lnum)
|
||||||
let tag = tolower(matchstr(syntax_name, '\u\U\+\zeBlock'))
|
let tag = matchstr(syntax_name, '\(\u\U\+\)\+\zeBlock')
|
||||||
|
let tag = substitute(tag, '\U\zs\(\u\)', "-\\1", 'g')
|
||||||
|
let tag = tolower(tag)
|
||||||
return tag
|
return tag
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -157,21 +161,22 @@ function! vue#AlterSyntaxForEmmetVim(name, syntax)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Remove css prefix
|
" Remove css prefix
|
||||||
function! s:RemoveCssPrefix(syntax_name, syntax)
|
function! s:RemoveCssPrefix(syntax_name)
|
||||||
let syntax = a:syntax
|
let syntax_name = a:syntax_name
|
||||||
|
let syntax = matchstr(syntax_name, '^\U\+')
|
||||||
if syntax == 'css'
|
if syntax == 'css'
|
||||||
let next_syntax = tolower(matchstr(a:syntax_name, '^\U\+\zs\u\U\+'))
|
let next_syntax = tolower(matchstr(syntax_name, '^\U\+\zs\u\U\+'))
|
||||||
if count(s:style_with_css_prefix, next_syntax)
|
if count(s:style_with_css_prefix, next_syntax)
|
||||||
let syntax = next_syntax
|
let syntax_name = matchstr(syntax_name, '^\U\+\zs.*')
|
||||||
|
let syntax_name = tolower(syntax_name[0]).syntax_name[1:]
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
return syntax
|
return syntax_name
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:GetBlockSyntax(lnum)
|
function! s:GetBlockSyntax(lnum)
|
||||||
let syntax_name = s:SyntaxAtEnd(a:lnum)
|
let syntax_name = s:SyntaxAtEnd(a:lnum)
|
||||||
let syntax = matchstr(syntax_name, '^\U\+')
|
let syntax = matchstr(syntax_name, '^\U\+')
|
||||||
let syntax = s:RemoveCssPrefix(syntax_name, syntax)
|
|
||||||
return syntax
|
return syntax
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -196,9 +201,7 @@ endfunction
|
|||||||
function! vue#LoadSyntax(group, syntax)
|
function! vue#LoadSyntax(group, syntax)
|
||||||
let group = a:group
|
let group = a:group
|
||||||
let syntax = a:syntax
|
let syntax = a:syntax
|
||||||
let full_syntax_type = type(s:full_syntax)
|
if s:IncludeOrEqual(s:full_syntax, syntax)
|
||||||
if (full_syntax_type == v:t_list && count(s:full_syntax, syntax))
|
|
||||||
\ || (full_syntax_type == v:t_string && s:full_syntax == syntax)
|
|
||||||
call vue#LoadFullSyntax(group, syntax)
|
call vue#LoadFullSyntax(group, syntax)
|
||||||
else
|
else
|
||||||
let loaded = vue#LoadDefaultSyntax(group, syntax)
|
let loaded = vue#LoadDefaultSyntax(group, syntax)
|
||||||
@@ -272,6 +275,18 @@ function! vue#GetSyntaxList(config_syntax)
|
|||||||
return syntax_list
|
return syntax_list
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:IncludeOrEqual(listOrString, item)
|
||||||
|
let listOrString = a:listOrString
|
||||||
|
let item = a:item
|
||||||
|
let type = type(listOrString)
|
||||||
|
return (type == v:t_list && count(listOrString, item))
|
||||||
|
\ || (type == v:t_string && listOrString == item)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! vue#IncludeOrEqual(listOrString, item)
|
||||||
|
return s:IncludeOrEqual(a:listOrString, a:item)
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:ModifySyntaxOrder(syntax_list)
|
function! s:ModifySyntaxOrder(syntax_list)
|
||||||
let syntax_list = a:syntax_list
|
let syntax_list = a:syntax_list
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ function! s:Init()
|
|||||||
""" Configs
|
""" Configs
|
||||||
let s:config = vue#GetConfig('config', {})
|
let s:config = vue#GetConfig('config', {})
|
||||||
let s:config_syntax = s:config.syntax
|
let s:config_syntax = s:config.syntax
|
||||||
let s:enable_init_indent = s:config.init_indent
|
let s:initial_indent = s:config.initial_indent
|
||||||
|
|
||||||
""" Variables
|
""" Variables
|
||||||
let s:indent = {}
|
let s:indent = {}
|
||||||
@@ -131,14 +131,15 @@ function! s:AdjustBlockIndent(syntax, ind)
|
|||||||
return ind
|
return ind
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:CheckInitIndent(tag, syntax, ind)
|
function! s:CheckInitialIndent(tag, syntax, ind)
|
||||||
let ind = a:ind
|
let ind = a:ind
|
||||||
let curline = getline(v:lnum)
|
let add = 0
|
||||||
|
|
||||||
let add = s:enable_init_indent
|
if ind == 0 && getline(v:lnum) !~ s:block_tag
|
||||||
\&& ind == 0
|
let add = vue#IncludeOrEqual(s:initial_indent, a:tag.'.'.a:syntax)
|
||||||
\&& count(['style', 'script'], a:tag) == 1
|
\ || vue#IncludeOrEqual(s:initial_indent, a:tag)
|
||||||
\&& curline !~ s:block_tag
|
\ || vue#IncludeOrEqual(s:initial_indent, a:syntax)
|
||||||
|
endif
|
||||||
if add
|
if add
|
||||||
call vue#LogWithLnum('add initial indent')
|
call vue#LogWithLnum('add initial indent')
|
||||||
let ind = &sw
|
let ind = &sw
|
||||||
@@ -284,7 +285,7 @@ function! GetVueIndent()
|
|||||||
call vue#LogWithLnum('context, ind '.ind)
|
call vue#LogWithLnum('context, ind '.ind)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let ind = s:CheckInitIndent(tag, syntax, ind)
|
let ind = s:CheckInitialIndent(tag, syntax, ind)
|
||||||
return ind
|
return ind
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,15 @@
|
|||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
let s:config = vue#GetConfig('config', {})
|
let s:config = vue#GetConfig('config', {})
|
||||||
let s:keyword = s:config.keyword
|
let s:keyword = s:config.keyword
|
||||||
let s:init_indent = s:config.init_indent
|
let s:initial_indent = s:config.initial_indent
|
||||||
|
|
||||||
|
let s:enable_initial_indent = 0
|
||||||
|
for item in s:initial_indent
|
||||||
|
if match(item, 'script') != -1
|
||||||
|
let s:enable_initial_indent = 1
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
@@ -23,7 +31,7 @@ if !s:keyword | finish | endif
|
|||||||
|
|
||||||
let s:vue_keywords = 'name parent functional delimiters comments components directives filters extends mixins inheritAttrs model props propsData data computed watch methods template render renderError inject provide beforeCreate created beforeMount mounted beforeUpdate updated activated deactivated beforeDestroy destroyed setup beforeUnmount unmounted errorCaptured renderTracked renderTriggered'
|
let s:vue_keywords = 'name parent functional delimiters comments components directives filters extends mixins inheritAttrs model props propsData data computed watch methods template render renderError inject provide beforeCreate created beforeMount mounted beforeUpdate updated activated deactivated beforeDestroy destroyed setup beforeUnmount unmounted errorCaptured renderTracked renderTriggered'
|
||||||
|
|
||||||
let s:indent = &sw * (1 + s:init_indent)
|
let s:indent = &sw * (1 + s:enable_initial_indent)
|
||||||
let s:keywords_regexp = '\v^\s{'.s:indent.'}(async )?<('
|
let s:keywords_regexp = '\v^\s{'.s:indent.'}(async )?<('
|
||||||
\.join(split(s:vue_keywords, ' '), '|')
|
\.join(split(s:vue_keywords, ' '), '|')
|
||||||
\.')\ze'
|
\.')\ze'
|
||||||
|
|||||||
Reference in New Issue
Block a user