From a82cab3bcc68abe015aa3dc3ea723298afa40398 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 6 Nov 2017 22:44:54 -0500 Subject: [PATCH] added cursor type and manipulation functions --- docs/Buf.Cursor.html | 24 ++++++++++---------- docs/Buf.html | 21 +++++++++-------- docs/index_types.html | 6 +++++ docs/index_values.html | 12 ++++++++-- docs/type_Buf.Cursor.html | 11 ++++++--- lib/buf.ml | 48 +++++++++++++++++++++++++++------------ lib/buf.mli | 25 ++++++++++---------- 7 files changed, 94 insertions(+), 53 deletions(-) diff --git a/docs/Buf.Cursor.html b/docs/Buf.Cursor.html index d8783be..0123ebb 100644 --- a/docs/Buf.Cursor.html +++ b/docs/Buf.Cursor.html @@ -25,31 +25,31 @@
module Cursor: sig .. end

-
type t = {
+
type csr = {
+mutable start : int; - - - - - +mutable stop : int;
   -start : int;
   -stop : int;
-   -column : int;
} -
val make : int -> int -> t
-
val clone : t -> t
\ No newline at end of file +
type t = csr 
+ + +
val make : Buf.buf -> int -> csr
+
val goto : Buf.buf -> csr -> int -> unit
+
val nextc : Buf.buf -> csr -> unit
+
val prevc : Buf.buf -> csr -> unit
+
val nextln : Buf.buf -> csr -> unit
+
val prevln : Buf.buf -> csr -> unit
\ No newline at end of file diff --git a/docs/Buf.html b/docs/Buf.html index 5a61b53..9a579ca 100644 --- a/docs/Buf.html +++ b/docs/Buf.html @@ -29,28 +29,31 @@
module Buf: sig .. end

-
module Cursor: sig .. end
-
type t = {
+
type buf = {
+path : string; +rope : Rope.t;
   -path : string;
   -rope : Rope.t;
} -
val empty : t
-
val load : string -> t
-
val rope : t -> Rope.t
-
val iter_from : (Rope.rune -> bool) -> t -> int -> unit
-
val iteri_from : (int -> Rope.rune -> bool) -> t -> int -> unit
\ No newline at end of file +
type t = buf 
+ + +
val empty : buf
+
val load : string -> buf
+
val rope : buf -> Rope.t
+
val iter_from : (Rope.rune -> bool) -> buf -> int -> unit
+
val iteri_from : (int -> Rope.rune -> bool) -> buf -> int -> unit
+
module Cursor: sig .. end
\ No newline at end of file diff --git a/docs/index_types.html b/docs/index_types.html index d213abe..f148594 100644 --- a/docs/index_types.html +++ b/docs/index_types.html @@ -21,6 +21,12 @@  

Index of types

+ + + + + + diff --git a/docs/index_values.html b/docs/index_values.html index c5f3910..5748025 100644 --- a/docs/index_values.html +++ b/docs/index_values.html @@ -41,8 +41,6 @@ - - @@ -137,6 +135,8 @@ + + @@ -212,8 +212,12 @@ + + + + @@ -230,8 +234,12 @@ + + + + diff --git a/docs/type_Buf.Cursor.html b/docs/type_Buf.Cursor.html index b2a156d..ca872d5 100644 --- a/docs/type_Buf.Cursor.html +++ b/docs/type_Buf.Cursor.html @@ -17,7 +17,12 @@ sig
-  type t = { start : int; stop : int; column : int; }
-  val make : int -> int -> Buf.Cursor.t
-  val clone : Buf.Cursor.t -> Buf.Cursor.t
+  type csr = { mutable start : int; mutable stop : int; }
+  type t = Buf.Cursor.csr
+  val make : Buf.buf -> int -> Buf.Cursor.csr
+  val goto : Buf.buf -> Buf.Cursor.csr -> int -> unit
+  val nextc : Buf.buf -> Buf.Cursor.csr -> unit
+  val prevc : Buf.buf -> Buf.Cursor.csr -> unit
+  val nextln : Buf.buf -> Buf.Cursor.csr -> unit
+  val prevln : Buf.buf -> Buf.Cursor.csr -> unit
end
\ No newline at end of file diff --git a/lib/buf.ml b/lib/buf.ml index 6c8d245..f2e6c7b 100644 --- a/lib/buf.ml +++ b/lib/buf.ml @@ -1,21 +1,8 @@ -module Cursor = struct - type t = { - start : int; - stop : int; - column : int; - } - - let make start stop = - { start = start; stop = stop; column = 0 } - - let clone csr = - { start = csr.start; stop = csr.stop; column = csr.column } -end - -type t = { +type buf = { path : string; rope : Rope.t } +type t = buf let empty = { path = ""; rope = Rope.empty } @@ -31,3 +18,34 @@ let iter_from fn buf i = let iteri_from fn buf i = Rope.iteri_from fn buf.rope i + +module Cursor = struct + type csr = { + mutable start : int; + mutable stop : int + } + + type t = csr + + let make buf idx = + { start = 0; stop = (Rope.limit_index buf.rope idx) } + + let goto buf csr idx = + csr.stop <- (Rope.limit_index buf.rope idx) + + let getc buf csr = + Rope.getc buf.rope csr.stop + + let nextc buf csr = + csr.stop <- (Rope.nextc buf.rope csr.stop) + + let prevc buf csr = + csr.stop <- (Rope.prevc buf.rope csr.stop) + + let nextln buf csr = + csr.stop <- (Rope.nextln buf.rope csr.stop) + + let prevln buf csr = + csr.stop <- (Rope.prevln buf.rope csr.stop) +end + diff --git a/lib/buf.mli b/lib/buf.mli index fae0030..6562edf 100644 --- a/lib/buf.mli +++ b/lib/buf.mli @@ -1,17 +1,18 @@ -(* -module Cursor : sig - type t - val to_offset : t -> int - val next_rune : t -> t - val prev_rune : t -> t - val next_line : t -> t - val prev_line : t -> t -end -*) - -type t +type buf +type t = buf val empty : t val load : string -> t val rope : t -> Rope.t val iter_from : (int -> bool) -> t -> int -> unit val iteri_from : (int -> int -> bool) -> t -> int -> unit + +module Cursor : sig + type t + val make : buf -> int -> t + val goto : buf -> t -> int -> unit + val getc : buf -> t -> int + val nextc : buf -> t -> unit + val prevc : buf -> t -> unit + val nextln : buf -> t -> unit + val prevln : buf -> t -> unit +end -- 2.52.0

B
buf [Buf]

C
csr [Buf.Cursor]

F
font [X11]
check_index [Rope]
clone [Buf.Cursor]
clrvar [Cfg]
cmd_tags [Cfg]
glyph_width [Draw]
goto [Buf.Cursor]
gutter_nor [Cfg.Color]
gutter_sel [Cfg.Color]
next_line [Draw.Cursor]
nextc [Buf.Cursor]
nextc [Rope]
nextln [Buf.Cursor]
nextln [Rope]
normal [Cfg.Color.Syntax]
preproc [Cfg.Color.Syntax]
prevc [Buf.Cursor]
prevc [Rope]
prevln [Buf.Cursor]
prevln [Rope]
procedure [Cfg.Color.Syntax]