@@ -357,14 +357,37 @@ is either labeled (C) or not (B).
357
357
(when aot ?
358
358
(resolve - conflicts targets )))))
359
359
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 []))
360
+ ; State that is persisted between the API invocations of a single usage.
361
+ (local target - state {:backdrop-ranges nil
362
+ :hl-affected-windows nil
363
+ })
364
+
365
+
366
+ (fn with - highlight - chores [task ]
367
+ (do (local hl - affected - windows (or target - state.hl - affected - windows []))
368
+ (local backdrop - ranges (or target - state.backdrop - ranges []))
369
+ (hl:cleanup (or hl - affected - windows []))
370
+ (hl:apply - backdrop (or backdrop - ranges []))
364
371
(task )
365
372
(hl:highlight - cursor )
366
373
(vim.cmd :redraw)))
367
374
375
+ (fn pre - exit []
376
+ (set target - state.hl - affected - windows nil )
377
+ (set target - state.backdrop - ranges nil ))
378
+
379
+ (macro exit []
380
+ `(do (hl:cleanup target - state.hl - affected - windows )
381
+ (pre - exit )
382
+ (exec - user - autocmds :LeapLeave)
383
+ (lua :return)))
384
+
385
+ (fn prebeacon [opts ]
386
+ (set target - state.backdrop - ranges opts.backdrop - ranges )
387
+ (set target - state.hl - affected - windows opts.hl - affected - windows )
388
+ (with - highlight - chores (fn []))
389
+ )
390
+
368
391
(fn light - up - beacons [targets opts ]
369
392
(local opts (or opts {}))
370
393
(for [i (or opts.start 1 ) (or opts.end (length targets ))]
@@ -400,12 +423,6 @@ is either labeled (C) or not (B).
400
423
:offset nil }
401
424
:saved_editor_opts {}})
402
425
403
- ; State that is persisted between the API invocations of a single usage
404
- (local target - state {:backdrop-ranges nil
405
- :hl-affected-windows nil
406
- })
407
-
408
-
409
426
(fn leap [kwargs ]
410
427
"Entry point for Leap motions."
411
428
(local {:dot_repeat dot - repeat ?
@@ -487,11 +504,6 @@ is either labeled (C) or not (B).
487
504
488
505
; Macros
489
506
490
- (macro exit []
491
- `(do (hl:cleanup hl - affected - windows )
492
- (exec - user - autocmds :LeapLeave)
493
- (lua :return)))
494
-
495
507
; Be sure not to call the macro twice accidentally,
496
508
; `handle-interrupted-change-op!` moves the cursor!
497
509
(macro exit - early []
@@ -673,7 +685,7 @@ is either labeled (C) or not (B).
673
685
(values start end ))))
674
686
675
687
(fn get - first - pattern - input []
676
- (with - highlight - chores { : backdrop - ranges : hl - affected - windows } (fn [] (echo "" ))) ; clean up the command line
688
+ (with - highlight - chores (fn [] (echo "" ))) ; clean up the command line
677
689
(case (get - input - by - keymap prompt )
678
690
; Here we can handle any other modifier key as "zeroth" input,
679
691
; if the need arises.
@@ -692,7 +704,7 @@ is either labeled (C) or not (B).
692
704
; char<enter> partial input (but it implies not needing
693
705
; to show beacons).
694
706
(not count ))
695
- (with - highlight - chores { : backdrop - ranges : hl - affected - windows } (fn [] (light - up - beacons targets ))))
707
+ (with - highlight - chores (fn [] (light - up - beacons targets ))))
696
708
(get - input - by - keymap prompt ))
697
709
698
710
(fn get - full - pattern - input []
@@ -715,7 +727,7 @@ is either labeled (C) or not (B).
715
727
(set- label - states targets {: group - offset }))
716
728
(set- beacons targets {:aot? vars.aot ? : no - labels ? : user - given - targets ?})
717
729
(local (start end ) (get - highlighted - idx - range targets no - labels ?))
718
- (with - highlight - chores { : backdrop - ranges : hl - affected - windows } (fn [] (light - up - beacons targets {: start : end }))))
730
+ (with - highlight - chores (fn [] (light - up - beacons targets {: start : end }))))
719
731
; ---
720
732
(fn loop [group - offset first - invoc ?]
721
733
(display group - offset )
@@ -780,7 +792,7 @@ is either labeled (C) or not (B).
780
792
(fn display []
781
793
(set- beacons targets {: no - labels ? :aot? vars.aot ? : user - given - targets ?})
782
794
(local (start end ) (get - highlighted - idx - range targets no - labels ?))
783
- (with - highlight - chores { : backdrop - ranges : hl - affected - windows } (fn [] (light - up - beacons targets {: start : end }))))
795
+ (with - highlight - chores (fn [] (light - up - beacons targets {: start : end }))))
784
796
; ---
785
797
(fn get - new - idx [idx in ]
786
798
(if (contains ? spec - keys.next_target in ) (min (inc idx ) (length targets ))
@@ -817,6 +829,8 @@ is either labeled (C) or not (B).
817
829
818
830
(exec - user - autocmds :LeapEnter)
819
831
832
+ (prebeacon {: backdrop - ranges : hl - affected - windows })
833
+
820
834
(local (in1 ?in2 ) (if dot - repeat ? (if state.dot_repeat.callback
821
835
(values true true )
822
836
(values state.dot_repeat.in1
@@ -892,7 +906,7 @@ is either labeled (C) or not (B).
892
906
targets **
893
907
; The action callback should expect a list in this case.
894
908
; It might also get user input, so keep the beacons highlighted.
895
- (do (with - highlight - chores { : backdrop - ranges : hl - affected - windows } (fn [] (light - up - beacons targets ** )))
909
+ (do (with - highlight - chores (fn [] (light - up - beacons targets ** )))
896
910
(do- action targets ** )))
897
911
(exit ))
898
912
0 commit comments