summaryrefslogtreecommitdiff
path: root/lib/zipper.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/zipper.ml')
-rw-r--r--lib/zipper.ml12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/zipper.ml b/lib/zipper.ml
index 202f6d4..413f365 100644
--- a/lib/zipper.ml
+++ b/lib/zipper.ml
@@ -61,11 +61,21 @@ let pop_after ?(n = 1) z =
61 if right_length z < 2 then z else right z |> pop ~n |> left 61 if right_length z < 2 then z else right z |> pop ~n |> left
62 62
63let push x z = { z with after = Sequence.shift_right z.after x } 63let push x z = { z with after = Sequence.shift_right z.after x }
64let push_seq s z = { z with after = Sequence.append s z.after }
64let push_after x z = right z |> push x |> left 65let push_after x z = right z |> push x |> left
66let push_after_seq s z = right z |> push_seq s |> left
65 67
66let push_before x z = 68let push_before x z =
67 { z with pos = z.pos + 1; before = Sequence.shift_right z.before x } 69 { z with pos = z.pos + 1; before = Sequence.shift_right z.before x }
68 70
71let push_before_seq s z =
72 let f a e = Sequence.shift_right a e in
73 {
74 z with
75 pos = z.pos + Sequence.length s;
76 before = Sequence.fold ~init:z.before ~f s;
77 }
78
69let split z = 79let split z =
70 ( { z with after = Sequence.empty }, 80 ( { z with after = Sequence.empty },
71 { z with pos = 0; before = Sequence.empty } ) 81 { z with pos = 0; before = Sequence.empty } )
@@ -119,7 +129,7 @@ let filter p z = z |> filter_left p |> filter_right p
119let context_left n z = { z with before = Sequence.take z.before n } 129let context_left n z = { z with before = Sequence.take z.before n }
120let context_right n z = { z with after = Sequence.take z.after n } 130let context_right n z = { z with after = Sequence.take z.after n }
121let context ~l ?(r = l) z = z |> context_left l |> context_right r 131let context ~l ?(r = l) z = z |> context_left l |> context_right r
122let swap_focus a = map_focus (Fn.const a) 132let swap_focus a = map_focus_or ~default:a (Fn.const a)
123let of_seq s = { empty with after = s } 133let of_seq s = { empty with after = s }
124let to_seq z = z |> far_left |> after 134let to_seq z = z |> far_left |> after
125let window ~from ~len z = goto from z |> context_right len |> after 135let window ~from ~len z = goto from z |> context_right len |> after