From 8fae6713bcb95b8828c97a84fbbd67603695407d Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 7 Nov 2017 20:30:22 -0500 Subject: [PATCH] totally broke scrolling but im not sure how... --- docs/Buf.Cursor.html | 2 ++ docs/Buf.html | 4 ++-- docs/Rope.html | 6 ++++-- docs/index_exceptions.html | 2 ++ docs/index_values.html | 12 ++++++++---- docs/type_Buf.Cursor.html | 2 ++ lib/buf.ml | 13 +++++++++---- lib/buf.mli | 11 +++++++++-- lib/draw.ml | 2 +- lib/rope.ml | 22 +++++++++++++++++++++- lib/rope.mli | 3 +-- lib/scrollmap.ml | 6 +++++- 12 files changed, 66 insertions(+), 19 deletions(-) diff --git a/docs/Buf.Cursor.html b/docs/Buf.Cursor.html index 0ee7c57..8e5a261 100644 --- a/docs/Buf.Cursor.html +++ b/docs/Buf.Cursor.html @@ -48,6 +48,8 @@
val make : Buf.buf -> int -> csr
+
val clone : csr -> csr
+
val iter : 'a -> 'b -> 'c -> unit
val offset : 'a -> csr -> int
val goto : Buf.buf -> csr -> int -> unit
val getc : Buf.buf -> csr -> Rope.rune
diff --git a/docs/Buf.html b/docs/Buf.html index 15b942c..81f30d3 100644 --- a/docs/Buf.html +++ b/docs/Buf.html @@ -53,7 +53,7 @@
val empty : buf
val load : string -> buf
-
val iter_from : (Rope.rune -> bool) -> buf -> int -> unit
-
val iteri_from : (int -> Rope.rune -> bool) -> buf -> int -> unit
+
val iter : (Rope.rune -> bool) -> buf -> int -> unit
+
val iteri : (int -> Rope.rune -> bool) -> buf -> int -> unit
val is_eol : buf -> int -> bool
module Cursor: sig .. end
\ No newline at end of file diff --git a/docs/Rope.html b/docs/Rope.html index 8b12eb3..ba5d84c 100644 --- a/docs/Rope.html +++ b/docs/Rope.html @@ -70,8 +70,10 @@
val getb : t -> int -> char
val getc : t -> int -> int
val putc : 'a -> 'b -> 'c -> 'a
-
val iter_from : (int -> bool) -> t -> int -> unit
-
val iteri_from : (int -> int -> bool) -> t -> int -> unit
+
exception Break_loop
+ +
val iteri_leaf : (int -> int -> bool) -> int -> string -> int -> int -> unit
+
val iteri : (int -> int -> bool) -> t -> int -> unit
val gets : t -> int -> int -> string
val puts : t -> string -> int -> t
val nextc : t -> int -> int
diff --git a/docs/index_exceptions.html b/docs/index_exceptions.html index 79682f4..d9c6c7e 100644 --- a/docs/index_exceptions.html +++ b/docs/index_exceptions.html @@ -24,6 +24,8 @@
B Bad_rotation [Rope] +Break_loop [Rope] +
O Out_of_bounds [Rope] diff --git a/docs/index_values.html b/docs/index_values.html index 8c16029..f415397 100644 --- a/docs/index_values.html +++ b/docs/index_values.html @@ -41,6 +41,8 @@ check_index [Rope] +clone [Buf.Cursor] + clrvar [Cfg] cmd_tags [Cfg] @@ -163,13 +165,15 @@ is_eol [Rope] -iter_from [Buf] +iter [Buf.Cursor] + +iter [Buf] -iter_from [Rope] +iteri [Buf] -iteri_from [Buf] +iteri [Rope] -iteri_from [Rope] +iteri_leaf [Rope]
J join [Rope] diff --git a/docs/type_Buf.Cursor.html b/docs/type_Buf.Cursor.html index fe50066..6f55025 100644 --- a/docs/type_Buf.Cursor.html +++ b/docs/type_Buf.Cursor.html @@ -20,6 +20,8 @@   type csr = { mutable start : int; mutable stop : int; }
  type t = Buf.Cursor.csr
  val make : Buf.buf -> int -> Buf.Cursor.csr
+  val clone : Buf.Cursor.csr -> Buf.Cursor.csr
+  val iter : '-> '-> '-> unit
  val offset : '-> Buf.Cursor.csr -> int
  val goto : Buf.buf -> Buf.Cursor.csr -> int -> unit
  val getc : Buf.buf -> Buf.Cursor.csr -> Rope.rune
