From: Michael D. Lowis Date: Wed, 8 Nov 2017 16:27:48 +0000 (-0500) Subject: Implemented various cursor and offset movement and test functions as curried wrappers... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=c9648494ff917844d50b80db913f90b449863c24;p=archive%2Ftide-ocaml.git Implemented various cursor and offset movement and test functions as curried wrappers around cursor functionality --- diff --git a/docs/Buf.Cursor.html b/docs/Buf.Cursor.html index c9d7c7e..42b69e9 100644 --- a/docs/Buf.Cursor.html +++ b/docs/Buf.Cursor.html @@ -53,9 +53,13 @@
val goto : Buf.buf -> csr -> int -> unit
val iter : (csr -> Rope.rune -> bool) -> Buf.buf -> csr -> unit
val getc : Buf.buf -> csr -> Rope.rune
+
val move_to : Buf.dest -> Buf.buf -> csr -> int
val nextc : Buf.buf -> csr -> int
val prevc : Buf.buf -> csr -> int
val nextln : Buf.buf -> csr -> int
val prevln : Buf.buf -> csr -> int
-
val is_eol : Buf.buf -> csr -> bool
-
val to_bol : Buf.buf -> csr -> int
\ No newline at end of file +
val bol : Buf.buf -> csr -> int
+
val eol : Buf.buf -> csr -> int
+
val is_at : Buf.dest -> Buf.buf -> csr -> bool
+
val is_bol : Buf.buf -> csr -> bool
+
val is_eol : Buf.buf -> csr -> bool
\ No newline at end of file diff --git a/docs/Buf.html b/docs/Buf.html index d47d555..e7943e7 100644 --- a/docs/Buf.html +++ b/docs/Buf.html @@ -51,8 +51,65 @@
type t = buf 
+
type dest = 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+| +StartOfLine
+| +EndOfLine
+| +NextChar
+| +PrevChar
+| +NextLine
+| +PrevLine
+ + +
val empty : buf
val load : string -> buf
val iteri : (int -> Rope.rune -> bool) -> buf -> int -> unit
val iter : (Rope.rune -> bool) -> buf -> int -> unit
-
module Cursor: sig .. end
\ No newline at end of file +
module Cursor: sig .. end
+
val move_to : dest -> buf -> int -> int
+
val nextc : buf -> int -> int
+
val prevc : buf -> int -> int
+
val nextln : buf -> int -> int
+
val prevln : buf -> int -> int
+
val bol : buf -> int -> int
+
val eol : buf -> int -> int
+
val eol : buf -> int -> int
+
val is_at : dest -> buf -> int -> bool
+
val is_bol : buf -> int -> bool
+
val is_eol : buf -> int -> bool
\ No newline at end of file diff --git a/docs/Scrollmap.html b/docs/Scrollmap.html index ce83037..35cb91c 100644 --- a/docs/Scrollmap.html +++ b/docs/Scrollmap.html @@ -56,8 +56,6 @@
val find_line : 'a array -> 'a -> int -> int
val make : Buf.t -> int -> int -> t
val first : t -> int
-
val bopl : Buf.buf -> int -> int
-
val bonl : Buf.buf -> int -> int
val scroll_up : t -> Buf.t -> t
val scroll_dn : t -> Buf.t -> t
val resize : t -> Buf.t -> int -> t
\ No newline at end of file diff --git a/docs/index_types.html b/docs/index_types.html index f148594..79c783a 100644 --- a/docs/index_types.html +++ b/docs/index_types.html @@ -27,6 +27,9 @@
C csr [Buf.Cursor] +
D +dest [Buf] +
F font [X11] diff --git a/docs/index_values.html b/docs/index_values.html index e88a90c..4394030 100644 --- a/docs/index_values.html +++ b/docs/index_values.html @@ -22,14 +22,14 @@

Index of values

