Skip to content

Commit 54a9c3d

Browse files
authored
Merge pull request #296 from dekellum/indent-return-type-defcustom
Add rust-indent-return-type-to-arguments defcustom variable
2 parents d3a7025 + 5f37343 commit 54a9c3d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

rust-mode-tests.el

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,17 @@ fn foo4(a:i32,
450450
}
451451
"))
452452

453+
(ert-deftest indent-return-type-non-visual ()
454+
(let ((rust-indent-return-type-to-arguments nil))
455+
(test-indent
456+
"
457+
fn imagine_long_enough_to_wrap_at_arrow(a:i32, b:char)
458+
-> i32
459+
{
460+
let body;
461+
}
462+
")))
463+
453464
(ert-deftest indent-body-after-where ()
454465
(let ((rust-indent-where-clause t))
455466
(test-indent

rust-mode.el

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ When nil, `where' will be aligned with `fn' or `trait'."
131131
:group 'rust-mode
132132
:safe #'booleanp)
133133

134+
(defcustom rust-indent-return-type-to-arguments t
135+
"Indent a line starting with the `->' (RArrow) following a function, aligning
136+
to the function arguments. When nil, `->' will be indented one level."
137+
:type 'boolean
138+
:group 'rust-mode
139+
:safe #'booleanp)
140+
134141
(defcustom rust-playpen-url-format "https://play.rust-lang.org/?code=%s"
135142
"Format string to use when submitting code to the playpen."
136143
:type 'string
@@ -399,8 +406,10 @@ buffer."
399406
(back-to-indentation)
400407
(current-column))))))
401408

402-
;; A function return type is indented to the corresponding function arguments
403-
((looking-at "->")
409+
;; A function return type is indented to the corresponding
410+
;; function arguments, if -to-arguments is selected.
411+
((and rust-indent-return-type-to-arguments
412+
(looking-at "->"))
404413
(save-excursion
405414
(backward-list)
406415
(or (rust-align-to-expr-after-brace)

0 commit comments

Comments
 (0)