diff --git a/lib/buf.ml b/lib/buf.ml index cdefefb..f8a37f3 100644 --- a/lib/buf.ml +++ b/lib/buf.ml @@ -11,11 +11,11 @@ let empty = let load path = { path = path; rope = Rope.from_string (Misc.load_file path) } -let iter_from fn buf i = - Rope.iter_from fn buf.rope i +let iter fn buf i = + Rope.iteri (fun i c -> (fn c)) buf.rope i -let iteri_from fn buf i = - Rope.iteri_from fn buf.rope i +let iteri fn buf i = + Rope.iteri fn buf.rope i let is_eol buf off = Rope.is_eol buf.rope off @@ -31,6 +31,11 @@ module Cursor = struct let make buf idx = { start = 0; stop = (Rope.limit_index buf.rope idx) } + let clone csr = + { start = csr.start; stop = csr.stop } + + let iter fn buf csr = () + let offset buf csr = csr.stop diff --git a/lib/buf.mli b/lib/buf.mli index 12b49c2..a5aa8bc 100644 --- a/lib/buf.mli +++ b/lib/buf.mli @@ -2,14 +2,16 @@ type buf type t = buf val empty : t val load : string -> t -val iter_from : (int -> bool) -> t -> int -> unit -val iteri_from : (int -> int -> bool) -> t -> int -> unit +val iter : (int -> bool) -> t -> int -> unit +val iteri : (int -> int -> bool) -> t -> int -> unit val is_eol : buf -> int -> bool module Cursor : sig type t val make : buf -> int -> t + val clone : t -> t + val iter : (t -> bool) -> buf -> t -> unit val offset : buf -> t -> int val goto : buf -> t -> int -> unit val getc : buf -> t -> int @@ -23,6 +25,11 @@ module Cursor : sig val nextln : buf -> t -> int val prevln : buf -> t -> int +(* + val is_bol : buf -> t -> bool + val to_eol : buf -> t -> int +*) + val is_eol : buf -> t -> bool val to_bol : buf -> t -> int end diff --git a/lib/draw.ml b/lib/draw.ml index e796136..8cafd26 100644 --- a/lib/draw.ml +++ b/lib/draw.ml @@ -97,7 +97,7 @@ let buffer csr buf off = draw_glyph csr c; has_next_line csr in - Buf.iter_from draw_rune buf off + Buf.iter draw_rune buf off let status csr str = dark_bkg csr.width (4 + font_height) csr; diff --git a/lib/rope.ml b/lib/rope.ml index fdde27f..bb5ff38 100644 --- a/lib/rope.ml +++ b/lib/rope.ml @@ -102,6 +102,25 @@ let putc rope i c = rope (******************************************************************************) +exception Break_loop + +let iteri_leaf fn pos str off len = + let offset = pos - off in + for i = off to off + len - 1 do (* break loop when fn returns false *) + if (fn (i + offset) (Char.code str.[i])) == false then + raise Break_loop + done + +let rec iteri fn rope pos = + match rope with + | Leaf (str, off, len) -> + (try iteri_leaf fn pos str off len + with Break_loop -> ()) + | Node (l,r,_,_) -> + iteri fn l pos; + iteri fn r (pos + (length l)) + +(* let rec iter_from fn rope pos = if pos < (length rope) && (fn (getc rope pos)) then iter_from fn rope (pos + 1) @@ -109,12 +128,13 @@ let rec iter_from fn rope pos = let rec iteri_from fn rope pos = if pos < (length rope) && (fn pos (getc rope pos)) then iteri_from fn rope (pos + 1) +*) (******************************************************************************) let gets rope i j = let buf = Bytes.create (j - i) in - iteri_from + iteri (fun n c -> Bytes.set buf (n - i) (getb rope i); (n <= j)) diff --git a/lib/rope.mli b/lib/rope.mli index 69a5591..57be4b4 100644 --- a/lib/rope.mli +++ b/lib/rope.mli @@ -19,8 +19,7 @@ val join : rope -> rope -> rope val split : rope -> int -> (rope * rope) val del : rope -> int -> int -> rope -val iter_from : (rune -> bool) -> rope -> int -> unit -val iteri_from : (int -> rune -> bool) -> rope -> int -> unit +val iteri : (int -> rune -> bool) -> rope -> int -> unit val getb : rope -> int -> char val getc : rope -> int -> rune diff --git a/lib/scrollmap.ml b/lib/scrollmap.ml index 01914d6..7db51d0 100644 --- a/lib/scrollmap.ml +++ b/lib/scrollmap.ml @@ -20,12 +20,16 @@ let make buf width off = lines := i :: !lines; not_eol in - Buf.iteri_from process_glyph buf off; + Buf.iteri process_glyph buf off; let lines = (Array.of_list (List.rev !lines)) in + print_string "map: "; + Array.iter (fun x -> Printf.printf "%d " x) lines; + print_endline ""; let index = (find_line lines off ((Array.length lines) - 1)) in { width = width; lines = lines; index = index } let first map = + Printf.printf "first: %d\n" map.lines.(map.index); map.lines.(map.index) let bopl buf off = -- 2.52.0