emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/rust-mode 5f37343 379/486: Add rust-indent-return-type-to-


From: ELPA Syncer
Subject: [nongnu] elpa/rust-mode 5f37343 379/486: Add rust-indent-return-type-to-arguments variable
Date: Sat, 7 Aug 2021 09:25:57 -0400 (EDT)

branch: elpa/rust-mode
commit 5f3734314de0e38f472740dfeeb0102ddc5d0b2c
Author: David Kellum <dek-oss@gravitext.com>
Commit: David Kellum <dek-oss@gravitext.com>

    Add rust-indent-return-type-to-arguments variable
    
    This preserves as default (t), the current indentation behavior of `->
    ReturnType` when found on its own line: indenting as per the arguments
    of the above function.  When disabled (nil) by the user, however, this
    will now just indent such a line one level from base-line (e.g. no
    special treatment).
    
    Includes a basic test.
---
 rust-mode-tests.el | 11 +++++++++++
 rust-mode.el       | 13 +++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 9d87960..a5fea28 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -450,6 +450,17 @@ fn foo4(a:i32,
 }
 "))
 
+(ert-deftest indent-return-type-non-visual ()
+  (let ((rust-indent-return-type-to-arguments nil))
+(test-indent
+   "
+fn imagine_long_enough_to_wrap_at_arrow(a:i32, b:char)
+    -> i32
+{
+    let body;
+}
+")))
+
 (ert-deftest indent-body-after-where ()
   (let ((rust-indent-where-clause t))
     (test-indent
diff --git a/rust-mode.el b/rust-mode.el
index a8af671..a433d8d 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -131,6 +131,13 @@ When nil, `where' will be aligned with `fn' or `trait'."
   :group 'rust-mode
   :safe #'booleanp)
 
+(defcustom rust-indent-return-type-to-arguments t
+  "Indent a line starting with the `->' (RArrow) following a function, aligning
+to the function arguments.  When nil, `->' will be indented one level."
+  :type 'boolean
+  :group 'rust-mode
+  :safe #'booleanp)
+
 (defcustom rust-playpen-url-format "https://play.rust-lang.org/?code=%s";
   "Format string to use when submitting code to the playpen."
   :type 'string
@@ -399,8 +406,10 @@ buffer."
                        (back-to-indentation)
                        (current-column))))))
 
-              ;; A function return type is indented to the corresponding 
function arguments
-              ((looking-at "->")
+              ;; A function return type is indented to the corresponding
+             ;; function arguments, if -to-arguments is selected.
+              ((and rust-indent-return-type-to-arguments
+                   (looking-at "->"))
                (save-excursion
                  (backward-list)
                  (or (rust-align-to-expr-after-brace)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]