[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 1d4a75f 324/486: Make rust-beginning-of-defun ig
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 1d4a75f 324/486: Make rust-beginning-of-defun ignore comments and strings |
Date: |
Sat, 7 Aug 2021 09:25:45 -0400 (EDT) |
branch: elpa/rust-mode
commit 1d4a75f84865356a3cf6dbc1b0b32ec43496446e
Author: Tom Tromey <tom@tromey.com>
Commit: Tom Tromey <tom@tromey.com>
Make rust-beginning-of-defun ignore comments and strings
Change rust-beginning-of-defun to keep searching when it stops in a
comment or a string. Fixes #222.
---
rust-mode-tests.el | 37 +++++++++++++++++++++++++++++++++++++
rust-mode.el | 18 ++++++++++++++++--
2 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 7f1020f..de8a2cc 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -1025,6 +1025,43 @@ All positions are position symbols found in
`rust-test-positions-alist'."
'beginning-of-fn3
#'beginning-of-defun))
+(ert-deftest rust-beginning-of-defun-string-comment ()
+ (let (fn-1 fn-2 p-1 p-2)
+ (with-temp-buffer
+ (rust-mode)
+ (insert "fn test1() {
+ let s=r#\"
+fn test2();
+\"#;")
+ (setq p-1 (point))
+ (setq fn-1 (1+ p-1))
+ (insert "
+fn test3() {
+ /*
+fn test4();")
+ (setq p-2 (point))
+ (insert "\n*/\n}\n")
+ (setq fn-2 (point))
+ (insert "fn test5() { }")
+
+ (goto-char p-1)
+ (beginning-of-defun)
+ (should (eq (point) (point-min)))
+
+ (beginning-of-defun -2)
+ (should (eq (point) fn-2))
+
+ (goto-char p-2)
+ (beginning-of-defun)
+ (should (eq (point) fn-1))
+
+ (beginning-of-defun -1)
+ (should (eq (point) fn-2))
+
+ (goto-char (point-max))
+ (beginning-of-defun 2)
+ (should (eq (point) fn-1)))))
+
(ert-deftest rust-end-of-defun-from-middle-of-fn ()
(rust-test-motion
rust-test-motion-string
diff --git a/rust-mode.el b/rust-mode.el
index 46231fd..33e6b28 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -1198,8 +1198,22 @@ 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 "\\)")
- nil 'move (or arg 1)))
+ (let* ((arg (or arg 1))
+ (magnitude (abs arg))
+ (sign (if (< arg 0) -1 1)))
+ ;; If moving forward, don't find the defun we might currently be
+ ;; on.
+ (when (< sign 0)
+ (end-of-line))
+ (catch 'done
+ (dotimes (_ magnitude)
+ ;; Search until we find a match that is not in a string or comment.
+ (while (if (re-search-backward (concat "^\\(" rust-top-item-beg-re
"\\)")
+ nil 'move sign)
+ (rust-in-str-or-cmnt)
+ ;; Did not find it.
+ (throw 'done nil)))))
+ t))
(defun rust-end-of-defun ()
"Move forward to the next end of defun.
- [nongnu] elpa/rust-mode 6886300 256/486: [master] Copy buffer only when format changes., (continued)
- [nongnu] elpa/rust-mode 6886300 256/486: [master] Copy buffer only when format changes., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e452995 261/486: rust--after-revert-hook should preserve point position., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d2e57a9 263/486: fix regex to account for `[E123]`, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bec3d0c 267/486: Test #169, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7fb78d4 273/486: Bump version, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f6cf013 275/486: Add instructions for version tag update requests, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4935090 279/486: convert http links into https links, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b8126e4 284/486: Recognize "extern" imenu items, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a436945 294/486: Merge pull request #172 from nokaa/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 954221f 316/486: Define `rust-test-project-located' conditionally instead of using `skip-unless'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1d4a75f 324/486: Make rust-beginning-of-defun ignore comments and strings,
ELPA Syncer <=
- [nongnu] elpa/rust-mode dea81aa 334/486: Types get correct font-lock in if-let statements, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ac5dac0 335/486: Added test for if-let font lock, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6550d94 336/486: Renamed and relocated if-let font-lock test, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a814cd8 338/486: Pass 'visible to get-buffer-window, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c8280ae 339/486: Merge pull request #235 from tromey/get-buffer-window-fixlet, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fca71c6 342/486: feat(rust-mode): add yield to the keywords list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode eae291a 343/486: Merge pull request #240 from michael-zapata/feat/add-yield-keyword, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b7cd368 346/486: % as punctuation character., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 04e3078 347/486: Merge pull request #244 from kubo39/percent-as-punctuation-character, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b911835 356/486: Merge pull request #262 from kngwyu/highlight-dyn, ELPA Syncer, 2021/08/07