Skip to content

Commit 6f29127

Browse files
committed
refactor(leap): extract conditional expressions
1 parent 8d7350c commit 6f29127

File tree

2 files changed

+153
-159
lines changed

2 files changed

+153
-159
lines changed

fnl/leap/main.fnl

+25-24
Original file line numberDiff line numberDiff line change
@@ -529,22 +529,22 @@ is either labeled (C) or not (B).
529529
(let [pat1 (or (expand-to-equivalence-class in1)
530530
; Sole '\' needs to be escaped even for \V.
531531
(in1:gsub "\\" "\\\\"))
532-
pat2 (or (-?> ?in2 expand-to-equivalence-class)
532+
pat2 (or (and ?in2 (expand-to-equivalence-class ?in2))
533533
?in2
534534
"\\_.") ; match anything, including EOL
535-
pat (if (and (pat1:match "\\n") (or (not ?in2) (pat2:match "\\n")))
536-
; If \n\n is a possible sequence to appear, add ^\n
537-
; to the pattern, to make our convenience feature -
538-
; targeting empty lines by typing the newline alias
539-
; twice - work.
540-
; This hack is always necessary for single-step
541-
; processing, when we already have the full pattern
542-
; (this includes repeating the previous search), but
543-
; also for two-step processing, in the special case of
544-
; targeting the very last line in the file (normally,
545-
; `search.get-targets` takes care of this situation,
546-
; but the pattern `\n\_.` does not match `\n$` if it's
547-
; on the last line).
535+
potential-\n\n? (and (pat1:match "\\n")
536+
(or (not ?in2) (pat2:match "\\n")))
537+
; If \n\n is a possible sequence to appear, add |^\n to the
538+
; pattern, to make our convenience feature - targeting empty
539+
; lines by typing the newline alias twice - work.
540+
; This hack is always necessary for single-step processing,
541+
; when we already have the full pattern (this includes
542+
; repeating the previous search), but also for two-step
543+
; processing, in the special case of targeting the very last
544+
; line in the file (normally, `search.get-targets` takes care
545+
; of this situation, but the pattern `\n\_.` does not match
546+
; `\n$` if it's on the last line).
547+
pat (if potential-\n\n?
548548
(.. pat1 pat2 "\\|\\^\\n")
549549
(.. pat1 pat2))]
550550
(.. "\\V" (if opts.case_sensitive "\\C" "\\c") pat)))
@@ -687,16 +687,17 @@ is either labeled (C) or not (B).
687687
(display group-offset)
688688
(case (get-input)
689689
input
690-
(if (and (< 1 |groups|)
691-
(or (= input spec-keys.next_group)
692-
(and (= input spec-keys.prev_group) (not first-invoc?))))
693-
(let [inc/dec (if (= input spec-keys.next_group) inc dec)
694-
max-offset (dec |groups|)
695-
group-offset* (-> group-offset inc/dec (clamp 0 max-offset))]
696-
; Switch, and ask for input again.
697-
(loop group-offset* false))
698-
; Otherwise return with input.
699-
(values input group-offset))))
690+
(let [switch-group? (and (> |groups| 1)
691+
(or (= input spec-keys.next_group)
692+
(and (= input spec-keys.prev_group)
693+
(not first-invoc?))))]
694+
(if switch-group?
695+
(let [inc/dec (if (= input spec-keys.next_group) inc dec)
696+
max-offset (dec |groups|)
697+
group-offset* (-> group-offset inc/dec (clamp 0 max-offset))]
698+
(loop group-offset* false))
699+
; Otherwise return with input.
700+
(values input group-offset)))))
700701
; ---
701702
(loop (or ?group-offset 0) (not= first-invoc? false)))
702703

0 commit comments

Comments
 (0)