Skip to content

Indent inside strings after line-ending backslash #43

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

Merged
merged 3 commits into from
Feb 23, 2015

Conversation

MicahChalmer
Copy link
Contributor

Fix #9.

Note there are a few different ways it tries to determine how to indent a line within a string. Here are some examples from the tests:

pub fn aligned_with_str_begin() {
    format!("abc \
             def");
}


pub fn indented_to_next_level() {
    format!("\
        abc \
        def");
}

pub fn arbitrary_indents_with_and_without_backslashes() {

    println!("
Here is the beginning of the string
            and here is a line that is arbitrarily indented \
            *and a continuation of that indented line
     and another arbitrary indentation
  still another
        yet another \
        *with a line continuing it
And another line not indented
");

}

In the first function, the continuation aligns with the start of the string. In the second, it pushes out to the next indentation level, since there is nothing in the string on the previous line. (This is intended to be similar to how it indents lists inside parentheses--aligns to the open paren if there is anything following it on the same line, indent to next level otherwise.)

If the line ending with a backslash is not the first line in the string, the indent level of that line is used to continue it. In the third function, the indentation will change the whitespace before the lines beginning in * in order to align them with their previous lines. It will leave all the other lines of that string entirely untouched.

Use (forward-line -1) instead of (previous-line)
or (previous-logical-line).  This avoids spurious "beginning-of-buffer"
errors in emacs 23, and is otherwise the same.
@rust-highfive
Copy link

r? @huonw

(rust_highfive has picked a reviewer for you, use r? to override)

(backward-up-list)
(rust-rewind-to-beginning-of-current-level-expr)
(+ (current-column) rust-indent-offset))))))
(cond
;; Indent inside a non-raw string only if the the previous line
;; ends with a backslash that is is inside the same string
((nth 3 (syntax-ppss))
Copy link
Contributor

Choose a reason for hiding this comment

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

how "well known and unchangable" are these indices? it feels like it'd be more obvious what's happening here if we at least used symbolic names.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, I see, it's returning into some crazy tuple...ok.

nikomatsakis added a commit that referenced this pull request Feb 23, 2015
Indent inside strings after line-ending backslash
@nikomatsakis nikomatsakis merged commit 22c8cfa into rust-lang:master Feb 23, 2015
@MicahChalmer MicahChalmer deleted the indent-backslash-strings branch February 23, 2015 23:36
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.

emacs mode indendation is wrong for string constants with backslashes
4 participants