File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -1025,6 +1025,43 @@ All positions are position symbols found in `rust-test-positions-alist'."
1025
1025
'beginning-of-fn3
1026
1026
#'beginning-of-defun ))
1027
1027
1028
+ (ert-deftest rust-beginning-of-defun-string-comment ()
1029
+ (let (fn-1 fn-2 p-1 p-2)
1030
+ (with-temp-buffer
1031
+ (rust-mode )
1032
+ (insert " fn test1() {
1033
+ let s=r#\"
1034
+ fn test2();
1035
+ \" #;" )
1036
+ (setq p-1 (point ))
1037
+ (setq fn-1 (1+ p-1))
1038
+ (insert "
1039
+ fn test3() {
1040
+ /*
1041
+ fn test4();" )
1042
+ (setq p-2 (point ))
1043
+ (insert " \n */\n }\n " )
1044
+ (setq fn-2 (point ))
1045
+ (insert " fn test5() { }" )
1046
+
1047
+ (goto-char p-1)
1048
+ (beginning-of-defun )
1049
+ (should (eq (point ) (point-min )))
1050
+
1051
+ (beginning-of-defun -2 )
1052
+ (should (eq (point ) fn-2))
1053
+
1054
+ (goto-char p-2)
1055
+ (beginning-of-defun )
1056
+ (should (eq (point ) fn-1))
1057
+
1058
+ (beginning-of-defun -1 )
1059
+ (should (eq (point ) fn-2))
1060
+
1061
+ (goto-char (point-max ))
1062
+ (beginning-of-defun 2 )
1063
+ (should (eq (point ) fn-1)))))
1064
+
1028
1065
(ert-deftest rust-end-of-defun-from-middle-of-fn ()
1029
1066
(rust-test-motion
1030
1067
rust-test-motion-string
Original file line number Diff line number Diff line change @@ -1198,8 +1198,22 @@ This is written mainly to be used as `beginning-of-defun-function' for Rust.
1198
1198
Don't move to the beginning of the line. `beginning-of-defun' ,
1199
1199
which calls this, does that afterwards."
1200
1200
(interactive " p" )
1201
- (re-search-backward (concat " ^\\ (" rust-top-item-beg-re " \\ )" )
1202
- nil 'move (or arg 1 )))
1201
+ (let* ((arg (or arg 1 ))
1202
+ (magnitude (abs arg))
1203
+ (sign (if (< arg 0 ) -1 1 )))
1204
+ ; ; If moving forward, don't find the defun we might currently be
1205
+ ; ; on.
1206
+ (when (< sign 0 )
1207
+ (end-of-line ))
1208
+ (catch 'done
1209
+ (dotimes (_ magnitude)
1210
+ ; ; Search until we find a match that is not in a string or comment.
1211
+ (while (if (re-search-backward (concat " ^\\ (" rust-top-item-beg-re " \\ )" )
1212
+ nil 'move sign)
1213
+ (rust-in-str-or-cmnt)
1214
+ ; ; Did not find it.
1215
+ (throw 'done nil )))))
1216
+ t ))
1203
1217
1204
1218
(defun rust-end-of-defun ()
1205
1219
" Move forward to the next end of defun.
You can’t perform that action at this time.
0 commit comments