Skip to content

Commit fd834e6

Browse files
committed
genericize set-beacon-for-labeled
1 parent 1340684 commit fd834e6

File tree

2 files changed

+269
-252
lines changed

2 files changed

+269
-252
lines changed

fnl/leap/main.fnl

+33-19
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,16 @@ char separately.
196196
(+ (ch1:len) (ch2:len)))))
197197

198198

199-
(fn set-beacon-for-labeled [target {: user-given-targets? : aot?}]
200-
(let [offset (if aot? (get-label-offset target) 0) ; user-given-targets implies (not aot)
201-
pad (if (or user-given-targets? aot?) "" " ")
199+
(fn set-beacon-for-labeled [target]
200+
(let [offset (or target.beacon-offset 0) ; user-given-targets implies (not aot)
201+
pad (or target.pad "")
202202
label (or (. opts.substitute_chars target.label) target.label)
203-
text (.. label pad)
203+
text (or target.text (.. label pad))
204204
virttext (case target.label-state
205205
:selected [[text hl.group.label-selected]]
206206
:active-primary [[text hl.group.label-primary]]
207207
:active-secondary [[text hl.group.label-secondary]]
208-
:inactive (if (and aot? (not opts.highlight_unlabeled_phase_one_targets))
209-
; In this case, "no highlight" should
210-
; unambiguously signal "no further keystrokes
211-
; needed", so it is mandatory to show all labeled
212-
; positions in some way.
213-
[[(.. " " pad) hl.group.label-secondary]]
214-
:else nil))]
208+
:inactive (if target.text [[target.text hl.group.label-secondary]] :else nil))]
215209
(set target.beacon (when virttext [offset virttext]))))
216210

217211

@@ -344,13 +338,13 @@ is either labeled (C) or not (B).
344338
other (set-beacon-to-match-hl target)))))))))
345339

346340

347-
(fn set-beacons [targets {: no-labels? : user-given-targets? : aot?}]
341+
(fn set-beacons [targets {: no-labels? : aot?}]
348342
(if (and no-labels? (. targets 1 :chars)) ; user-given targets might not have :chars
349343
(each [_ target (ipairs targets)]
350344
(set-beacon-to-match-hl target))
351345
(do (each [_ target (ipairs targets)]
352346
(if target.label
353-
(set-beacon-for-labeled target {: user-given-targets? : aot?})
347+
(set-beacon-for-labeled target)
354348

355349
(and aot? opts.highlight_unlabeled_phase_one_targets)
356350
(set-beacon-to-match-hl target)))
@@ -502,6 +496,12 @@ is either labeled (C) or not (B).
502496
:curr-idx 0 ; for traversal mode
503497
:errmsg nil})
504498

499+
(macro aot-finish []
500+
`(do
501+
(set vars.aot? false)
502+
(each [_ target (ipairs targets)]
503+
(set target.beacon-offset 0))))
504+
505505
; Macros
506506

507507
; Be sure not to call the macro twice accidentally,
@@ -725,7 +725,7 @@ is either labeled (C) or not (B).
725725
; setting the initial label states if using `spec-keys.repeat_search`.
726726
(when targets.label-set
727727
(set-label-states targets {: group-offset}))
728-
(set-beacons targets {:aot? vars.aot? : no-labels? : user-given-targets?})
728+
(set-beacons targets {:aot? vars.aot? : no-labels?})
729729
(local (start end) (get-highlighted-idx-range targets no-labels?))
730730
(with-highlight-chores (fn [] (light-up-beacons targets {: start : end}))))
731731
; ---
@@ -790,7 +790,7 @@ is either labeled (C) or not (B).
790790
(doto (. targets i) (tset :label nil) (tset :beacon nil))))))
791791
; ---
792792
(fn display []
793-
(set-beacons targets {: no-labels? :aot? vars.aot? : user-given-targets?})
793+
(set-beacons targets {: no-labels? :aot? vars.aot?})
794794
(local (start end) (get-highlighted-idx-range targets no-labels?))
795795
(with-highlight-chores (fn [] (light-up-beacons targets {: start : end}))))
796796
; ---
@@ -864,13 +864,27 @@ is either labeled (C) or not (B).
864864
(prepare-targets targets))
865865
(do
866866
(when (> (length targets) max-phase-one-targets)
867-
(set vars.aot? false))
867+
(do
868+
(set vars.aot? false)
869+
(each [_ target (ipairs targets)]
870+
(set target.beacon-offset 0))))
868871
(populate-sublists targets)
869872
(each [_ sublist (pairs targets.sublists)]
870873
(prepare-targets sublist))
871-
(doto targets
872-
(set-initial-label-states)
873-
(set-beacons {:aot? vars.aot?}))))
874+
(set-initial-label-states targets)
875+
(each [_ target (ipairs targets)]
876+
(if vars.aot?
877+
(do
878+
(set target.beacon-offset (get-label-offset target))
879+
(when (and (not opts.highlight_unlabeled_phase_one_targets) (= target.label-state :inactive))
880+
; In this case, "no highlight" should
881+
; unambiguously signal "no further keystrokes
882+
; needed", so it is mandatory to show all labeled
883+
; positions in some way.
884+
(set target.text " ")
885+
))
886+
(when (not user-given-targets?) (set target.pad " "))))
887+
(set-beacons {:aot? vars.aot?} targets)))
874888
(local in2 (or ?in2 (get-second-pattern-input targets))) ; REDRAW
875889
(when-not in2
876890
(exit-early))

0 commit comments

Comments
 (0)