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

Conversation

yorickpeterse
Copy link

To help explain this problem, consider this input (where | is the
cursor):

foo(|)

Prior to this commit, pressing Enter would result in the following:

foo(
    |)

That is, the closing parenthesis is indented by one level. This is the
case regardless of the cindent options/keys chosen.

To fix this, we manually indent lines that start with a ")" (ignoring
leading whitespace). Such lines are indented according to the
indentation of the line that contained the opening parenthesis.

Fixes #443

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @chris-morgan (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@yorickpeterse
Copy link
Author

@login224444 as you had the same issue, could you give this patch a try to see if it also fixes the indentation for you? Thanks!

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 ).

To help explain this problem, consider this input (where | is the
cursor):

    foo(|)

Prior to this commit, pressing Enter would result in the following:

    foo(
        |)

That is, the closing parenthesis is indented by one level. This is the
case regardless of the cindent options/keys chosen.

To fix this, we manually indent lines that start with a ")" (ignoring
leading whitespace). Such lines are indented according to the
indentation of the line that contained the opening parenthesis.

Fixes rust-lang#443
@ghost
Copy link

ghost commented May 21, 2021

@login224444 as you had the same issue, could you give this patch a try to see if it also fixes the indentation for you? Thanks!

Yes, it's pretty good. Thanks!

@yorickpeterse
Copy link
Author

@chris-morgan Any thoughts on these changes? 😃

@yorickpeterse
Copy link
Author

@chris-morgan As per #444 (comment), do you have any thoughts on these changes? Or is this plugin no longer actively maintained?

@Oglo12
Copy link

Oglo12 commented Jun 23, 2024

I am so glad someone else had this issue and made a pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Indentation for closing parentheses is incorrect
4 participants