Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ()
Loading