Load init file from .config/utop/init.ml as per XDG conventions (fix #144)

This commit is contained in:
Fabian 2020-02-22 21:38:28 +01:00 committed by ZAN DoYe
parent c719401992
commit 53813ef663
1 changed files with 23 additions and 9 deletions

View File

@ -1449,20 +1449,34 @@ let common_init ~initial_env =
if !autoload && !UTop_private.autoload && Sys.file_exists autoload_dir then if !autoload && !UTop_private.autoload && Sys.file_exists autoload_dir then
load_init_files autoload_dir load_init_files autoload_dir
| None -> ()); | None -> ());
(* Load user's .ocamlinit file. *) (* Load user's init file. *)
(match !Clflags.init_file with let init_fn =
match !Clflags.init_file with
| Some fn -> | Some fn ->
if Sys.file_exists fn then if Sys.file_exists fn then
ignore (Toploop.use_silently Format.err_formatter fn : bool) Some fn
else else (
Printf.eprintf "Init file not found: \"%s\".\n" fn Printf.eprintf "Init file not found: \"%s\".\n" fn;
None
)
| None -> | None ->
if Sys.file_exists ".ocamlinit" then if Sys.file_exists ".ocamlinit" then
ignore (Toploop.use_silently Format.err_formatter ".ocamlinit" : bool) Some ".ocamlinit"
else else
let fn = Filename.concat LTerm_resources.home ".ocamlinit" in let xdg_fn = LTerm_resources.xdgbd_file ~loc:LTerm_resources.Config "utop/init.ml" in
if Sys.file_exists fn then if Sys.file_exists xdg_fn then
ignore (Toploop.use_silently Format.err_formatter fn)); Some xdg_fn
else
let fn = Filename.concat LTerm_resources.home ".ocamlinit" in
if Sys.file_exists fn then
Some fn
else
None
in
(match init_fn with
| None -> ()
| Some fn ->
ignore (Toploop.use_silently Format.err_formatter fn : bool));
(* Load history after the initialization file so the user can change (* Load history after the initialization file so the user can change
the history file name. *) the history file name. *)
Lwt_main.run (init_history ()); Lwt_main.run (init_history ());