[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 4659aee 098/486: rollup merge of #19913: KOMON/r
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 4659aee 098/486: rollup merge of #19913: KOMON/rust-mode-emacs-indentation |
Date: |
Sat, 7 Aug 2021 09:24:57 -0400 (EDT) |
branch: elpa/rust-mode
commit 4659aeedcb009016c8fac135878b7d624446f257
Merge: 186583d f292554
Author: Alex Crichton <alex@alexcrichton.com>
Commit: Alex Crichton <alex@alexcrichton.com>
rollup merge of #19913: KOMON/rust-mode-emacs-indentation
I added an option to auto-indent method chains to line up along their '.'
operators. Like so:
```
let input = io::stdin().readline()
.ok()
.expect("Failed to read line");
```
The old default would indent like so:
```
let input = io::stdin().readme()
.ok()
.expect("Failed to read line");
```
The Rust guide explicitly condones the former, so I thought it would be
nice for the emacs mode to support it. It's off by default, you have to set
```rust-indent-method-chain``` to ```t``` via your .emacs or the customize menu
---
rust-mode.el | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/rust-mode.el b/rust-mode.el
index f25a590..dae685f 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -54,6 +54,11 @@
:type 'integer
:group 'rust-mode)
+(defcustom rust-indent-method-chain nil
+ "Indent Rust method chains, aligned by the '.' operators"
+ :type 'boolean
+ :group 'rust-mode)
+
(defun rust-paren-level () (nth 0 (syntax-ppss)))
(defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss)))
(defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss))))
@@ -73,10 +78,19 @@
;; open bracket ends the line
(when (not (looking-at "[[:blank:]]*\\(?://.*\\)?$"))
(when (looking-at "[[:space:]]")
- (forward-word 1)
- (backward-word 1))
+ (forward-word 1)
+ (backward-word 1))
(current-column))))
+(defun rust-align-to-method-chain ()
+ (save-excursion
+ (previous-line)
+ (end-of-line)
+ (backward-word 1)
+ (backward-char)
+ (when (looking-at "\\..+\(.*\)\n")
+ (- (current-column) rust-indent-offset))))
+
(defun rust-rewind-to-beginning-of-current-level-expr ()
(let ((current-level (rust-paren-level)))
(back-to-indentation)
@@ -99,10 +113,13 @@
;; the inside of it correctly relative to the outside.
(if (= 0 level)
0
+ (or
+ (when rust-indent-method-chain
+ (rust-align-to-method-chain))
(save-excursion
(backward-up-list)
(rust-rewind-to-beginning-of-current-level-expr)
- (+ (current-column) rust-indent-offset)))))
+ (+ (current-column) rust-indent-offset))))))
(cond
;; A function return type is indented to the corresponding
function arguments
((looking-at "->")
@@ -114,6 +131,16 @@
;; A closing brace is 1 level unindended
((looking-at "}") (- baseline rust-indent-offset))
+ ;;Line up method chains by their .'s
+ ((when (and rust-indent-method-chain
+ (looking-at "\..+\(.*\);?\n"))
+ (or
+ (let ((method-indent (rust-align-to-method-chain)))
+ (when method-indent
+ (+ method-indent rust-indent-offset)))
+ (+ baseline rust-indent-offset))))
+
+
;; Doc comments in /** style with leading * indent to line up
the *s
((and (nth 4 (syntax-ppss)) (looking-at "*"))
(+ 1 baseline))
- [nongnu] elpa/rust-mode 9c94ec4 079/486: auto merge of #13922 : Rufflewind/rust/patch-1, r=pnkfelix, (continued)
- [nongnu] elpa/rust-mode 9c94ec4 079/486: auto merge of #13922 : Rufflewind/rust/patch-1, r=pnkfelix, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b2c9e05 069/486: Emacs: indent relative to enclosing block, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 336c052 087/486: emacs: Remove outdated references to ~ in tests, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8622310 091/486: Add 'move' keyword to emacs, kate, and vim editor modes., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4ccac8e 095/486: Update editor syntax files for isize/usize., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2a81393 094/486: added optional method chain indentations for emacs major mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 079f0c2 093/486: Update emacs and vi modes., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0b9a7e0 092/486: rust-mode.el: Tweak syntax table, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 67f4832 099/486: Fix tests broken by trailing whitespace removal, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f292554 097/486: Changed rust-mode code for tabs -> spaces, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4659aee 098/486: rollup merge of #19913: KOMON/rust-mode-emacs-indentation,
ELPA Syncer <=
- [nongnu] elpa/rust-mode e6e16cc 102/486: Add test for closing braces in character literals, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 66438d4 108/486: Merge pull request #2 from MicahChalmer/fix-quotes-with-syntax-properties, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f0d4c25 109/486: Fix aligning of method chains (more-or-less) and add various unit tests., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fd92bfd 111/486: Merge pull request #17 from ramnes/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 149cfdd 106/486: Merge pull request #20 from pnkfelix/fix-broken-tests, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 81d0680 118/486: Fix ERT section of README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2038365 120/486: Fix bug in rust-indent-method-chains, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fea20e7 131/486: Include the last character in indentation tests, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2e7c6dc 128/486: Add test for raw string with inner quote and hash, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode eaa332e 143/486: Add rust-playpen-buffer and rust-playpen-region for sharing code., ELPA Syncer, 2021/08/07