allow to configure the external editor

This commit is contained in:
Jeremie Dimino 2015-10-29 10:07:28 +00:00
parent 8d104762ce
commit c41969dc62
5 changed files with 22 additions and 0 deletions

View File

@ -35,6 +35,13 @@ to disable the autoloading of files in
.I $OCAML_TOPLEVEL_PATH/autoload .I $OCAML_TOPLEVEL_PATH/autoload
at startup. at startup.
The key
.I external-editor
can be set to a command line. It is used to edit the input when
pressing C-x C-e. It defaults to the contents of the
.I EDITOR
environment variable.
The key The key
.I profile .I profile
may have the value may have the value

View File

@ -75,6 +75,11 @@ let phrase_terminator, get_phrase_terminator, set_phrase_terminator = make_varia
let auto_run_lwt, get_auto_run_lwt, set_auto_run_lwt = make_variable true let auto_run_lwt, get_auto_run_lwt, set_auto_run_lwt = make_variable true
let auto_run_async, get_auto_run_async, set_auto_run_async = make_variable true let auto_run_async, get_auto_run_async, set_auto_run_async = make_variable true
let topfind_verbose, get_topfind_verbose, set_topfind_verbose = make_variable false let topfind_verbose, get_topfind_verbose, set_topfind_verbose = make_variable false
let external_editor, get_external_editor, set_external_editor =
make_variable
(match Sys.getenv "EDITOR" with
| exception Not_found -> "vi"
| s -> s)
(* Ugly hack until the action system of lambda-term is improved *) (* Ugly hack until the action system of lambda-term is improved *)
let end_and_accept_current_phrase : LTerm_read_line.action = let end_and_accept_current_phrase : LTerm_read_line.action =

View File

@ -177,6 +177,11 @@ val end_and_accept_current_phrase : LTerm_read_line.action
]} ]}
*) *)
(** External editor command. [None] for default. *)
val external_editor : string signal
val set_external_editor : string -> unit
val get_external_editor : unit -> string
(** {6 History} *) (** {6 History} *)
val history : LTerm_history.t val history : LTerm_history.t

View File

@ -146,6 +146,8 @@ class read_phrase ~term = object(self)
method create_temporary_file_for_external_editor = method create_temporary_file_for_external_editor =
Filename.temp_file "utop" ".ml" Filename.temp_file "utop" ".ml"
method external_editor = UTop.get_external_editor ()
val mutable return_value = None val mutable return_value = None
method eval = method eval =

View File

@ -87,6 +87,9 @@ let load () =
| str -> raise (LTerm_resources.Error (Printf.sprintf "invalid profile %S" str))); | str -> raise (LTerm_resources.Error (Printf.sprintf "invalid profile %S" str)));
UTop_private.error_style := styles.style_error; UTop_private.error_style := styles.style_error;
UTop_private.autoload := LTerm_resources.get_bool "autoload" res <> Some false; UTop_private.autoload := LTerm_resources.get_bool "autoload" res <> Some false;
(match LTerm_resources.get "external-editor" res with
| "" -> ()
| s -> UTop.set_external_editor s);
return ()) return ())
(function (function
| Unix.Unix_error(Unix.ENOENT, _, _) -> | Unix.Unix_error(Unix.ENOENT, _, _) ->