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

Adding a line break after a Trait in a template argument list breaks emacs-mode indentation #10

Closed
steveklabnik opened this issue Feb 2, 2015 · 3 comments · Fixed by #79

Comments

@steveklabnik
Copy link
Member

Issue by gsingh93
Friday Aug 22, 2014 at 01:25 GMT

For earlier discussion, see rust-lang/rust#16665

This issue was labelled with: A-infrastructure in the Rust repository


I think this is a somewhat serious bug with emacs-mode, since I can't use the tab key for indentation inside a function block in many cases.

My code ends up with a long list of traits with bounds in the template argument list, and according to the style guide, I can wrap between traits. However, if I wrap between traits, identation is broken for the function. Consider the following example,

pub fn foo<T,
           V>() {
              // Indentation puts me here
}

As you can see, hitting tab inside the function idents too much. I should mention that I aligned the second template argument to match up with the first, as hitting tab there doesn't work either.

@strega-nil
Copy link

The second issue is one with (backward-up-list) in (rust-mode-indent-line), after
(rust-rewind-irrelevant):

mod test |2| {
    fn test|3|<A,|1|
               V>() {

The cursor goes from |1| to |2|, when it should go from |1| to |3|.

With issue 1, <> is not recognized as a paren-level by (rust-paren-level)

@MicahChalmer
Copy link
Contributor

To make backward-up-list go where it should, emacs would have to recognize the < and > angle brackets as parentheses in its syntax table. In theory it's possible to do it perfectly, since rust's grammar does not require you to know the symbol table to make this distinction (unlike C++.)

I've been trying to get it to do just that recognizing angle brackets but not mistaking other < and > characters (return type arrows, match arrows, less than and greater than operators, etc). At this point I have something that almost works. Under normal circumstances it fixes this issue. It also makes the normal paren matching modes work on them without the code to simulate it that's there now (taking care of #50 in the process.)

Unfortunately at this point there are still a few cases where it gets the angle bracket identification wrong. The other problem with the patch as I currently have it is performance--on my machine, it makes emacs grind to a halt on even moderately large source files (at 7637 lines, src/librustc/middle/ty.rs from the rust tree is enough to make it freeze for minutes.) If anyone is curious I can put it up as an incomplete work-in-progress PR, but it's not ready for merging yet.

@gsingh93
Copy link

Is this related to the following indentation problem, or should I make a new issue:

if true
    || false {
        // Wrong indentation
    }

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