- + + + - - @@ -99,6 +99,10 @@ + + + + @@ -157,10 +161,20 @@ + + + + + + + + + + @@ -213,6 +227,10 @@ + + + + @@ -220,10 +238,14 @@ + + + + @@ -244,10 +266,14 @@ + + + + @@ -317,8 +343,6 @@ - - diff --git a/docs/type_Buf.Cursor.html b/docs/type_Buf.Cursor.html index 5bc2e2f..dd15c50 100644 --- a/docs/type_Buf.Cursor.html +++ b/docs/type_Buf.Cursor.html @@ -27,10 +27,14 @@     (Buf.Cursor.csr -> Rope.rune -> bool) ->
    Buf.buf -> Buf.Cursor.csr -> unit
  val getc : Buf.buf -> Buf.Cursor.csr -> Rope.rune
+  val move_to : Buf.dest -> Buf.buf -> Buf.Cursor.csr -> int
  val nextc : Buf.buf -> Buf.Cursor.csr -> int
  val prevc : Buf.buf -> Buf.Cursor.csr -> int
  val nextln : Buf.buf -> Buf.Cursor.csr -> int
  val prevln : Buf.buf -> Buf.Cursor.csr -> int
+  val bol : Buf.buf -> Buf.Cursor.csr -> int
+  val eol : Buf.buf -> Buf.Cursor.csr -> int
+  val is_at : Buf.dest -> Buf.buf -> Buf.Cursor.csr -> bool
+  val is_bol : Buf.buf -> Buf.Cursor.csr -> bool
  val is_eol : Buf.buf -> Buf.Cursor.csr -> bool
