Skip to content

Commit

Permalink
fix(rtop): try load ~/.config/rtop/init.re, don't load utop config …
Browse files Browse the repository at this point in the history
…files (#2813)

* fix(rtop): try load `~/.config/rtop/init.re`, don't load utop config files

* chore: add changelog entry

* wip

* fix changelog
  • Loading branch information
anmonteiro authored Dec 2, 2024
1 parent d322b12 commit e49db1c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
8 changes: 7 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

- rtop: read `~/.config/rtop/init.re` configuration file (@anmonteiro, [#2813])
- the `-init FILE` flag works as before
- rtop: ignore `~/.ocamlinit.ml` or `~/.config/utop/init.ml` config files (@anmonteiro, [#2813])

## 3.14.0

- Support OCaml 5.3 (@anmonteiro,
Expand All @@ -15,7 +21,7 @@
[#2773](https://github.com/reasonml/reason/pull/2773))
- Wrap `let lazy patterns = ..` in parentheses (`let lazy(patterns) = ..`)
(@anmonteiro, [#2774](https://github.com/reasonml/reason/pull/2774))
- Print poly variants as normal variansts (@Sander Spies,
- Print poly variants as normal variants (@Sander Spies,
[#2708](https://github.com/reasonml/reason/pull/2708))
- Improve printing of anonymous function return type (@Sander Spies,
[#2686](https://github.com/reasonml/reason/pull/2686))
Expand Down
46 changes: 34 additions & 12 deletions rtop/rtop.ml
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
let () = UTop.require [ "reason.ocaml-migrate-parsetree"; "menhirLib" ]

let () =
try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH") with
| Not_found -> ()

let () = UTop.require [ "reason.easy_format"; "reason" ]
let () = Reason_toploop.main ()
let () = Reason_utop.init_reason ()

let () =
let print_init_message () =
print_string
"\n\
\ ___ _______ ________ _ __\n\
Expand All @@ -21,4 +11,36 @@ let () =
\ > let myList: list(string) = [\"first\", \"second\"];\n\
\ > #use \"./src/myFile.re\"; /* loads the file into here */\n"

let () = UTop_main.main ()
let start_utop () =
(match !Clflags.init_file with
| Some _ -> ()
| None ->
let xdg_fn =
LTerm_resources.xdgbd_file ~loc:LTerm_resources.Config "rtop/init.re"
in
(* NOTE(anmonteiro): in the future, we could try checking for
`~/.ocamlinit` and `~/.config/utop/init.ml` and convert those to Reason
*)
Clflags.init_file :=
(match Sys.file_exists xdg_fn with
| true -> Some xdg_fn
| false ->
(* If `~/.config/rtop/init.re` isn't found, we can't be loading a
user's `init.ml` because it'll be full of syntax errors for
`rtop`. Create an empty temp file instead. *)
Some (Filename.temp_file "rtop" ".re")));
UTop_main.main ()

let main () =
UTop.require [ "reason.ocaml-migrate-parsetree"; "menhirLib" ];

(try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH") with
| Not_found -> ());

UTop.require [ "reason.easy_format"; "reason" ];
Reason_toploop.main ();
Reason_utop.init_reason ();
print_init_message ();
start_utop ()

let () = main ()

0 comments on commit e49db1c

Please sign in to comment.