File tree 2 files changed +39
-10
lines changed
2 files changed +39
-10
lines changed Original file line number Diff line number Diff line change @@ -3449,14 +3449,32 @@ impl Two<'a> {
3449
3449
" Foo" font-lock-type-face
3450
3450
" in" font-lock-keyword-face )))
3451
3451
3452
- (ert-deftest rust-test-dbg-wrap-symbol ()
3452
+ (ert-deftest rust-test-dbg-wrap-sexp ()
3453
+ " a valid sexp ahead of current pos"
3453
3454
(rust-test-manip-code
3454
3455
" let x = add(first, second);"
3455
3456
15
3456
3457
#'rust-dbg-wrap-or-unwrap
3457
3458
" let x = add(dbg!(first), second);"
3458
3459
24 ))
3459
3460
3461
+ (ert-deftest rust-test-dbg-wrap-sexp-fallback ()
3462
+ " a invalid sexp ahead of current pos"
3463
+ ; ; inside
3464
+ (rust-test-manip-code
3465
+ " if let Ok(val) = may_val {}"
3466
+ 27
3467
+ #'rust-dbg-wrap-or-unwrap
3468
+ " if let Ok(val) = may_val {dbg!()}"
3469
+ 32 )
3470
+ ; ; before
3471
+ (rust-test-manip-code
3472
+ " let a = {}"
3473
+ 9
3474
+ #'rust-dbg-wrap-or-unwrap
3475
+ " let a = dbg!({})"
3476
+ 17 ))
3477
+
3460
3478
(ert-deftest rust-test-dbg-wrap-empty-line ()
3461
3479
(rust-test-manip-code
3462
3480
" let a = 1;
Original file line number Diff line number Diff line change @@ -36,16 +36,27 @@ visit the new file."
36
36
37
37
; ;; dbg! macro
38
38
39
- (defun rust-insert-dbg ()
40
- " Insert the dbg! macro. Move cursor to the end of macro."
39
+ (defun rust-insert-dbg-sexp ()
40
+ " Insert the dbg! macro around a sexp if possible, insert at current position
41
+ if not. Move cursor to the end of macro."
41
42
(when (rust-in-str)
42
43
(up-list -1 t t ))
43
- (insert " (" )
44
- (forward-sexp )
45
- (insert " )" )
46
- (backward-sexp )
47
- (insert " dbg!" )
48
- (forward-sexp ))
44
+ (setq safe-to-forward t )
45
+ (save-excursion
46
+ (condition-case nil
47
+ (forward-sexp )
48
+ (error (setq safe-to-forward nil )
49
+ nil )))
50
+ (cond
51
+ ((not safe-to-forward)
52
+ (rust-insert-dbg-alone))
53
+ (t
54
+ (insert " (" )
55
+ (forward-sexp )
56
+ (insert " )" )
57
+ (backward-sexp )
58
+ (insert " dbg!" )
59
+ (forward-sexp ))))
49
60
50
61
(defun rust-insert-dbg-region ()
51
62
" Insert the dbg! macro around a region. Move cursor to the end of macro."
@@ -93,7 +104,7 @@ visit the new file."
93
104
(goto-char dbg-point)
94
105
(delete-char -4 )
95
106
(delete-pair ))
96
- (t (rust-insert-dbg)))))
107
+ (t (rust-insert-dbg-sexp )))))
97
108
)
98
109
)
99
110
You can’t perform that action at this time.
0 commit comments