From c41969dc620aa84f3102a201687588c6c278fd19 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Thu, 29 Oct 2015 10:07:28 +0000 Subject: [PATCH] allow to configure the external editor --- man/utoprc.5 | 7 +++++++ src/lib/uTop.cppo.ml | 5 +++++ src/lib/uTop.mli | 5 +++++ src/lib/uTop_main.cppo.ml | 2 ++ src/lib/uTop_styles.ml | 3 +++ 5 files changed, 22 insertions(+) diff --git a/man/utoprc.5 b/man/utoprc.5 index 5c890ab..609258d 100644 --- a/man/utoprc.5 +++ b/man/utoprc.5 @@ -35,6 +35,13 @@ to disable the autoloading of files in .I $OCAML_TOPLEVEL_PATH/autoload 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 .I profile may have the value diff --git a/src/lib/uTop.cppo.ml b/src/lib/uTop.cppo.ml index 02cc6c8..3827400 100644 --- a/src/lib/uTop.cppo.ml +++ b/src/lib/uTop.cppo.ml @@ -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_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 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 *) let end_and_accept_current_phrase : LTerm_read_line.action = diff --git a/src/lib/uTop.mli b/src/lib/uTop.mli index b7ecfcb..e77f9de 100644 --- a/src/lib/uTop.mli +++ b/src/lib/uTop.mli @@ -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} *) val history : LTerm_history.t diff --git a/src/lib/uTop_main.cppo.ml b/src/lib/uTop_main.cppo.ml index 8fe47c1..f613ea7 100644 --- a/src/lib/uTop_main.cppo.ml +++ b/src/lib/uTop_main.cppo.ml @@ -146,6 +146,8 @@ class read_phrase ~term = object(self) method create_temporary_file_for_external_editor = Filename.temp_file "utop" ".ml" + method external_editor = UTop.get_external_editor () + val mutable return_value = None method eval = diff --git a/src/lib/uTop_styles.ml b/src/lib/uTop_styles.ml index dcba4b3..2ed77ef 100644 --- a/src/lib/uTop_styles.ml +++ b/src/lib/uTop_styles.ml @@ -87,6 +87,9 @@ let load () = | str -> raise (LTerm_resources.Error (Printf.sprintf "invalid profile %S" str))); UTop_private.error_style := styles.style_error; 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 ()) (function | Unix.Unix_error(Unix.ENOENT, _, _) ->