[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode dae5af7 298/486: Merge pull request #198 from tr
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode dae5af7 298/486: Merge pull request #198 from tromey/indentation-fix |
Date: |
Sat, 7 Aug 2021 09:25:39 -0400 (EDT) |
branch: elpa/rust-mode
commit dae5af71ebf4b5c6797ef057e8a0ebf655bcdbfb
Merge: 85befb9 5469d9b
Author: Tom Tromey <tom@tromey.com>
Commit: GitHub <noreply@github.com>
Merge pull request #198 from tromey/indentation-fix
fix rust indentation bug
---
rust-mode-tests.el | 28 ++++++++++++++++++++++++++++
rust-mode.el | 25 +++++++++++++++++--------
2 files changed, 45 insertions(+), 8 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 98230de..5abd4a7 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -1628,6 +1628,34 @@ fn main() {
"
)))
+(ert-deftest indent-function-after-where ()
+ (let ((rust-indent-method-chain t)) (test-indent
+ "
+fn each_split_within<'a, F>(ss: &'a str, lim: usize, mut it: F)
+ -> bool where F: FnMut(&'a str) -> bool {
+}
+
+#[test]
+fn test_split_within() {
+}
+"
+ )))
+
+(ert-deftest indent-function-after-where-nested ()
+ (let ((rust-indent-method-chain t)) (test-indent
+ "
+fn outer() {
+ fn each_split_within<'a, F>(ss: &'a str, lim: usize, mut it: F)
+ -> bool where F: FnMut(&'a str) -> bool {
+ }
+ #[test]
+ fn test_split_within() {
+ }
+ fn bar() {
+ }
+}
+"
+ )))
(ert-deftest test-for-issue-36-syntax-corrupted-state ()
"This is a test for a issue #36, which involved emacs's
diff --git a/rust-mode.el b/rust-mode.el
index 2307cc0..f1c3994 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -35,6 +35,14 @@
(defconst rust-re-unsafe "unsafe")
(defconst rust-re-extern "extern")
+;;; Start of a Rust item
+(defvar rust-top-item-beg-re
+ (concat "\\s-*\\(?:priv\\|pub\\)?\\s-*"
+ (regexp-opt
+ '("enum" "struct" "type" "mod" "use" "fn" "static" "impl"
+ "extern" "trait"))
+ "\\_>"))
+
(defun rust-looking-back-str (str)
"Like `looking-back' but for fixed strings rather than regexps (so that it's
not so slow)"
(let ((len (length str)))
@@ -394,6 +402,10 @@ buffer."
;; our search for "where ".
(let ((function-start nil) (function-level nil))
(save-excursion
+ ;; If we're already at the start of a function,
+ ;; don't go back any farther. We can easily do
+ ;; this by moving to the end of the line first.
+ (end-of-line)
(rust-beginning-of-defun)
(back-to-indentation)
;; Avoid using multiple-value-bind
@@ -437,6 +449,10 @@ buffer."
;; baseline as well.
(looking-at "\\<else\\>\\|{\\|/[/*]")
+ ;; If this is the start of a top-level item,
+ ;; stay on the baseline.
+ (looking-at rust-top-item-beg-re)
+
(save-excursion
(rust-rewind-irrelevant)
;; Point is now at the end of the previous line
@@ -1136,13 +1152,6 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
;;; Defun Motions
-;;; Start of a Rust item
-(defvar rust-top-item-beg-re
- (concat "^\\s-*\\(?:priv\\|pub\\)?\\s-*"
- (regexp-opt
- '("enum" "struct" "type" "mod" "use" "fn" "static" "impl"
- "extern" "trait"))))
-
(defun rust-beginning-of-defun (&optional arg)
"Move backward to the beginning of the current defun.
@@ -1153,7 +1162,7 @@ This is written mainly to be used as
`beginning-of-defun-function' for Rust.
Don't move to the beginning of the line. `beginning-of-defun',
which calls this, does that afterwards."
(interactive "p")
- (re-search-backward (concat "^\\(" rust-top-item-beg-re "\\)\\_>")
+ (re-search-backward (concat "^\\(" rust-top-item-beg-re "\\)")
nil 'move (or arg 1)))
(defun rust-end-of-defun ()
- [nongnu] elpa/rust-mode 0077bbf 160/486: Fix package.el URL, (continued)
- [nongnu] elpa/rust-mode 0077bbf 160/486: Fix package.el URL, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 86db9bd 166/486: Merge pull request #65 from tromey/blink-matching-paren, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 53c558c 175/486: Factor out rust-conditional-re-search-forward, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5231709 177/486: Speed up calls to "looking-back", ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c801dda 197/486: Merge pull request #77 from tromey/fix-byte-compiler-add-lexbind, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode cdaf3fc 201/486: Update MELPA URL, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1761a9c 204/486: Merge pull request #105 from MicahChalmer/remove-misc, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f8d94cb 229/486: Use catch and throw instead of block and return, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 40c33fd 250/486: add code to handle new-style rustc errors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c69adaf 254/486: Add menu titles for items in imenu, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode dae5af7 298/486: Merge pull request #198 from tromey/indentation-fix,
ELPA Syncer <=
- [nongnu] elpa/rust-mode bfe4056 452/486: Re-implement rust-in-macro for performance, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode eaf95af 210/486: Merge pull request #111 from mrBliss/where-indentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2540d7e 262/486: Go back to the current line and column after formatting., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 52870b6 203/486: Remove unused require of misc.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 95d089c 211/486: Merge pull request #110 from mrBliss/fix-103, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 00e5366 224/486: Merge pull request #122 from kraai/remove-duplicate-keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0601540 205/486: Merge pull request #96 from MicahChalmer/add-licenses, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1492106 232/486: Fix hook args for after-revert-hook, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2f42da8 228/486: Add rust-promote-module-into-dir, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0914b48 234/486: Merge pull request #133 from kraai/avoid-cl, ELPA Syncer, 2021/08/07