@@ -357,9 +357,17 @@ is either labeled (C) or not (B).
357
357
(when aot ?
358
358
(resolve - conflicts targets )))))
359
359
360
-
361
- (fn light - up - beacons [targets ?start ?end ]
362
- (for [i (or ?start 1 ) (or ?end (length targets ))]
360
+ (fn with - highlight - chores [opts task ]
361
+ (do (local opts (or opts {}))
362
+ (hl:cleanup opts.hl - affected - windows )
363
+ (hl:apply - backdrop (or opts.backdrop - ranges []))
364
+ (task )
365
+ (hl:highlight - cursor )
366
+ (vim.cmd :redraw)))
367
+
368
+ (fn light - up - beacons [targets opts ]
369
+ (local opts (or opts {}))
370
+ (for [i (or opts.start 1 ) (or opts.end (length targets ))]
363
371
(local target (. targets i ))
364
372
(case target.beacon
365
373
[offset virttext ]
@@ -486,13 +494,29 @@ is either labeled (C) or not (B).
486
494
(when vars.errmsg (echo vars.errmsg ))
487
495
(exit )))
488
496
489
- (macro with - highlight - chores [... ]
490
- `(do (hl:cleanup hl - affected - windows )
491
- (when-not count
492
- (hl:apply - backdrop backward ? ?target - windows ))
493
- (do ,... )
494
- (hl:highlight - cursor )
495
- (vim.cmd :redraw)))
497
+ (local backdrop - ranges [])
498
+ (when (and (pcall api.nvim_get_hl_by_name hl.group.backdrop false ) (not count ))
499
+ (if ?target - windows
500
+ (each [_ winid (ipairs ?target - windows )]
501
+ (local wininfo (. (vim.fn.getwininfo winid ) 1 ))
502
+ (local range {:bufnr wininfo.bufnr
503
+ :startrow (dec wininfo.topline )
504
+ :startcol 0
505
+ :endrow (dec wininfo.botline )
506
+ :endcol -1 })
507
+ (table . insert backdrop - ranges range ))
508
+ (let [[curline curcol ] (map dec [(vim.fn.line "." ) (vim.fn.col "." )])
509
+ [win - top win - bot ] [(dec (vim.fn.line "w0" )) (dec (vim.fn.line "w$" ))]
510
+ [startrow startcol endrow endcol ] (if backward ?
511
+ [win - top 0 curline curcol ]
512
+ [curline (inc curcol ) win - bot -1 ])]
513
+ (local wininfo (. (vim.fn.getwininfo 0 ) 1 ))
514
+ (local range {:bufnr wininfo.bufnr
515
+ :startrow startrow
516
+ :startcol startcol
517
+ :endrow endrow
518
+ :endcol endcol })
519
+ (table . insert backdrop - ranges range ))))
496
520
497
521
; Helper functions ///
498
522
@@ -644,7 +668,7 @@ is either labeled (C) or not (B).
644
668
(values start end ))))
645
669
646
670
(fn get - first - pattern - input []
647
- (with - highlight - chores ( echo "" )) ; clean up the command line
671
+ (with - highlight - chores { : backdrop - ranges : hl - affected - windows } ( fn [] ( echo "" ) )) ; clean up the command line
648
672
(case (get - input - by - keymap prompt )
649
673
; Here we can handle any other modifier key as "zeroth" input,
650
674
; if the need arises.
@@ -663,7 +687,7 @@ is either labeled (C) or not (B).
663
687
; char<enter> partial input (but it implies not needing
664
688
; to show beacons).
665
689
(not count ))
666
- (with - highlight - chores ( light - up - beacons targets )))
690
+ (with - highlight - chores { : backdrop - ranges : hl - affected - windows } ( fn [] ( light - up - beacons targets ) )))
667
691
(get - input - by - keymap prompt ))
668
692
669
693
(fn get - full - pattern - input []
@@ -685,9 +709,8 @@ is either labeled (C) or not (B).
685
709
(when targets.label -set
686
710
(set- label - states targets {: group - offset }))
687
711
(set- beacons targets {:aot? vars.aot ? : no - labels ? : user - given - targets ?})
688
- (with - highlight - chores
689
- (local (start end ) (get - highlighted - idx - range targets no - labels ?))
690
- (light - up - beacons targets start end )))
712
+ (local (start end ) (get - highlighted - idx - range targets no - labels ?))
713
+ (with - highlight - chores {: backdrop - ranges : hl - affected - windows } (fn [] (light - up - beacons targets {: start : end }))))
691
714
; ---
692
715
(fn loop [group - offset first - invoc ?]
693
716
(display group - offset )
@@ -751,9 +774,8 @@ is either labeled (C) or not (B).
751
774
; ---
752
775
(fn display []
753
776
(set- beacons targets {: no - labels ? :aot? vars.aot ? : user - given - targets ?})
754
- (with - highlight - chores
755
- (local (start end ) (get - highlighted - idx - range targets no - labels ?))
756
- (light - up - beacons targets start end )))
777
+ (local (start end ) (get - highlighted - idx - range targets no - labels ?))
778
+ (with - highlight - chores {: backdrop - ranges : hl - affected - windows } (fn [] (light - up - beacons targets {: start : end }))))
757
779
; ---
758
780
(fn get - new - idx [idx in ]
759
781
(if (contains ? spec - keys.next_target in ) (min (inc idx ) (length targets ))
@@ -865,7 +887,7 @@ is either labeled (C) or not (B).
865
887
targets **
866
888
; The action callback should expect a list in this case.
867
889
; It might also get user input, so keep the beacons highlighted.
868
- (do (with - highlight - chores ( light - up - beacons targets ** ))
890
+ (do (with - highlight - chores { : backdrop - ranges : hl - affected - windows } ( fn [] ( light - up - beacons targets ** ) ))
869
891
(do- action targets ** )))
870
892
(exit ))
871
893
0 commit comments