Skip to content

Instantly share code, notes, and snippets.

@hcarty
Created May 11, 2015 14:37
Show Gist options
  • Select an option

  • Save hcarty/b2dab5324d0d4344d771 to your computer and use it in GitHub Desktop.

Select an option

Save hcarty/b2dab5324d0d4344d771 to your computer and use it in GitHub Desktop.
Snippet to toggle requiring/not requiring ;; in utop
(* Put this in ~/.ocamlinit to be able to toggle requiring ;; on and off *)
let toggle_semi =
let original = !UTop.parse_toplevel_phrase in
let no_semi str eos_is_error = original (str ^ ";;") eos_is_error in
let semi = ref true in
fun () ->
UTop.parse_toplevel_phrase := if !semi then no_semi else original;
semi := not !semi
;;
(* Include this line to not require ;; by default *)
toggle_semi ();;
@hcarty
Copy link
Copy Markdown
Author

hcarty commented May 11, 2015

The method and idea is originally from ocaml-community/utop#131

@frou
Copy link
Copy Markdown

frou commented Apr 6, 2020

We can then hook up a single key e.g. F5 to use your toggle function!

#require "lambda-term"

let () =
  LTerm_read_line.bind
    [{control = false; meta = false; shift = false; code = F5}]
    [LTerm_read_line.Edit (Custom toggle_semi)]

@hcarty
Copy link
Copy Markdown
Author

hcarty commented Apr 12, 2020

Ah, not bad!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment