add #edit_mode_default #edit_mode_vi directives

This commit is contained in:
ZAN DoYe 2020-04-14 16:05:09 +08:00
parent fd5bd4f665
commit cea5509294
3 changed files with 24 additions and 2 deletions

View File

@ -467,6 +467,8 @@ let default_prompt =
let prompt = ref default_prompt
let edit_mode= ref LTerm_editor.Default
let () =
Hashtbl.add Toploop.directive_table "utop_prompt_simple"
(Toploop.Directive_none
@ -488,7 +490,17 @@ let () =
(Toploop.Directive_none
(fun () ->
set_profile Dark;
prompt := default_prompt))
prompt := default_prompt));
Hashtbl.add Toploop.directive_table "edit_mode_default"
(Toploop.Directive_none
(fun () ->
edit_mode:= LTerm_editor.Default));
Hashtbl.add Toploop.directive_table "edit_mode_vi"
(Toploop.Directive_none
(fun () ->
edit_mode:= LTerm_editor.Vi))
(* +-----------------------------------------------------------------+
| Help |

View File

@ -234,6 +234,11 @@ val time : float ref
val prompt : LTerm_text.t React.signal ref
(** The prompt. *)
(** {6 Edit mode configuration} *)
val edit_mode : LTerm_editor.mode ref
(** The edit mode. *)
(** {6 Hooks} *)
val new_command_hooks : (unit -> unit) LTerm_dlist.t

View File

@ -712,7 +712,12 @@ let execute_phrase = Toploop.execute_phrase
let rec read_phrase term =
Lwt.catch
(fun () -> (new read_phrase ~term)#run)
(fun () ->
let read_line= new read_phrase ~term in
(match !UTop.edit_mode with
| LTerm_editor.Default-> ()
| LTerm_editor.Vi as mode-> read_line#set_editor_mode mode);
read_line#run)
(function
| Sys.Break ->
LTerm.fprintl term "Interrupted." >>= fun () ->