[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode afeddec 325/486: Merge pull request #224 from tr
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode afeddec 325/486: Merge pull request #224 from tromey/beginning-of-defun |
Date: |
Sat, 7 Aug 2021 09:25:45 -0400 (EDT) |
branch: elpa/rust-mode
commit afeddec5a4755418cde1537364cfc30ae280354e
Merge: 30a9d39 1d4a75f
Author: Tom Tromey <tom@tromey.com>
Commit: GitHub <noreply@github.com>
Merge pull request #224 from tromey/beginning-of-defun
Make rust-beginning-of-defun ignore comments and strings
---
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 494d59f 486/486: Make most additional libraries optional, (continued)
- [nongnu] elpa/rust-mode 494d59f 486/486: Make most additional libraries optional, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9f3d8cf 432/486: rust format buffer now saves position across multiple frames (#348), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6f1abc3 438/486: Expand README to include more information about features (#358), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e04e485 441/486: rustc-compilation-regexps: handle `note` case as compilation-info., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 39f32cc 447/486: In emacs >= 26.2, use replace-buffer-contents after formatting, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode eca55c0 451/486: Check for -> and => early in rust-ordinary-lt-gt-p, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ca7d99c 469/486: Set default directory when compiling., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c5c7ed3 471/486: Update README.md, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4e394ac 475/486: Add Makefile, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 09b4320 476/486: test: Suppress some noisy messages, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode afeddec 325/486: Merge pull request #224 from tromey/beginning-of-defun,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 7fd78f0 444/486: rust-goto-format-problem: make sure to always just to a buffer that exists., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9e03890 478/486: Create rust-compile.el from existing code, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 41642f0 481/486: rust-end-of-string: Move definition, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d548425 483/486: Create rust-playpen.el from existing code, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode eb5270b 437/486: rust-before-save-hook: log errors., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2df6cf7 439/486: Don't fail on re-search-forward. (#359), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ca415e9 470/486: Add rust-check function, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e327658 274/486: Merge pull request #178 from ryuslash/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7e2533f 415/486: Fix rustc-compilation-regexps: match error messages with dashes. (#331), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9107989 424/486: review, ELPA Syncer, 2021/08/07