~~~ save ~~~ (C-x C-s)

This commit is contained in:
cqc
2024-07-08 23:00:09 -05:00
parent 0193c3e7f0
commit 5117bff3ae

62
ogui.ml
View File

@ -6,16 +6,6 @@ module Str = Re.Str
module Lwd = struct module Lwd = struct
open Lwt_react open Lwt_react
(*module S = struct
include Lwt_react.S
include Lwt_react.S.Make (struct
type 'a t
let equal = Stdlib.( == )
end)
end*)
type 'a var = 'a React.signal * (?step:React.step -> 'a -> unit) type 'a var = 'a React.signal * (?step:React.step -> 'a -> unit)
type 'a t = 'a React.signal type 'a t = 'a React.signal
@ -299,6 +289,29 @@ module TextBuffer = struct
let length { path; tree; _ } = let length { path; tree; _ } =
Store.S.Tree.get (Lwd.peek tree) (Lwd.peek path) >>= fun text -> Store.S.Tree.get (Lwd.peek tree) (Lwd.peek path) >>= fun text ->
Lwt.return (String.length text) Lwt.return (String.length text)
let save { path; tree; repo } =
Store.S.Tree.get (Lwd.peek tree) (Lwd.peek path)
>>= fun contents ->
repo >>= fun r ->
Store.S.set
~info:
Store.S.Info.(
fun () ->
v ~author:"me" ~message:"TextBuffer.save"
(Unix.time () |> Int64.of_float))
r (Lwd.peek path) contents
>>= fun r ->
(match r with
| Ok () -> ()
| Error (`Conflict s) ->
F.epr "TextBuffer.save Error `Conflict %s@." s
| Error (`Too_many_retries n) ->
F.epr "TextBuffer.save Error `Too_many_retries %d@." n
| Error (`Test_was n) ->
F.epr "TextBuffer.save Error `Test_was %s@."
"<not implemented>");
Lwt.return_unit
end end
module Event = struct module Event = struct
@ -737,7 +750,6 @@ module Ui = struct
let process_key t (resolver : action list Event.result) let process_key t (resolver : action list Event.result)
(state : Event.key_action) (key : Event.key) (state : Event.key_action) (key : Event.key)
(mods : Event.key_mod list) : action list Event.result Lwt.t = (mods : Event.key_mod list) : action list Event.result Lwt.t =
F.epr "process_key1@.";
let res = let res =
match resolver with match resolver with
| Event.Rejected | Event.Accepted _ -> | Event.Rejected | Event.Accepted _ ->
@ -748,24 +760,17 @@ module Ui = struct
] ]
| Event.Continue r -> r | Event.Continue r -> r
in in
F.epr "process_key2@.";
let res = Event.resolve (Key (state, key, mods)) res in let res = Event.resolve (Key (state, key, mods)) res in
F.epr "process_key3@.";
(match res with (match res with
| Event.Accepted actions -> | Event.Accepted actions ->
let rec exec : action list -> unit Lwt.t = function let rec exec : action list -> unit Lwt.t = function
| Custom (name, f) :: actions -> | Custom (name, f) :: actions ->
f () >>= fun () -> f () >>= fun () -> exec actions
F.epr "process_key4 %s f ()@." name;
exec actions
| [] -> Lwt.return_unit | [] -> Lwt.return_unit
in in
F.epr "process_key5@.";
exec actions >>= fun () -> Lwt.return_unit exec actions >>= fun () -> Lwt.return_unit
| Event.Continue _ | Event.Rejected -> Lwt.return_unit) | Event.Continue _ | Event.Rejected -> Lwt.return_unit)
>>= fun () -> >>= fun () -> Lwt.return res
F.epr "process_key5@.";
Lwt.return res
let update_bindings ui let update_bindings ui
(f : action list Event.t -> action list Event.t) = (f : action list Event.t -> action list Event.t) =
@ -804,7 +809,9 @@ module Ui = struct
(* junk the `Char that is sent with a `Key that has no mods *) (* junk the `Char that is sent with a `Key that has no mods *)
Lwt_stream.peek events Lwt_stream.peek events
>>= function >>= function
| Some (`Char _) -> Lwt_stream.junk events | Some (`Char _) ->
F.epr "process_events: junking next event@.";
Lwt_stream.junk events
| _ -> Lwt.return_unit) | _ -> Lwt.return_unit)
| Accepted _ | Continue _ | Rejected -> Lwt.return_unit) | Accepted _ | Continue _ | Rejected -> Lwt.return_unit)
>>= fun () -> proc res >>= fun () -> proc res
@ -1155,6 +1162,17 @@ module TextEdit = struct
fun () -> fun () ->
Lwd.set t.mark None; Lwd.set t.mark None;
Lwt.return_unit ); Lwt.return_unit );
]
|> adds
[
[
Key (Press, X, [ Control ]);
Key (Press, S, [ Control ]);
];
]
(* Save *)
[
Custom ("save_buffer", fun () -> TextBuffer.save t.text);
]); ]);
Ui.chrcallback_ref := Ui.chrcallback_ref :=
@ -1293,8 +1311,6 @@ module Layout = struct
ui; ui;
Lwt.return_unit ); Lwt.return_unit );
]); ]);
(* let teln = List.length telist in *)
(* let ratio n = `Ratio (1. /. float (teln - (n + 1))) in *)
Lwd.map_s Lwd.map_s
~f:(fun (_, tl) -> ~f:(fun (_, tl) ->
Lwt_list.mapi_s Lwt_list.mapi_s