-
Notifications
You must be signed in to change notification settings - Fork 137
Keep prev spaces #607
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
Keep prev spaces #607
Conversation
837f6d1 to
57e2a7d
Compare
| end | ||
| end | ||
| when :on_tstring_beg, :on_regexp_beg, :on_symbeg | ||
| when :on_tstring_beg, :on_regexp_beg, :on_symbeg, :on_backtick |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to add :on_backtick and the test test_pasted_code_keep_base_indent_spaces failed
]+[["a
b" + `c
d` + /e ← failed here
f/ + :"g
h".tap do| # irb(main):002:1* if b # base_indent is 6, indent calculated from tokens is 2 | ||
| # irb(main):003:0> c # base_indent is 6, indent calculated from tokens is 4 | ||
| if prev_open_token | ||
| base_indent = [0, indent_difference(lines, line_results, prev_open_token.pos[0] - 1)].max |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this imply the result of indent_difference(lines, line_results, prev_open_token.pos[0] - 1) could be negative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It could be negative.
if 1 # diff = 0
if 2 # diff = 0
end
end if 1 # diff = 4
if 2 # diff = 4
end
end if 1 # diff = 4
if 2 # diff = 2
end
endif 1 # diff = 0
if 2 # diff = -2 ← negative
end
end
Re-imlement prev_space feature #605 (temporarily dropped in #500)
Code pasted to irb sometimes have base indent. This pull request make IRB indent correctly with base indent
Example of base indent and heredoc
TODO: wait for #515, #608, write tests for heredocdoneBasic algorithm
I defined
base_indentto satisfyactual_indent == base_indent + 2 * indent_level. base_indent can differ on line.Pasted code
Reference code
Line 5 is just inside token
doon line 4. We need to calculate base_indent of line 4 wheredois located.base_indent of line 4 can be calculated by
12 - 2 * indent_level.12 is the indent of pasted code on line 4 and indent_level is 2
Exceptional case
If the beginning of line 4 is inside string literal, we cannot calculate base_indent of line 4.
In that case, base_indent of line 3 is used instead.
Exceptional case 2
Cannot calculate line 4, fallback to line 3 (beginning of tstring_beg)
Cannot calculate line 3, fallback to line 1 (beginning of symbeg)
base_indent of line 1 is 6