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

Emacs mode indentation is incorrect in several common cases #8787

Closed
nikomatsakis opened this issue Aug 27, 2013 · 5 comments · Fixed by #12486
Closed

Emacs mode indentation is incorrect in several common cases #8787

nikomatsakis opened this issue Aug 27, 2013 · 5 comments · Fixed by #12486

Comments

@nikomatsakis
Copy link
Contributor

There are several common cases where the emacs mode gets the indentation incorrect. I'll list the examples as I believe they should be formatted.

  1. One indent after open paren with no argument:
call_to_func(
    a,
    b,
    c)
  1. Align -> with arguments:
fn a_func_decl(a: int,
               b: int)
               -> int {
}
  1. Align field names:
foo(SomeStructName { a: int,
                     b: int })
foo(SomeStructName {a: int,
                    b: int})
@nikomatsakis
Copy link
Contributor Author

Oh, and the motivating example for filing the bug: comments don't work quite right.

/*!
 * Foo
 * Bar
 */ 

and also you should be able to hit M-q and have it reflow correctly.

@huonw
Copy link
Member

huonw commented Aug 27, 2013

I've found trailing line comments breaks the indentation of the next line:

fn main() {
    println("foo"); // bar
        println("baz");
    println("qux");
}

(Not sure if this is worth a separate bug.)

@nikomatsakis
Copy link
Contributor Author

Another example is a pattern relative to an indented match:

let x =
    match expr {
        Pattern => ... 
    };

Also, I believe patterns in general are indented incorrectly, though admittedly I'm not sure what the standard is. My preference is to keep all patterns at the same level of indentation, as shown here:

match foo {
    Pattern1 |
    Pattern2 => {
    }
}

@pnkfelix
Copy link
Member

If we're going to fix /*! ... */, we should try to also take the time to fix the other doc comment variations, namely //!, if possible.

@pnkfelix
Copy link
Member

part of #8793

bors added a commit that referenced this issue Aug 30, 2013
This fixes some, but not all, of the issues mentioned in #8787
bors added a commit that referenced this issue Sep 7, 2013
…tsakis

Here are fixes for more problems mentioned in #8787.  I think I've addressed everything mentioned there except for @nikomatsakis's comment about match/patterns now.  (This also fixes the bug in struct alignment that @pnkfelix mentioned from my earlier pull request #8872.)

The biggest change here is to make fill-paragraph (M-q) and auto-fill-mode work inside different variations of multi-line and doc comments.  Because of the way emacs paragraph fills work (callbacks interacting with global regexp variables that are used in odd ways) there were quite a few edge cases that I had to work around.

The only way I was able to keep it all straight was to create some regression tests.  They use the emacs lisp regression testing tool ERT, and are included as the last commit here.  I added a few tests for indentation as well.  I have not attempted to integrate the tests into the overall rust compiler build process, since I can't imagine anyone would want the compiler build to have a dependency on emacs.  Maybe at some point tools like this get their own repositories?  Just a thought.

One other thought related to the tests: should there be a place to put these types of style samples that isn't specific to one text editor?  Maybe as part of an official rust style guide, but in a form that would allow tools like this to pull out the samples and use them for tests?
@bors bors closed this as completed in 780adff Feb 27, 2014
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 a pull request may close this issue.

4 participants