35
35
(defconst rust-re-unsafe " unsafe" )
36
36
(defconst rust-re-extern " extern" )
37
37
38
+ ; ;; Start of a Rust item
39
+ (defvar rust-top-item-beg-re
40
+ (concat " \\ s-*\\ (?:priv\\ |pub\\ )?\\ s-*"
41
+ (regexp-opt
42
+ '(" enum" " struct" " type" " mod" " use" " fn" " static" " impl"
43
+ " extern" " trait" ))
44
+ " \\ _>" ))
45
+
38
46
(defun rust-looking-back-str (str )
39
47
" Like `looking-back' but for fixed strings rather than regexps (so that it's not so slow)"
40
48
(let ((len (length str)))
@@ -394,6 +402,10 @@ buffer."
394
402
; ; our search for "where ".
395
403
(let ((function-start nil ) (function-level nil ))
396
404
(save-excursion
405
+ ; ; If we're already at the start of a function,
406
+ ; ; don't go back any farther. We can easily do
407
+ ; ; this by moving to the end of the line first.
408
+ (end-of-line )
397
409
(rust-beginning-of-defun)
398
410
(back-to-indentation )
399
411
; ; Avoid using multiple-value-bind
@@ -437,6 +449,10 @@ buffer."
437
449
; ; baseline as well.
438
450
(looking-at " \\ <else\\ >\\ |{\\ |/[/*]" )
439
451
452
+ ; ; If this is the start of a top-level item,
453
+ ; ; stay on the baseline.
454
+ (looking-at rust-top-item-beg-re)
455
+
440
456
(save-excursion
441
457
(rust-rewind-irrelevant)
442
458
; ; Point is now at the end of the previous line
@@ -1136,13 +1152,6 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
1136
1152
1137
1153
; ;; Defun Motions
1138
1154
1139
- ; ;; Start of a Rust item
1140
- (defvar rust-top-item-beg-re
1141
- (concat " ^\\ s-*\\ (?:priv\\ |pub\\ )?\\ s-*"
1142
- (regexp-opt
1143
- '(" enum" " struct" " type" " mod" " use" " fn" " static" " impl"
1144
- " extern" " trait" ))))
1145
-
1146
1155
(defun rust-beginning-of-defun (&optional arg )
1147
1156
" Move backward to the beginning of the current defun.
1148
1157
@@ -1153,7 +1162,7 @@ This is written mainly to be used as `beginning-of-defun-function' for Rust.
1153
1162
Don't move to the beginning of the line. `beginning-of-defun' ,
1154
1163
which calls this, does that afterwards."
1155
1164
(interactive " p" )
1156
- (re-search-backward (concat " ^\\ (" rust-top-item-beg-re " \\ )\\ _> " )
1165
+ (re-search-backward (concat " ^\\ (" rust-top-item-beg-re " \\ )" )
1157
1166
nil 'move (or arg 1 )))
1158
1167
1159
1168
(defun rust-end-of-defun ()
0 commit comments