-
Notifications
You must be signed in to change notification settings - Fork 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
Indentation bug (parentheses) #74
Comments
I would write (defun kotlin-mode--prev-line-same-level ()
"Move to nearest preceeding non-empty line with same nesting level.
If an unmatched open bracket is found, move to the position after it.
If an unmatched close bracket is found, move to the beginning of the buffer."
(condition-case nil
(while (not (kotlin-mode--bol-other-than-spaces-p))
(backward-sexp))
(scan-error
(forward-comment (- (point)))
(when (memq (char-before) '(?} ?\) ?\]))
(goto-char (point-min))))))
(defun kotlin-mode--bol-other-than-spaces-p ()
"Return non-nil if the point is at the beginning of line other than spaces.
Return nil otherwise"
;; omitted
) Then, replace (forward-comment (- (point)))
(if (and (eq (char-before) ?>)
(eq (char-before (1- (point))) ?-))
;; previous line ends with ->
(setq cur-indent (+ (current-indentation) kotlin-tab-width))
(kotlin-mode--prev-line-same-level)
(setq cur-indent (+ (current-indentation)
(if (memq (char-before) '(?{ ?\( ?\[))
kotlin-tab-width
0)))) Those code are not tested. |
It would still mishandle those cases: Expected: foo(1,
2,
3) Actual: foo(1,
2,
3) Expected: let x = foo +
bar Actual: let x = foo +
bar My branch works fine for those cases: #53. |
when (x) {
aaa() ->
// This line should be aligned with `aaa` with offset.
bbb()
ccc() ->
ccc()
}
foofoofoo { x ->
// This line should be aligned with `foofoofoo` with offset, not `x`.
bar(x)
}
when (x) {
aaa() ->
// This line should be aligned with `aaa` with offset.
bbb()
ccc() ->
ccc()
}
foofoofoo { x ->
// This line should be aligned with `foofoofoo` with offset, not `x`.
bar(x)
} After all, indenting Kotlin code is not a hundred lines of simple thing, but thousands of lines of complex logic. More pathological example: when (foo) {
object: A1,
A2 {
},
object: A3 by object: A4,
A5 {
},
A6 {
} ->
1
} |
Now fixed as #53 is merged. |
If round parentheses are on different lines, the indentation gets broken.
Try to write this code in the
kotlin-mode
:And press Enter.
Expected result:
The cursor is here
Actual result:
The cursor is here
The text was updated successfully, but these errors were encountered: