Backport the #use_output directive from OCaml 4.11
Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This commit is contained in:
parent
693ef525b1
commit
3f735497d9
|
@ -2,6 +2,7 @@ next
|
|||
----
|
||||
|
||||
- Load init file from ~/.config/utop/init.ml as per XDG conventions (@copy, #144)
|
||||
- Backport the #use_output directive (@diml, #...)
|
||||
|
||||
2.4.3 (2019-12-31)
|
||||
------------------
|
||||
|
|
|
@ -743,6 +743,34 @@ let () =
|
|||
(Toploop.Directive_string
|
||||
(fun str -> require (split_words str)))
|
||||
|
||||
(* +-----------------------------------------------------------------+
|
||||
| Backports |
|
||||
+-----------------------------------------------------------------+ *)
|
||||
|
||||
|
||||
let use_output command =
|
||||
let fn = Filename.temp_file "ocaml" "_toploop.ml" in
|
||||
Misc.try_finally ~always:(fun () ->
|
||||
try Sys.remove fn with Sys_error _ -> ())
|
||||
(fun () ->
|
||||
match
|
||||
Printf.ksprintf Sys.command "%s > %s"
|
||||
command
|
||||
(Filename.quote fn)
|
||||
with
|
||||
| 0 ->
|
||||
ignore (Toploop.use_file Format.std_formatter fn : bool)
|
||||
| n ->
|
||||
Format.printf "Command exited with code %d.@." n)
|
||||
|
||||
let () =
|
||||
let name = "use_output" in
|
||||
if not (Hashtbl.mem Toploop.directive_table name) then
|
||||
Hashtbl.add
|
||||
Toploop.directive_table
|
||||
name
|
||||
(Toploop.Directive_string use_output)
|
||||
|
||||
(* +-----------------------------------------------------------------+
|
||||
| Initialization |
|
||||
+-----------------------------------------------------------------+ *)
|
||||
|
|
Loading…
Reference in New Issue