Skip to content

vim: Fix indentation at global scope after non-semantic ([{/)]} #13925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/etc/vim/indent/rust.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endif

" 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.
" Use syntax highlighting attributes when possible.
" NOTE: this is not accurate; /* */ or a line continuation could trick it
Expand Down Expand Up @@ -61,6 +61,20 @@ function s:get_line_trimmed(lnum)
endif
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)

" Starting assumption: cindent (called at the end) will do it right
Expand Down Expand Up @@ -152,8 +166,10 @@ function GetRustIndent(lnum)
" column zero)

call cursor(a:lnum, 1)
if searchpair('{\|(', '', '}\|)', 'nbW') == 0
if searchpair('\[', '', '\]', 'nbW') == 0
if searchpair('{\|(', '', '}\|)', 'nbW'
\ 's:is_string_comment(line("."), col("."))') == 0
if searchpair('\[', '', '\]', 'nbW',
\ 's:is_string_comment(line("."), col("."))') == 0
" Global scope, should be zero
return 0
else
Expand Down