Skip to content
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

Fix indentation for closing parentheses #444

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions indent/rust.vim
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,31 @@ function GetRustIndent(lnum)
endif
endif

" cindent messes up indentation of closing parentheses. It does so
" regardless of the cindent options.
"
" Consider this input example, where | is the cursor:
"
" foo(|)
"
" When pressing Enter, the indentation will be this:
"
" foo(
" |)
"
" But that's not what we want, we want it to be this instead:
"
" foo(
" |)
if line =~# '\V\^\s\*)'
let l:paren_start = searchpair('(', '', ')', 'nbW',
\ 's:is_string_comment(line("."), col("."))')

if l:paren_start != 0 && l:paren_start < a:lnum
return indent(l:paren_start)
endif
endif
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly, I'm not sure if this it the best way of going about fixing this, but it seemed to be the least problematic approach. I spent some time trying to figure out if there's another way (e.g. setting some option), but it seems that enabling cindent results in this behaviour, without there being an obvious way of disabling the indentation of ).


" Fall back on cindent, which does it mostly right
return cindent(a:lnum)
endfunction
Expand Down