Skip to content

vim: Fix an indentation issue with cindent #14056

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

Closed
wants to merge 1 commit into from

Conversation

lilyball
Copy link
Contributor

@lilyball lilyball commented May 9, 2014

cindent handles the following case incorrectly:

impl X {
    b: int,
    //
    c: int,
}

if you try and insert a new line after the c declaration.

To fix this, fix the get_line_trimmed() function to work properly, and
then extend GetRustIndent to keep searching backwards until it finds a
non-blank line after trimming. This lets it handle the trailing comma
case properly, as if the comment were never there.

Fixes #14041.

cindent handles the following case incorrectly:

impl X {
    b: int,
    //
    c: int,
}

if you try and insert a new line after the `c` declaration.

To fix this, fix the get_line_trimmed() function to work properly, and
then extend GetRustIndent to keep searching backwards until it finds a
non-blank line after trimming. This lets it handle the trailing comma
case properly, as if the comment were never there.

Fixes rust-lang#14041.
@lilyball
Copy link
Contributor Author

lilyball commented May 9, 2014

cc @chris-morgan

@@ -40,12 +40,12 @@ function! s:get_line_trimmed(lnum)
" If the last character in the line is a comment, do a binary search for
" the start of the comment. synID() is slow, a linear search would take
" too long on a long line.
if synIDattr(synID(a:lnum, line_len, 1), "name") =~ "Comment\|Todo"
if synIDattr(synID(a:lnum, line_len, 1), "name") =~ 'Comment\|Todo'
Copy link
Member

Choose a reason for hiding this comment

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

Good catch—that was stupid of me.

@chris-morgan
Copy link
Member

Nicely done! LGTM.

bors added a commit that referenced this pull request May 10, 2014
cindent handles the following case incorrectly:

    impl X {
        b: int,
        //
        c: int,
    }

if you try and insert a new line after the `c` declaration.

To fix this, fix the get_line_trimmed() function to work properly, and
then extend GetRustIndent to keep searching backwards until it finds a
non-blank line after trimming. This lets it handle the trailing comma
case properly, as if the comment were never there.

Fixes #14041.
@bors bors closed this May 10, 2014
@lilyball lilyball deleted the vim_indent_fix branch May 12, 2014 07:23
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2023
Parse macros `allow_internal_unsafe` attribute

We don't use it for anything yet but it might become part of hygiene
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.

Vim indentation broken with commented struct fields.
5 participants