Last active
March 4, 2026 20:45
-
-
Save greglook/037e64fd5b7da0f84469769c93780f72 to your computer and use it in GitHub Desktop.
Clojure rebel-readline customizations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {:paths ["src" "resources"] | |
| ,,, | |
| :aliases | |
| {;; For a basic clojure REPL with an initial namespace and pretty-printing: | |
| ;; clj -M:repl | |
| :repl | |
| {:extra-paths ["dev" "test"] | |
| :extra-deps {org.clojure/tools.namespace {:mvn/version "1.3.0"} | |
| com.amperity/dialog {:mvn/version "1.0.1"} | |
| mvxcvi/puget {:mvn/version "1.3.2"}} | |
| :jvm-opts ["-XX:-OmitStackTraceInFastThrow" | |
| "-Ddialog.profile=repl"] | |
| :main-opts ["-e" "(require,'puget.printer)" | |
| "-e" "(clojure.main/repl,:init,#(do,(require,'acme.repl),(in-ns,'acme.repl)),:print,puget.printer/cprint)"]} | |
| ;; For a fancier rebel-readline experience with autocomplete and interruptible eval: | |
| ;; clojure -M:rebel | |
| :rebel | |
| {:extra-paths ["dev" "test"] | |
| :extra-deps {org.clojure/tools.namespace {:mvn/version "1.3.0"} | |
| org.clojure/tools.reader {:mvn/version "1.3.6"} | |
| com.bhauman/rebel-readline {:mvn/version "0.1.4"} | |
| com.amperity/dialog {:mvn/version "1.0.1"} | |
| mvxcvi/puget {:mvn/version "1.3.2"}} | |
| :jvm-opts ["-XX:-OmitStackTraceInFastThrow" | |
| "-Ddialog.profile=repl"] | |
| :main-opts ["-m" "acme.repl.main"]} | |
| ,,,}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns acme.repl | |
| (:require | |
| [clojure.java.io :as io] | |
| [clojure.repl :refer :all] | |
| [clojure.tools.namespace.repl :refer [refresh]] | |
| ,,,)) | |
| ;; other repl utilities |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns acme.repl.main | |
| "Main setup for the Acme REPL." | |
| (:require | |
| [clojure.repl :as clj-repl] | |
| ;; Prevent a weird startup issue with lazy-loading | |
| [clojure.tools.reader.edn] | |
| [io.aviso.exception :as ex] | |
| [puget.printer :as puget] | |
| [rebel-readline.clojure.line-reader :as rebel-reader] | |
| [rebel-readline.clojure.main :as rebel-main] | |
| [rebel-readline.core :as rebel-core] | |
| [rebel-readline.jline-api :as rebel-jline])) | |
| (def print-options | |
| "REPL value printer options." | |
| {,,,}) | |
| (defn init-ns | |
| "Initialize the REPL namespace entry." | |
| [] | |
| (require 'acme.repl) | |
| (in-ns 'acme.repl)) | |
| (defn interruptable-eval | |
| "Evaluate the provided form in a way that is interruptable with Ctrl+C." | |
| [form] | |
| (eval | |
| `(let [thread# (Thread/currentThread)] | |
| (clj-repl/set-break-handler! | |
| (fn handle-interrupt# | |
| [_signal#] | |
| (.stop thread#))) | |
| ~form))) | |
| (defn print-value | |
| "Print a syntax highlighted clojure value with Puget. This printer respects | |
| the current color settings set in the service. | |
| See `rebel-readline.main/syntax-highlight-prn`." | |
| [x] | |
| (binding [*out* (.. rebel-jline/*line-reader* getTerminal writer)] | |
| (puget/cprint x print-options))) | |
| (defn -main | |
| "Main entry point to start a new REPL." | |
| [] | |
| (rebel-core/ensure-terminal | |
| (rebel-main/repl | |
| :init init-ns | |
| :eval interruptable-eval | |
| :print print-value | |
| :caught ex/write-exception))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # vim: ft=bash | |
| set -e | |
| cd "$(dirname "${BASH_SOURCE[0]}")/.." | |
| if [[ -z $1 || $1 = rebel ]]; then | |
| exec clojure -M:dev:rebel | |
| elif [[ $1 = clj ]]; then | |
| exec clj -M:dev:repl | |
| else | |
| echo "Unknown REPL type: $1" >&2 | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment