@@ -218,6 +218,21 @@ function or trait. When nil, where will be aligned with fn or trait."
218
218
(rust-in-macro))
219
219
)))
220
220
221
+ (defun rust-looking-at-where ()
222
+ " Return T when looking at the \" where\" keyword."
223
+ (and (looking-at-p " \\ bwhere\\ b" )
224
+ (not (rust-in-str-or-cmnt))))
225
+
226
+ (defun rust-rewind-to-where (&optional limit )
227
+ " Rewind the point to the closest occurrence of the \" where\" keyword.
228
+ Return T iff a where-clause was found. Does not rewind past
229
+ LIMIT when passed, otherwise only stops at the beginning of the
230
+ buffer."
231
+ (when (re-search-backward " \\ bwhere\\ b" limit t )
232
+ (if (rust-in-str-or-cmnt)
233
+ (rust-rewind-to-where limit)
234
+ t )))
235
+
221
236
(defun rust-align-to-expr-after-brace ()
222
237
(save-excursion
223
238
(forward-char )
@@ -248,12 +263,12 @@ function or trait. When nil, where will be aligned with fn or trait."
248
263
(setq function-start (point )
249
264
function-level (rust-paren-level)))
250
265
; ; On a where clause
251
- (when (or (looking-at " \\ bwhere \\ b " )
266
+ (when (or (rust- looking-at-where )
252
267
; ; or in one of the following lines, e.g.
253
268
; ; where A: Eq
254
269
; ; B: Hash <- on this line
255
270
(and (save-excursion
256
- (re-search-backward " \\ bwhere \\ b " function-start t ))
271
+ (rust-rewind-to-where function-start))
257
272
(= current-level function-level)))
258
273
(goto-char function-start)))))
259
274
@@ -392,7 +407,8 @@ function or trait. When nil, where will be aligned with fn or trait."
392
407
393
408
; ; When the user chose not to indent the start of the where
394
409
; ; clause, put it on the baseline.
395
- ((and (not rust-indent-where-clause) (looking-at " \\ bwhere\\ b" ))
410
+ ((and (not rust-indent-where-clause)
411
+ (rust-looking-at-where))
396
412
baseline)
397
413
398
414
; ; If we're in any other token-tree / sexp, then:
@@ -425,17 +441,16 @@ function or trait. When nil, where will be aligned with fn or trait."
425
441
; ; When we're not on a line starting with "where ", but
426
442
; ; still on a where-clause line, go to "where "
427
443
(when (and
428
- (not (looking-at " \\ bwhere \\ b " ))
444
+ (not (rust- looking-at-where ))
429
445
; ; We're looking at something like "F: ..."
430
- (and (looking-at (concat rust-re-ident " :" ))
431
- ; ; There is a "where " somewhere after the
432
- ; ; start of the function.
433
- (re-search-backward " \\ bwhere\\ b"
434
- function-start t )
435
- ; ; Make sure we're not inside the function
436
- ; ; already (e.g. initializing a struct) by
437
- ; ; checking we are the same level.
438
- (= function-level level)))
446
+ (looking-at (concat rust-re-ident " :" ))
447
+ ; ; There is a "where " somewhere after the
448
+ ; ; start of the function.
449
+ (rust-rewind-to-where function-start)
450
+ ; ; Make sure we're not inside the function
451
+ ; ; already (e.g. initializing a struct) by
452
+ ; ; checking we are the same level.
453
+ (= function-level level))
439
454
; ; skip over "where"
440
455
(forward-char 5 )
441
456
; ; Unless "where" is at the end of the line
0 commit comments