Skip to content

Instantly share code, notes, and snippets.

@metametadata
Last active January 1, 2019 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metametadata/c11044a5d490eac7158ae535c10ce45c to your computer and use it in GitHub Desktop.
Save metametadata/c11044a5d490eac7158ae535c10ce45c to your computer and use it in GitHub Desktop.
Customized rebel-readline REPL
(ns repl.rebel
"Entry point for starting rebel-readline REPL.
Inspired by rebel-readline.main.
Usage: [LEIN_FAST_TRAMPOLINE=1] lein trampoline run -m repl.rebel [init-ns]"
(:require [clojure.repl :as clj-repl]
[rebel-readline.core :as rebel-core]
[rebel-readline.clojure.main :as rebel-clj-main]))
(defn -handle-sigint-form
[]
`(let [thread# (Thread/currentThread)]
(clj-repl/set-break-handler! (fn [_signal#] (.stop thread#)))))
(defn -main
[& [init-ns]]
(rebel-core/ensure-terminal
(rebel-clj-main/repl*
{:init (fn []
; HACK: rebel-readline doesn't have a convenient way to change init ns (it's always `user`).
; See https://github.com/bhauman/rebel-readline/issues/157.
(when (some? init-ns)
(let [init-ns (symbol init-ns)]
(require init-ns)
(in-ns init-ns))))
:eval (fn [form]
; HACK: allows Ctrl+C to interrupt long running tasks.
; See https://github.com/bhauman/rebel-readline/issues/180#issuecomment-429057767.
(eval `(do ~(-handle-sigint-form) ~form)))})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment