vim: Fix indentation at global scope after non-semantic ([{/)]}
If an unbalanced [ exists in a string or comment, this should not be considered when calculating the indent at the top level. Similarly, when testing for ({/}) to see if we're at the top level to begin with, strings and comments should be skipped.
This commit is contained in:
parent
0c691df8ac
commit
91e61ad967
@ -30,7 +30,7 @@ endif
|
|||||||
|
|
||||||
" Come here when loading the script the first time.
|
" Come here when loading the script the first time.
|
||||||
|
|
||||||
function s:get_line_trimmed(lnum)
|
function! s:get_line_trimmed(lnum)
|
||||||
" Get the line and remove a trailing comment.
|
" Get the line and remove a trailing comment.
|
||||||
" Use syntax highlighting attributes when possible.
|
" Use syntax highlighting attributes when possible.
|
||||||
" NOTE: this is not accurate; /* */ or a line continuation could trick it
|
" NOTE: this is not accurate; /* */ or a line continuation could trick it
|
||||||
@ -61,6 +61,20 @@ function s:get_line_trimmed(lnum)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:is_string_comment(lnum, col)
|
||||||
|
if has('syntax_items')
|
||||||
|
for id in synstack(a:lnum, a:col)
|
||||||
|
let synname = synIDattr(id, "name")
|
||||||
|
if synname == "rustString" || synname =~ "^rustComment"
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
else
|
||||||
|
" without syntax, let's not even try
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function GetRustIndent(lnum)
|
function GetRustIndent(lnum)
|
||||||
|
|
||||||
" Starting assumption: cindent (called at the end) will do it right
|
" Starting assumption: cindent (called at the end) will do it right
|
||||||
@ -152,8 +166,10 @@ function GetRustIndent(lnum)
|
|||||||
" column zero)
|
" column zero)
|
||||||
|
|
||||||
call cursor(a:lnum, 1)
|
call cursor(a:lnum, 1)
|
||||||
if searchpair('{\|(', '', '}\|)', 'nbW') == 0
|
if searchpair('{\|(', '', '}\|)', 'nbW'
|
||||||
if searchpair('\[', '', '\]', 'nbW') == 0
|
\ 's:is_string_comment(line("."), col("."))') == 0
|
||||||
|
if searchpair('\[', '', '\]', 'nbW',
|
||||||
|
\ 's:is_string_comment(line("."), col("."))') == 0
|
||||||
" Global scope, should be zero
|
" Global scope, should be zero
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user