-  val to_bol : Buf.buf -> Buf.Cursor.csr -> int
end \ No newline at end of file diff --git a/lib/buf.ml b/lib/buf.ml index 1219ee3..94a6fbb 100644 --- a/lib/buf.ml +++ b/lib/buf.ml @@ -5,6 +5,11 @@ type buf = { type t = buf +type dest = + | StartOfLine | EndOfLine + | NextChar | PrevChar + | NextLine | PrevLine + let empty = { path = ""; rope = Rope.empty } @@ -43,22 +48,45 @@ module Cursor = struct let getc buf csr = Rope.getc buf.rope csr.stop - let nextc buf csr = - csr.stop <- (Rope.nextc buf.rope csr.stop); csr.stop - - let prevc buf csr = - csr.stop <- (Rope.prevc buf.rope csr.stop); csr.stop - - let nextln buf csr = - csr.stop <- (Rope.nextln buf.rope csr.stop); csr.stop - - let prevln buf csr = - csr.stop <- (Rope.prevln buf.rope csr.stop); csr.stop - - let is_eol buf csr = - Rope.is_eol buf.rope csr.stop + let move_to dest buf csr = + csr.stop <- (match dest with + | StartOfLine -> Rope.to_bol buf.rope csr.stop + | EndOfLine -> Rope.to_eol buf.rope csr.stop + | NextChar -> Rope.nextc buf.rope csr.stop + | PrevChar -> Rope.prevc buf.rope csr.stop + | NextLine -> Rope.nextln buf.rope csr.stop + | PrevLine -> Rope.prevln buf.rope csr.stop + ); + csr.stop - let to_bol buf csr = - csr.stop <- (Rope.to_bol buf.rope csr.stop); csr.stop + let nextc = move_to NextChar + let prevc = move_to PrevChar + let nextln = move_to NextLine + let prevln = move_to PrevLine + let bol = move_to StartOfLine + let eol = move_to EndOfLine + + let is_at dest buf csr = + match dest with + | StartOfLine -> Rope.is_bol buf.rope csr.stop + | EndOfLine -> Rope.is_eol buf.rope csr.stop + | _ -> false + + let is_bol = is_at StartOfLine + let is_eol = is_at EndOfLine end +let move_to dest buf i = + Cursor.move_to dest buf (Cursor.make buf i) +let nextc = move_to NextChar +let prevc = move_to PrevChar +let nextln = move_to NextLine +let prevln = move_to PrevLine +let bol = move_to StartOfLine +let eol = move_to EndOfLine +let eol = move_to EndOfLine + +let is_at dest buf i = + Cursor.is_at dest buf (Cursor.make buf i) +let is_bol = is_at StartOfLine +let is_eol = is_at EndOfLine diff --git a/lib/buf.mli b/lib/buf.mli index 4bf4215..496882d 100644 --- a/lib/buf.mli +++ b/lib/buf.mli @@ -1,31 +1,52 @@ type buf type t = buf -val empty : t -val load : string -> t -val iter : (int -> bool) -> t -> int -> unit -val iteri : (int -> int -> bool) -> t -> int -> unit +type dest = + | StartOfLine | EndOfLine + | NextChar | PrevChar + | NextLine | PrevLine module Cursor : sig type t + val make : buf -> int -> t val clone : t -> t val iter : (t -> int -> bool) -> buf -> t -> unit val offset : t -> int val goto : buf -> t -> int -> unit + val getc : buf -> t -> int (* val putc : buf -> t -> int -> unit val gets : buf -> t -> string val puts : buf -> t -> string -> unit *) + + val move_to : dest -> buf -> t -> int val nextc : buf -> t -> int val prevc : buf -> t -> int val nextln : buf -> t -> int val prevln : buf -> t -> int -(* + val bol : buf -> t -> int + val eol : buf -> t -> int + + val is_at : dest -> buf -> t -> bool 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 + +val empty : t +val load : string -> t +val iter : (int -> bool) -> t -> int -> unit +val iteri : (int -> int -> bool) -> t -> int -> unit + +val move_to : dest -> t -> int -> int +val nextc : t -> int -> int +val prevc : t -> int -> int +val nextln : t -> int -> int +val prevln : t -> int -> int +val bol : t -> int -> int +val eol : t -> int -> int + +val is_at : dest -> t -> int -> bool +val is_bol : t -> int -> bool +val is_eol : t -> int -> bool diff --git a/lib/scrollmap.ml b/lib/scrollmap.ml index 6cb8cd4..960633d 100644 --- a/lib/scrollmap.ml +++ b/lib/scrollmap.ml @@ -12,8 +12,7 @@ let rec find_line lines off idx = let make buf width off = let csr = Draw.Cursor.make (width, 0) 0 0 in - (*let bol = Buf.goto StartOfLine buf off in*) - let bol = Buf.Cursor.to_bol buf (Buf.Cursor.make buf off) in + let bol = Buf.bol buf off in let lines = ref [bol] in let process_glyph i c = let not_eol = (c != 0x0A) in @@ -29,25 +28,21 @@ let make buf width off = let first map = map.lines.(map.index) -let bopl buf off = - Buf.Cursor.prevln buf (Buf.Cursor.make buf off) - -let bonl buf off = - Buf.Cursor.nextln buf (Buf.Cursor.make buf off) - let scroll_up map buf = let next = map.index - 1 in if (next >= 0) then { map with index = next } else - make buf map.width (bopl buf map.lines.(0)) + let off = map.lines.(0) in + make buf map.width (Buf.prevln buf off) let scroll_dn map buf = let next = map.index + 1 in if (next < (Array.length map.lines)) then { map with index = next } else - make buf map.width (bonl buf map.lines.((Array.length map.lines) - 1)) + let off = map.lines.((Array.length map.lines) - 1) in + make buf map.width (Buf.nextln buf off) let resize map buf width = if map.width == width then map

B
bonl [Scrollmap]
bol [Buf.Cursor]
bol [Buf]
boolean [Cfg.Color.Syntax]
boolvar [Cfg]
bopl [Scrollmap]
borders [Cfg.Color]
buffer [Draw]
empty [Rope]
eol [Buf.Cursor]
eol [Buf]
event_loop [X11]
event_timeout [Cfg]
intvar [Cfg]
is_at [Buf.Cursor]
is_at [Buf]
is_bol [Buf.Cursor]
is_bol [Buf]
is_bol [Rope]
is_eol [Buf.Cursor]
is_eol [Buf]
is_eol [Rope]
iter [Buf.Cursor]
move_till [Rope]
move_to [Buf.Cursor]
move_to [Buf]

N
next_glyph [Draw.Cursor]
nextc [Buf.Cursor]
nextc [Buf]
nextc [Rope]
nextln [Buf.Cursor]
nextln [Buf]
nextln [Rope]
normal [Cfg.Color.Syntax]
prevc [Buf.Cursor]
prevc [Buf]
prevc [Rope]
prevln [Buf.Cursor]
prevln [Buf]
prevln [Rope]
procedure [Cfg.Color.Syntax]
tags_sel [Cfg.Color]
to_bol [Buf.Cursor]
to_bol [Rope]
to_eol [Rope]