[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode b23efef 249/486: Merge pull request #153 from mr
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode b23efef 249/486: Merge pull request #153 from mrBliss/fix-151 |
Date: |
Sat, 7 Aug 2021 09:25:29 -0400 (EDT) |
branch: elpa/rust-mode
commit b23efef0b6a6a632b70c1db5579a835059239e4c
Merge: ed0b390 eafb7a0
Author: Micah Chalmer <micah@micahchalmer.net>
Commit: Micah Chalmer <micah@micahchalmer.net>
Merge pull request #153 from mrBliss/fix-151
Fix #151
---
rust-mode-tests.el | 32 ++++++++++++++++++++++++++++++++
rust-mode.el | 41 ++++++++++++++++++++++++++++-------------
2 files changed, 60 insertions(+), 13 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index de3900c..1e60768 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -623,6 +623,38 @@ impl<'a, K, Q: ?Sized, V, S> Index<&'a Q> for HashMap<K,
V, S>
}
"))
+(ert-deftest indent-align-where-in-comment1 ()
+ (test-indent
+ "/// - there must not exist an edge U->V in the graph where:
+#[derive(Clone, PartialEq, Eq)]
+pub struct Region { // <-- this should be flush with left margin!
+ entry: BasicBlockIndex,
+ leaves: BTreeMap<BasicBlockIndex, usize>,
+}
+"))
+
+(ert-deftest indent-align-where-in-comment2 ()
+ (test-indent
+ "fn foo<F,G>(f:F, g:G)
+ where F:Send,
+// where
+ G:Sized
+{
+ let body;
+}
+"))
+
+(ert-deftest indent-align-where-in-comment3 ()
+ (test-indent
+ "fn foo<F,G>(f:F, g:G)
+ where F:Send,
+// where F:ThisIsNotActualCode,
+ G:Sized
+{
+ let body;
+}
+"))
+
(ert-deftest indent-square-bracket-alignment ()
(test-indent
"
diff --git a/rust-mode.el b/rust-mode.el
index 647e6b1..df7e93c 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -218,6 +218,21 @@ function or trait. When nil, where will be aligned with
fn or trait."
(rust-in-macro))
)))
+(defun rust-looking-at-where ()
+ "Return T when looking at the \"where\" keyword."
+ (and (looking-at-p "\\bwhere\\b")
+ (not (rust-in-str-or-cmnt))))
+
+(defun rust-rewind-to-where (&optional limit)
+ "Rewind the point to the closest occurrence of the \"where\" keyword.
+Return T iff a where-clause was found. Does not rewind past
+LIMIT when passed, otherwise only stops at the beginning of the
+buffer."
+ (when (re-search-backward "\\bwhere\\b" limit t)
+ (if (rust-in-str-or-cmnt)
+ (rust-rewind-to-where limit)
+ t)))
+
(defun rust-align-to-expr-after-brace ()
(save-excursion
(forward-char)
@@ -248,12 +263,12 @@ function or trait. When nil, where will be aligned with
fn or trait."
(setq function-start (point)
function-level (rust-paren-level)))
;; On a where clause
- (when (or (looking-at "\\bwhere\\b")
+ (when (or (rust-looking-at-where)
;; or in one of the following lines, e.g.
;; where A: Eq
;; B: Hash <- on this line
(and (save-excursion
- (re-search-backward "\\bwhere\\b" function-start t))
+ (rust-rewind-to-where function-start))
(= current-level function-level)))
(goto-char function-start)))))
@@ -392,7 +407,8 @@ function or trait. When nil, where will be aligned with fn
or trait."
;; When the user chose not to indent the start of the where
;; clause, put it on the baseline.
- ((and (not rust-indent-where-clause) (looking-at "\\bwhere\\b"))
+ ((and (not rust-indent-where-clause)
+ (rust-looking-at-where))
baseline)
;; If we're in any other token-tree / sexp, then:
@@ -425,17 +441,16 @@ function or trait. When nil, where will be aligned with
fn or trait."
;; When we're not on a line starting with "where ", but
;; still on a where-clause line, go to "where "
(when (and
- (not (looking-at "\\bwhere\\b"))
+ (not (rust-looking-at-where))
;; We're looking at something like "F: ..."
- (and (looking-at (concat rust-re-ident ":"))
- ;; There is a "where " somewhere after the
- ;; start of the function.
- (re-search-backward "\\bwhere\\b"
- function-start t)
- ;; Make sure we're not inside the function
- ;; already (e.g. initializing a struct) by
- ;; checking we are the same level.
- (= function-level level)))
+ (looking-at (concat rust-re-ident ":"))
+ ;; There is a "where " somewhere after the
+ ;; start of the function.
+ (rust-rewind-to-where function-start)
+ ;; Make sure we're not inside the function
+ ;; already (e.g. initializing a struct) by
+ ;; checking we are the same level.
+ (= function-level level))
;; skip over "where"
(forward-char 5)
;; Unless "where" is at the end of the line
- [nongnu] elpa/rust-mode beec95a 231/486: Allow disabling rustfmt with a dir-local/file-local variable, (continued)
- [nongnu] elpa/rust-mode beec95a 231/486: Allow disabling rustfmt with a dir-local/file-local variable, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6739dd9 226/486: Merge pull request #123 from birkenfeld/fix-unicode-char-escapes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f408b06 227/486: Run the after-revert hook after rustfmt, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bc0df03 235/486: Merge pull request #135 from Stebalien/file-local, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9812232 236/486: Document how to install on Debian, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bfe24d2 237/486: Merge pull request #132 from tomjakubowski/move-module, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1c37249 238/486: Merge pull request #136 from Stebalien/indent-brace, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bd44088 239/486: Merge pull request #138 from kraai/upstream, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 18fad39 242/486: Merge pull request #142 from tromey/remove-emacs-23-support, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode eafb7a0 248/486: Properly fix #151, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b23efef 249/486: Merge pull request #153 from mrBliss/fix-151,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 4fce178 251/486: Merge pull request #154 from nikomatsakis/new-errors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e6eceea 253/486: Add macro_rules names to imenu, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5cfb919 265/486: Merge pull request #165 from nikomatsakis/new-errors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 01ac5d8 272/486: Merge pull request #177 from mrBliss/handle-comments-method-chains, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c091852 283/486: Merge pull request #180 from MicahChalmer/melpa-stable-readme, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8039d12 286/486: Merge pull request #191 from Wooble/readme_link, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0de149a 287/486: Merge pull request #190 from mrBliss/imenu-extern, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ee7043b 289/486: Use syntax-propertize-function, not font-lock-syntactic-keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d7458c2 290/486: set open-paren-in-column-0-is-defun-start to nil, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4d651ab 295/486: Merge pull request #197 from tromey/syntax-propertize, ELPA Syncer, 2021/08/07