open X11
-(*
-let font = font_load "Times New Roman:size=12"
-let font = font_load "Monaco:size=10::antialias=true:autohint=true"
-*)
-let font = font_load "Verdana:size=11:antialias=true:autohint=true"
-let tags_buf = ref Buf.create
-let edit_buf = ref Buf.create
+let font_times = font_load "Times New Roman:size=12"
+let font_monaco = font_load "Monaco:size=10::antialias=true:autohint=true"
+let font_verdana = font_load "Verdana:size=11:antialias=true:autohint=true"
+
+let font = font_verdana
+let tags_buf = ref Buf.empty
+let edit_buf = ref Buf.empty
(* Drawing functions
******************************************************************************)
-type item = Ch | Word | Line
+type cursor = {
+ start : int;
+ stop : int
+}
type buf = {
path : string;
let iter_from fn buf i =
Rope.iter_from fn buf.rope i
-let create =
+let empty =
{ path = ""; rope = Rope.empty }
let load path =
{ path = path; rope = Rope.from_string (Misc.load_file path) }
-let saveas buf path =
+let make_cursor buf start stop =
+ { start = (Rope.limit_index buf.rope start);
+ stop = (Rope.limit_index buf.rope stop) }
+
+let move_rune count csr buf ext =
+ let newstop = csr.stop + count in
+ let newstart = if ext then csr.start else newstop in
+ make_cursor buf newstart newstop
+
+let move_word count csr buf ext =
()
-let save buf =
- saveas buf buf.path
+let move_line count csr buf ext =
+ ()
+
+(* Unit Tests *****************************************************************)
-let move item count buf pos =
- match item with
- | Ch -> pos + count
- | Word -> pos + count
- | Line -> pos + count
+let run_unit_tests () =
+ let open Test in
+ ()
if i < 0 || i >= (length rope) then
raise (Out_of_bounds "Rope.check_index")
+let limit_index rope i =
+ if i < 0 then 0
+ else if i > 0 && i >= (length rope) then
+ ((length rope) - 1)
+ else i
+
let join left right =
let left_len = (length left) in
let right_len = (length right) in