summaryrefslogtreecommitdiff
path: root/rust-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'rust-mode.el')
-rw-r--r--rust-mode.el18
1 files changed, 16 insertions, 2 deletions
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.