branch: elpa/rust-mode
commit 01ac5d8197658c21412acde16df7c39325f03e4d
Merge: 1587839 fba7714
Author: Niko Matsakis <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #177 from mrBliss/handle-comments-method-chains
Handle comments when indenting method chains
---
rust-mode-tests.el | 24 ++++++++++++++++++++++++
rust-mode.el | 11 +++++++++++
2 files changed, 35 insertions(+)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 35a1cbd..2585237 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -1599,6 +1599,19 @@ fn main() {
"
)))
+(ert-deftest indent-method-chains-look-over-comment ()
+ (let ((rust-indent-method-chain t)) (test-indent
+ "
+fn main() {
+ thing.a.do_it
+ // A comment
+ .aligned
+ // Another comment
+ .more_alignment();
+}
+"
+ )))
+
(ert-deftest indent-method-chains-comment ()
(let ((rust-indent-method-chain t)) (test-indent
"
@@ -1627,6 +1640,17 @@ fn main() { // comment here should not push next line out
"
)))
+(ert-deftest indent-method-chains-after-comment2 ()
+ (let ((rust-indent-method-chain t)) (test-indent
+ "
+fn main() {
+ // Lorem ipsum lorem ipsum lorem ipsum lorem.ipsum
+ foo.bar()
+}
+"
+ )))
+
+
(ert-deftest test-for-issue-36-syntax-corrupted-state ()
"This is a test for a issue #36, which involved emacs's
internal state getting corrupted when actions were done in a
diff --git a/rust-mode.el b/rust-mode.el
index 2c97433..3f6e279 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -301,6 +301,17 @@ buffer."
(when (looking-at (concat "\s*\." rust-re-ident))
(forward-line -1)
(end-of-line)
+ ;; Keep going up (looking for a line that could contain a method chain)
+ ;; while we're in a comment or on a blank line. Stop when the paren
+ ;; level changes.
+ (let ((level (rust-paren-level)))
+ (while (and (or (rust-in-str-or-cmnt)
+ ;; Only whitespace (or nothing) from the beginning to
+ ;; the end of the line.
+ (looking-back "^\s*" (point-at-bol)))
+ (= (rust-paren-level) level))
+ (forward-line -1)
+ (end-of-line)))
(let
;; skip-dot-identifier is used to position the point at the