### ClojureScript REPL Setup with Rebel Readline Source: https://context7.com/bhauman/rebel-readline/llms.txt Provides `deps.edn` configuration and code examples for starting a ClojureScript REPL with Rebel Readline support, both programmatically and using a convenience function. ```clojure ;; deps.edn {:deps {com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}}} ;; Start from command line ;; clojure -m rebel-readline.cljs.main ;; Programmatic usage with ClojureScript REPL (require '[rebel-readline.core :as rebel] '[rebel-readline.clojure.line-reader :as line-reader] '[rebel-readline.cljs.service.local :as cljs-service] '[rebel-readline.cljs.repl :as cljs-repl] '[cljs.repl :as repl] '[cljs.repl.nashorn :as nashorn]) ;; Start ClojureScript REPL with Rebel Readline (rebel/with-line-reader (line-reader/create (cljs-service/create)) (repl/repl (nashorn/repl-env) :prompt (fn []) :read (cljs-repl/create-repl-read))) ;; Or use the convenience function (require '[rebel-readline.cljs.repl :as cljs-repl]) (cljs-repl/repl (nashorn/repl-env)) ``` -------------------------------- ### Rebel Readline Configuration File Example Source: https://context7.com/bhauman/rebel-readline/llms.txt An example of the `~/.clojure/rebel_readline.edn` file, showing settings for key maps, color themes, feature toggles, and custom key bindings. ```clojure ;; ~/.clojure/rebel_readline.edn { ;; Key bindings: :emacs (default) or :viins (vi insert mode) :key-map :emacs ;; Color theme: :dark-screen-theme, :light-screen-theme, or :neutral-screen-theme :color-theme :dark-screen-theme ;; Feature toggles :highlight true ; Syntax highlighting :completion true ; TAB completion :eldoc true ; Function signature display :indent true ; Auto-indentation :redirect-output true ; Protect prompt from concurrent output ;; Custom key bindings (applied after defaults) :key-bindings {:emacs [["^D" :clojure-doc-at-point] ["^X^X" :clojure-force-accept-line]] :viins [["^J" :clojure-force-accept-line]]}} ``` -------------------------------- ### Quick Start with Clojure CLI Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/README.md Invoke this command to start a Clojure REPL with Rebel readline editor input. ```shell clojure -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version "0.1.7"}}}" -m rebel-readline.main ``` -------------------------------- ### Start Rebel Readline with Boot Source: https://github.com/bhauman/rebel-readline/blob/master/README.md Integrate and start Rebel Readline using Boot with this command. ```shell boot -d com.bhauman/rebel-readline call -f rebel-readline.main/-main ``` -------------------------------- ### Start a basic nREPL Server Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-nrepl/README.md Launch a standalone nREPL server with specified dependencies and port. This command is useful for setting up a server to connect to. ```bash clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "1.3.1"}}}' -M -m nrepl.cmdline --port 7888 ``` -------------------------------- ### Install rebel-readline-nrepl as a Clojure Tool Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-nrepl/README.md Install the latest version of rebel-readline-nrepl using the clojure -Ttools command for convenient access. ```bash clojure -Ttools install-latest :lib com.github.bhauman/rebel-readline :coord '{:deps/root "rebel-readline-nrepl"}' :as nrebel ``` -------------------------------- ### Start Rebel Readline REPL with Leiningen Source: https://github.com/bhauman/rebel-readline/blob/master/README.md Use this command to start the REPL with Rebel Readline integration. ```shell lein trampoline run -m rebel-readline.main ``` -------------------------------- ### Start ClojureScript REPL with Rebel Readline (Leiningen) Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-cljs/README.md Add the rebel-readline-cljs dependency to your `project.clj` and use this command to start a REPL with the readline editor. Note that `lein run -m rebel-readline.cljs.main` will not work. ```shell lein trampoline run -m rebel-readline.cljs.main ``` -------------------------------- ### Start Rebel Readline REPL with Rebel Readline Main Source: https://context7.com/bhauman/rebel-readline/llms.txt Launches a fully configured Rebel Readline REPL. Custom prompts and initialization functions can be provided. Rebel Readline specific configurations like keymaps and color themes can also be applied. ```clojure (require '[rebel-readline.clojure.main :as rebel-main]) ;; Start a fully configured REPL (rebel-main/repl) ;; Start with custom options (rebel-main/repl :prompt #(print "my-app=> ") :init (fn [] (println "Welcome to my app!"))) ;; Start with rebel-readline specific config (rebel-main/repl* {:rebel-readline/config {:key-map :viins :color-theme :light-screen-theme :highlight true} :prompt #(print "=> ")}) ;; Entry point for -main (used by rebel-readline.main) ``` ```clojure (rebel-main/-main) ``` -------------------------------- ### Configure Rebel Readline nREPL Client Source: https://context7.com/bhauman/rebel-readline/llms.txt Configure `deps.edn` to use Rebel Readline as an nREPL client. This setup requires starting an nREPL server first and then connecting with the Rebel Readline client using specified host and port. ```clojure ;; deps.edn {:aliases {:nrebel {:extra-deps {com.bhauman/rebel-readline-nrepl {:mvn/version "0.1.8"}} :exec-fn rebel-readline.nrepl/connect :exec-args {:background-print false} :main-opts ["-m" "rebel-readline.nrepl.main"]}}} ``` ```bash ;; Start an nREPL server first ;; clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "1.3.1"}}}' -M -m nrepl.cmdline --port 7888 ``` ```bash ;; Connect with Rebel Readline nREPL client ;; clojure -T:nrebel :port 7888 ;; clojure -T:nrebel :host '"localhost"' :port 7888 ``` ```bash ;; CLI usage ;; clojure -M -m rebel-readline.nrepl.main --host localhost --port 7888 ``` ```bash ;; TLS support ;; clojure -T:nrebel :port 7888 :tls-key-file '"client.keys"' ``` ```clojure ;; Programmatic usage (require '[rebel-readline.nrepl.main :as nrepl-main]) (nrepl-main/start-repl {:port 7888 :host "localhost" :background-print true}) ``` -------------------------------- ### Start ClojureScript REPL with Rebel Readline (Clojure CLI) Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-cljs/README.md Use this command to start a Nashorn ClojureScript REPL with the Rebel readline editor using Clojure CLI tools. Ensure you use the `clojure` command, not `clj`, to avoid `rlwrap` interference. ```shell clojure -Sdeps '{:deps {com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}}}' -m rebel-readline.cljs.main ``` -------------------------------- ### Connect using installed Clojure Tool alias Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-nrepl/README.md Invoke the installed 'nrebel' alias to connect to an nREPL server, specifying the host and port. ```bash clojure -Tnrebel connect :port <50668> ``` -------------------------------- ### Syntax Highlight Printing for REPLs Source: https://context7.com/bhauman/rebel-readline/llms.txt Prints values with syntax highlighting, suitable for use as a custom `:print` function in REPLs. This example demonstrates integrating it with `clojure.main/repl` and Rebel Readline's input handling. ```clojure (require '[rebel-readline.clojure.main :as rebel-main] '[rebel-readline.core :as rebel] '[rebel-readline.clojure.line-reader :as line-reader] '[rebel-readline.clojure.service.local :as service] '[rebel-readline.jline-api :as api]) ;; Use syntax-highlighted printing in REPL (rebel/with-line-reader (line-reader/create (service/create)) (binding [*out* (api/safe-terminal-writer api/*line-reader*)] (clojure.main/repl :prompt (fn []) :read (rebel-main/create-repl-read) :print rebel-main/syntax-highlight-prn)) ;; Print a highlighted string directly (rebel-main/syntax-highlight-prn* "(defn hello [x] (str \"Hello \" x))") ;; Print a highlighted value (rebel-main/syntax-highlight-prn {:a 1 :b [2 3 4]}) ``` -------------------------------- ### Start Rebel Readline REPL with Clojure CLI Source: https://context7.com/bhauman/rebel-readline/llms.txt Quickly start the Rebel Readline REPL using Clojure CLI tools. For Java 22+, use the specified JVM option to suppress native access warnings. ```shell clojure -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version "0.1.7"}}}" -m rebel-readline.main ``` ```shell clojure -J--enable-native-access=ALL-UNNAMED -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version "0.1.7"}}}" -m rebel-readline.main ``` -------------------------------- ### Launch Rebel Readline REPL with Clojure CLI Source: https://github.com/bhauman/rebel-readline/blob/master/README.md Use this command to quickly try Rebel Readline by installing the Clojure CLI tools. Ensure you are using `clojure` and not `clj` to avoid readline conflicts. ```shell clojure -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version \"0.1.5\"}}}" -M -m rebel-readline.main ``` -------------------------------- ### Integrate Rebel Readline with clojure.main/repl Source: https://context7.com/bhauman/rebel-readline/llms.txt Use `rebel-readline.core/with-line-reader` to bind a line reader and enable all readline features during a REPL session. This example shows basic usage and integration with syntax highlighting and custom configurations. ```clojure (require '[rebel-readline.core :as rebel] '[rebel-readline.clojure.line-reader :as line-reader] '[rebel-readline.clojure.service.local :as service] '[rebel-readline.clojure.main :as rebel-main] '[rebel-readline.jline-api :as api]) ;; Basic usage with clojure.main/repl (rebel/with-line-reader (line-reader/create (service/create)) (clojure.main/repl :prompt (fn []) ; prompt handled by line-reader :read (rebel-main/create-repl-read))) ``` ```clojure ;; With syntax-highlighted output and custom configuration (rebel/with-line-reader (line-reader/create (service/create {:highlight true :completion true :eldoc true :indent true :key-map :emacs :color-theme :dark-screen-theme})) (binding [*out* (api/safe-terminal-writer api/*line-reader*)] (clojure.main/repl :prompt (fn []) :read (rebel-main/create-repl-read) :print rebel-main/syntax-highlight-prn))) ``` -------------------------------- ### Use Rebel Readline with clojure.main/repl via with-readline-in Source: https://context7.com/bhauman/rebel-readline/llms.txt Employ `rebel-readline.core/with-readline-in` to bind `*in*` to a readline-backed input stream, simplifying readline integration. This example includes a graceful fallback for non-terminal environments. ```clojure (require '[rebel-readline.core :as rebel] '[rebel-readline.clojure.line-reader :as line-reader] '[rebel-readline.clojure.service.local :as service]) ;; Simple usage - readline handles all input (rebel/with-readline-in (line-reader/create (service/create)) (clojure.main/repl :prompt (fn []))) ``` ```clojure ;; With graceful fallback for non-terminal environments (try (rebel/with-readline-in (line-reader/create (service/create)) (clojure.main/repl :prompt (fn []))) (catch clojure.lang.ExceptionInfo e (if (-> e ex-data :type (= :rebel-readline.jline-api/bad-terminal)) (do (println (.getMessage e)) (clojure.main/repl)) ; fallback to basic REPL (throw e)))) ``` -------------------------------- ### Basic Rebel Readline Usage in ClojureScript Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-cljs/README.md This is a simple usage example for integrating the rebel-readline service into a ClojureScript REPL. It sets up the line reader and creates a REPL read function, handling the prompt via the line reader. ```clojure (rebel-readline.core/with-line-reader (rebel-readline.clojure.core/create (rebel-readline.cljs.service.local/create)) (cljs.repl/repl :prompt (fn []) ;; prompt is handled by line-reader :read (rebel-readline.cljs.repl/create-repl-read))) ``` -------------------------------- ### Add rebel-readline-nrepl to deps.edn Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-nrepl/README.md Configure rebel-readline-nrepl as an alias in your deps.edn file for easy execution. This setup includes optional background print configuration. ```clojure { :aliases { :nrebel { :extra-deps {com.bhauman/rebel-readline-nrepl {:mvn/version "0.1.8"}} :exec-fn rebel-readline.nrepl/connect :exec-args {:background-print false} ;; Optional configuration parameters :main-opts ["-m" "rebel-readline.nrepl.main"] } } } ``` -------------------------------- ### Define rebel-readline alias in Leiningen project.clj Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/README.md Create a project-specific alias for starting the rebel-readline REPL to simplify commands. ```clojure { ... :aliases {"rebl" ["trampoline" "run" "-m" "rebel-readline.main"]} } ``` -------------------------------- ### Pass CLI Parameters to Rebel Readline Source: https://github.com/bhauman/rebel-readline/blob/master/README.md You can customize Rebel Readline's behavior by passing parameters when launching it via the `clojure -X` command. For example, disabling syntax highlighting. ```shell clojure -Xrebel :highlight false ``` -------------------------------- ### Launch Rebel Readline with CLI Parameters (Alternative) Source: https://github.com/bhauman/rebel-readline/blob/master/README.md This demonstrates launching Rebel Readline using the `rebel-readline.main` CLI with a specific option to disable syntax highlighting. This method is an alternative to using the tool alias. ```shell clojure -Mrebel --no-highlight ``` -------------------------------- ### Invoke rebel-readline-nrepl directly from classpath Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-nrepl/README.md Run rebel-readline-nrepl as a main class if it's available on the classpath, specifying host and port. ```bash clojure -m rebel-readline.nrepl.main --host localhost --port 7888 ``` -------------------------------- ### Use Simple REPL Service Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/README.md In the absence of specific services for nREPL, SocketREPL, or pREPL, the `rebel-readline.clojure.service.simple` service can be used as a fallback. ```clojure rebel-readline.clojure.service.simple ``` -------------------------------- ### Launch rebel-readline-nrepl via command line Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-nrepl/README.md Execute the configured :nrebel alias from the command line, specifying the desired port for the nREPL connection. ```bash clojure -T:nrebel :port <50668> ``` -------------------------------- ### Configure Key Bindings Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/README.md Configure key bindings in the config file. For literal characters, use a list of chars or ints like (\d) instead of serialized key names. ```clojure { ... :key-bindings { :emacs [["^D" :clojure-doc-at-point]] :viins [["^J" :clojure-force-accept-line]] } } ``` -------------------------------- ### Connect using Clojure Tool alias with host and port Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-nrepl/README.md Connect to an nREPL server using a Clojure Tool alias, specifying the host and port. ```bash clojure -Tnrebel connect :host localhost :port 7888 ``` -------------------------------- ### Create Clojure Local Service with Rebel Readline Source: https://context7.com/bhauman/rebel-readline/llms.txt Provides completion, documentation, and evaluation by querying the local Clojure runtime. Configure features like eval timeout, highlighting, completion, and keymaps. The service implements multimethods for completion, metadata resolution, source lookup, and evaluation. ```clojure (require '[rebel-readline.clojure.service.local :as service]) ;; Create default service (def svc (service/create)) ;; Create with configuration options (def svc-configured (service/create {:eval-timeout 3000 ; timeout for inline eval (ms) :highlight true :completion true :eldoc true :indent true :key-map :viins ; vi insert mode bindings :color-theme :light-screen-theme})) ;; The service implements these multimethods: ;; -complete : TAB completion using Compliment library ;; -resolve-meta: Resolve var metadata ;; -source : Get source code for vars ;; -apropos : Search for matching vars ;; -doc : Get documentation ;; -eval : Evaluate forms with timeout ;; -read-string : Read Clojure forms from strings ;; -current-ns : Get current namespace ``` -------------------------------- ### Connect to nREPL Server using :nrebel alias Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-nrepl/README.md Connect to a running nREPL server using the :nrebel alias defined in deps.edn, specifying the port. ```bash clojure -T:nrebel :port 7888 ``` -------------------------------- ### Key Bindings Reference and Programmatic Usage Source: https://context7.com/bhauman/rebel-readline/llms.txt Lists default Emacs and Vi mode key bindings for common REPL operations. Shows how to view current bindings programmatically and switch key map modes. ```clojure ;; Emacs mode key bindings (default) ;; Ctrl-C : Abort current line ;; Ctrl-D : End of stream (quit REPL at line start) ;; TAB : Complete word or indent line ;; Ctrl-X Ctrl-D : Show documentation for symbol at point ;; Ctrl-X Ctrl-S : Show source for symbol at point ;; Ctrl-X Ctrl-A : Show apropos for symbol at point ;; Ctrl-X Ctrl-E : Inline eval expression before point ;; Ctrl-X Ctrl-M : Force accept line (even if incomplete) ;; Ctrl-X Ctrl-I : Indent current line ;; Vi mode bindings (in command mode, prefix with \) ;; \d : Show documentation ;; \s : Show source ;; \a : Show apropos ;; \e : Inline eval ;; View current bindings programmatically (require '[rebel-readline.jline-api :as api]) ;; In a REPL with rebel-readline active: ;; :repl/key-bindings ; show all bindings ;; :repl/key-bindings doc ; search for "doc" in bindings ;; :repl/set-key-map :viins ; switch to vi mode ``` -------------------------------- ### Connect to nREPL Server with specified host and port Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-nrepl/README.md Connect to an nREPL server, explicitly defining both the host and port for the connection. ```bash clojure -T:nrebel :host localhost :port 7888 ``` -------------------------------- ### rebel-readline.clojure.main/repl Source: https://context7.com/bhauman/rebel-readline/llms.txt A convenience function that sets up a complete Rebel Readline REPL with all features configured. ```APIDOC ## rebel-readline.clojure.main/repl ### Description A convenience function that sets up a complete Rebel Readline REPL with all features configured. ### Method (require '[rebel-readline.clojure.main :as rebel-main]) ### Endpoint N/A (Function call) ### Parameters - `options` (map) - Optional - Configuration options for the REPL. - `:prompt` (fn) - Function to display the prompt. - `:init` (fn) - Function to execute on REPL initialization. - `:rebel-readline/config` (map) - Rebel Readline specific configuration options (e.g., `:key-map`, `:color-theme`, `:highlight`). ### Request Example ```clojure ;; Start a fully configured REPL (rebel-main/repl) ;; Start with custom options (rebel-main/repl :prompt #(print "my-app=> ") :init (fn [] (println "Welcome to my app!"))) ;; Start with rebel-readline specific config (rebel-main/repl* {:rebel-readline/config {:key-map :viins :color-theme :light-screen-theme :highlight true} :prompt #(print "=> ")}) ;; Entry point for -main (used by rebel-readline.main) (rebel-main/-main) ``` ### Response #### Success Response (200) Starts an interactive REPL session. #### Response Example No direct response, as it starts an interactive session. ``` -------------------------------- ### Configure global Leiningen alias for rebel-readline Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/README.md Set up a global alias in ~/.lein/profiles.clj to easily launch the rebel-readline REPL. ```clojure { ... :user {:aliases {"rebl" ["trampoline" "run" "-m" "rebel-readline.main"]}} } ``` -------------------------------- ### Add Custom REPL Command in Clojure Source: https://context7.com/bhauman/rebel-readline/llms.txt Demonstrates how to add a custom command to the REPL using `defmethod` for `commands/command` and `commands/command-doc`. Also shows the `add-command` helper and retrieving all commands. ```clojure (require '[rebel-readline.commands :as commands]) ;; Built-in commands (type :repl/help to see all): ;; :repl/help - Show help and key bindings ;; :repl/toggle-indent - Toggle auto-indentation ;; :repl/toggle-highlight - Toggle syntax highlighting ;; :repl/toggle-eldoc - Toggle function signature display ;; :repl/toggle-completion - Toggle TAB completion ;; :repl/toggle-color - Toggle all ANSI coloring ;; :repl/set-color-theme - Change color theme ;; :repl/set-key-map - Change key bindings (emacs/viins) ;; :repl/key-bindings - Display current key bindings ;; :repl/quit - Exit the REPL ;; :repl/*e - Show last internal error ;; Add a custom command (defmethod commands/command :repl/clear-screen [_] (print "\033[2J\033[H") (flush)) (defmethod commands/command-doc :repl/clear-screen [_] "Clears the terminal screen.") ;; Use the add-command helper (commands/add-command :repl/greet (fn [] (println "Hello from Rebel Readline!")) "Prints a friendly greeting.") ;; Get all available commands (commands/all-commands) ;; => (:repl/help :repl/toggle-indent :repl/quit ...) ``` -------------------------------- ### Create Clojure Line Reader with Rebel Readline Source: https://context7.com/bhauman/rebel-readline/llms.txt Configures a line reader with Clojure-specific features. Use `local-service/create` for full features or `simple-service/create` for a lighter version. Custom options can be passed to `local-service/create` to enable/disable features like syntax highlighting, completion, and auto-indentation. ```clojure (require '[rebel-readline.clojure.line-reader :as line-reader] '[rebel-readline.clojure.service.local :as local-service] '[rebel-readline.clojure.service.simple :as simple-service]) ;; Create with local service (full features) (def reader (line-reader/create (local-service/create))) ;; Create with custom options (def reader-custom (line-reader/create (local-service/create {:highlight true ; syntax highlighting :completion true ; TAB completion :eldoc true ; show function signatures :indent true ; auto-indentation :redirect-output true ; protect prompt from concurrent output :key-map :emacs ; or :viins for vi mode :color-theme :dark-screen-theme}))) ; or :light-screen-theme ;; Create with simple service (fewer features, works without eval) (def reader-simple (line-reader/create (simple-service/create))) ;; Override specific components (def reader-custom-completer (line-reader/create (local-service/create) {:completer my-custom-completer :highlighter my-custom-highlighter :parser my-custom-parser})) ``` -------------------------------- ### Launch Rebel Readline REPL using Tool Alias Source: https://github.com/bhauman/rebel-readline/blob/master/README.md After configuring the `deps.edn` alias, you can launch the REPL in your project directory using this command. It's recommended to use `clojure` over `clj` to prevent readline interference. ```shell clojure -Xrebel ``` -------------------------------- ### Configure Default Vi Key Bindings Source: https://github.com/bhauman/rebel-readline/blob/master/README.md Set vi key bindings by adding this configuration to your deps.edn or ~/.clojure/rebel_readline.edn file. ```clojure {:key-map :viins} ``` -------------------------------- ### Connect to nREPL over TLS Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-nrepl/README.md Connect to an nREPL server that is configured for TLS, providing the path to the TLS key file. ```bash clojure -T:nrebel :port 50668 :tls-key-file '"client.keys"' ``` -------------------------------- ### rebel-readline.clojure.service.local/create Source: https://context7.com/bhauman/rebel-readline/llms.txt Creates a local Clojure service that provides completion, documentation, source lookup, and evaluation by querying the local Clojure runtime. ```APIDOC ## rebel-readline.clojure.service.local/create ### Description Creates a local Clojure service that provides completion, documentation, source lookup, and evaluation by querying the local Clojure runtime. ### Method (require '[rebel-readline.clojure.service.local :as service]) ### Endpoint N/A (Function call) ### Parameters - `options` (map) - Optional - Configuration options for the service. - `:eval-timeout` (number) - Timeout for inline eval in milliseconds. - `:highlight` (boolean) - Enable syntax highlighting. - `:completion` (boolean) - Enable TAB completion. - `:eldoc` (boolean) - Show function signatures. - `:indent` (boolean) - Enable auto-indentation. - `:key-map` (keyword) - Keymap to use (:emacs or :viins). - `:color-theme` (keyword) - Color theme to use (:dark-screen-theme or :light-screen-theme). ### Request Example ```clojure ;; Create default service (def svc (service/create)) ;; Create with configuration options (def svc-configured (service/create {:eval-timeout 3000 ; timeout for inline eval (ms) :highlight true :completion true :eldoc true :indent true :key-map :viins ; vi insert mode bindings :color-theme :light-screen-theme})) ``` ### Response #### Success Response (200) A local Clojure service instance. #### Response Example ```clojure ;; Example of a created service instance (internal representation) #object[rebel_readline.clojure.service.local$reify__4567 0x98765432 "rebel_readline.clojure.service.local$reify__4567@98765432"] ``` ### Additional Information The service implements the following multimethods: - `-complete`: TAB completion using Compliment library - `-resolve-meta`: Resolve var metadata - `-source`: Get source code for vars - `-apropos`: Search for matching vars - `-doc`: Get documentation - `-eval`: Evaluate forms with timeout - `-read-string`: Read Clojure forms from strings - `-current-ns`: Get current namespace ``` -------------------------------- ### Add Documentation for Commands Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/README.md Add documentation for a command by adding a method to the `rebel-readline.commands/command-doc` multimethod. This is useful for providing help text for custom commands. ```clojure rebel-readline.commands/command-doc ``` -------------------------------- ### Configure Rebel Readline as a Tool in deps.edn Source: https://github.com/bhauman/rebel-readline/blob/master/README.md Add this configuration to your `~/.clojure/deps.edn` file to set up Rebel Readline as a convenient tool alias. This allows launching the REPL with `clojure -Xrebel`. ```clojure { \ ... \ :aliases {:rebel {:extra-deps {com.bhauman/rebel-readline {:mvn/version \"0.1.5\"}} \ :exec-fn rebel-readline.tool/repl \ :exec-args {} \ :main-opts [\"-m\" \"rebel-readline.main\"]}} \ ... \ } ``` -------------------------------- ### rebel-readline.clojure.main/syntax-highlight-prn Source: https://context7.com/bhauman/rebel-readline/llms.txt Print values with syntax highlighting. Useful as a custom `:print` function for REPLs. ```APIDOC ## rebel-readline.clojure.main/syntax-highlight-prn ### Description Print values with syntax highlighting. Useful as a custom `:print` function for REPLs. ### Method (require '[rebel-readline.clojure.main :as rebel-main]) ### Endpoint N/A (Function call) ### Parameters - `value` (any) - The value to print with syntax highlighting. ### Request Example ```clojure ;; Use syntax-highlighted printing in REPL (rebel/with-line-reader (line-reader/create (service/create)) (binding [*out* (api/safe-terminal-writer api/*line-reader*)] (clojure.main/repl :prompt (fn []) :read (rebel-main/create-repl-read) :print rebel-main/syntax-highlight-prn))) ;; Print a highlighted string directly (rebel-main/syntax-highlight-prn* "(defn hello [x] (str \"Hello \" x))") ;; Print a highlighted value (rebel-main/syntax-highlight-prn {:a 1 :b [2 3 4]}) ``` ### Response #### Success Response (200) Prints the syntax-highlighted representation of the input value to standard output. #### Response Example ```clojure ;; Example output for (rebel-main/syntax-highlight-prn {:a 1 :b [2 3 4]}) ;; {:a 1, :b [2 3 4]} ;; (where the output is syntax highlighted in the terminal) ``` ``` -------------------------------- ### Create Repl-Read Function for Clojure Main Source: https://context7.com/bhauman/rebel-readline/llms.txt Replaces `clojure.main/repl-read` to use Rebel Readline for input, handling multiple forms per line by buffering. This is used in conjunction with `clojure.main/repl` and `rebel/with-line-reader`. ```clojure (require '[rebel-readline.clojure.main :as rebel-main] '[rebel-readline.core :as rebel] '[rebel-readline.clojure.line-reader :as line-reader] '[rebel-readline.clojure.service.local :as service]) ;; Use create-repl-read with clojure.main/repl (rebel/with-line-reader (line-reader/create (service/create)) (clojure.main/repl :prompt (fn []) :read (rebel-main/create-repl-read))) ;; create-repl-read is a constructor that returns a stateful reader function ;; It buffers multiple forms if user enters them on one line: ;; user=> (+ 1 2) (+ 3 4) ;; 3 ;; 7 ``` -------------------------------- ### rebel-readline.clojure.main/create-repl-read Source: https://context7.com/bhauman/rebel-readline/llms.txt Creates a replacement for `clojure.main/repl-read` that uses Rebel Readline for input. Handles multiple forms per line by buffering. ```APIDOC ## rebel-readline.clojure.main/create-repl-read ### Description Creates a replacement for `clojure.main/repl-read` that uses Rebel Readline for input. Handles multiple forms per line by buffering. ### Method (require '[rebel-readline.clojure.main :as rebel-main]) ### Endpoint N/A (Function call) ### Parameters None explicitly defined as parameters in the function signature, but it's used within a context that provides line reading capabilities. ### Request Example ```clojure ;; Use create-repl-read with clojure.main/repl (rebel/with-line-reader (line-reader/create (service/create)) (clojure.main/repl :prompt (fn []) :read (rebel-main/create-repl-read))) ``` ### Response #### Success Response (200) A stateful reader function compatible with `clojure.main/repl`. #### Response Example ```clojure ;; Example of how it handles multiple forms: ;; user=> (+ 1 2) (+ 3 4) ;; 3 ;; 7 ``` ### Additional Information This function is a constructor that returns a stateful reader function. It buffers multiple forms if the user enters them on a single line. ``` -------------------------------- ### Rebel Readline Configuration Options Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/README.md This map in ~/.clojure/rebel_readline.edn allows customization of key maps, color themes, syntax highlighting, completion, eldoc, auto-indentation, and output redirection. ```clojure :key-map - either :viins or :emacs. Defaults to :emacs :color-theme - either :light-screen-theme or :dark-screen-theme :highlight - boolean, whether to syntax highlight or not. Defaults to true :completion - boolean, whether to complete on tab. Defaults to true :eldoc - boolean, whether to display function docs as you type. Defaults to true :indent - boolean, whether to auto indent code on newline. Defaults to true :redirect-output - boolean, rebinds root *out* during read to protect linereader Defaults to true :key-bindings - map of key-bindings that get applied after all other key bindings have been applied ``` -------------------------------- ### REPL with Rebel-readline and Fallback Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/README.md Use rebel-readline with a fallback to the default clojure.main/repl in case of a bad terminal configuration, catching specific ExceptionInfo types. ```clojure (try (rebel-readline.core/with-readline-in (rebel-readline.clojure.line-reader/create (rebel-readline.clojure.service.local/create)) (clojure.main/repl :prompt (fn[]))) (catch clojure.lang.ExceptionInfo e (if (-> e ex-data :type (= :rebel-readline.jline-api/bad-terminal)) (do (println (.getMessage e)) (clojure.main/repl)) (throw e)))) ``` -------------------------------- ### Execute integrated rebel-readline-nrepl alias Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-nrepl/README.md Run the :nrebelly alias defined in your project's deps.edn to connect to the nREPL server. ```bash clojure -T:nrebelly ``` -------------------------------- ### Configure Rebel Readline in Leiningen Source: https://context7.com/bhauman/rebel-readline/llms.txt Integrate Rebel Readline into Leiningen projects by adding it as a dependency and defining an alias. Alternatively, configure it globally in `~/.lein/profiles.clj`. Use 'trampoline' for proper terminal access when launching. ```clojure ;; project.clj - add dependency {:dependencies [[com.bhauman/rebel-readline "0.1.7"]] :aliases {"rebl" ["trampoline" "run" "-m" "rebel-readline.main"]}} ;; Or add globally in ~/.lein/profiles.clj {:user {:dependencies [[com.bhauman/rebel-readline "0.1.7"]] :aliases {"rebl" ["trampoline" "run" "-m" "rebel-readline.main"]}}} ;; Launch with: lein rebl ;; Note: Must use 'trampoline' for proper terminal access ``` -------------------------------- ### Easier REPL Wrapping with Rebel Readline Source: https://github.com/bhauman/rebel-readline/blob/master/README.md Utilize with-readline-in for a more straightforward way to wrap the REPL with Rebel Readline's capabilities. ```clojure (rebel-readline.core/with-readline-in (rebel-readline.clojure.line-reader/create (rebel-readline.clojure.service.local/create)) (clojure.main/repl :prompt (fn []))) ``` -------------------------------- ### Integrate rebel-readline-nrepl into project deps.edn Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline-nrepl/README.md Add rebel-readline-nrepl as a dependency within your project's deps.edn file, defining an alias for easy execution with specified host and port. ```clojure {:aliases {:nrebelly {:extra-deps {com.bhauman/rebel-readline-nrepl {:mvn/version "NOT-PUBLISHED-YET"}} :exec-fn rebel-readline.nrepl/connect :exec-args {:host "localhost" :port 7888}}}} ``` -------------------------------- ### Rebel Readline CLI Options Source: https://github.com/bhauman/rebel-readline/blob/master/README.md This lists the available command-line options for Rebel Readline when launched via `rebel-readline.main`. These options allow customization of keymaps, color themes, and feature toggles. ```shell Options: -h, --help Display help -k, --key-map KEYMAP :emacs Choose between :viins or :emacs -t, --color-theme THEME :dark-screen-theme :(light, dark, or neutral)-screen-theme --no-highlight Disable syntax highlighting --no-completion Disable code completion --no-eldoc Disable function documentation display --no-indent Disable auto indentation --no-redirect-output Disable output redirection -b, --key-bindings BINDINGS Specify custom key bindings -c, --config CONFIG Path to a config file ``` -------------------------------- ### Add New Commands Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/README.md New commands can be added by defining methods for the `rebel-readline.commands/command` multimethod. This allows for extending the functionality of the REPL. ```clojure rebel-readline.commands/command ``` -------------------------------- ### Configure Rebel Readline as a Clojure Tool Source: https://context7.com/bhauman/rebel-readline/llms.txt Configure `deps.edn` for using Rebel Readline as a Clojure tool with `-X` or `-T` flags. This allows launching Rebel Readline with customizable options for key mapping and syntax highlighting. ```clojure ;; deps.edn configuration for tool usage {:aliases {:rebel {:extra-deps {com.bhauman/rebel-readline {:mvn/version "0.1.7"}} :exec-fn rebel-readline.tool/repl :exec-args {:key-map :emacs :highlight true :color-theme :dark-screen-theme}}}} ``` ```bash ;; Launch as exec function ;; clojure -X:rebel ``` ```bash ;; Launch as tool with overrides ;; clojure -X:rebel :highlight false :key-map :viins ``` ```bash ;; Launch as standalone tool ;; clojure -T:rebel ``` ```clojure ;; The function signature (require '[rebel-readline.tool :as tool]) (tool/repl {:key-map :emacs :highlight true :completion true :eldoc true :indent true :color-theme :dark-screen-theme}) ``` -------------------------------- ### Rebel Readline Configuration Options Source: https://github.com/bhauman/rebel-readline/blob/master/README.md These are the available configuration options for Rebel Readline, which can be set in deps.edn or ~/.clojure/rebel_readline.edn. ```clojure :config - path to an edn configuration file :key-map - :viins or :emacs (default: :emacs) :color-theme - (:light, :dark or :neutral)-screen-theme :highlight - (boolean) enable syntax highlighting (default: true) :completion - (boolean) enable code completion (default: true) :eldoc - (boolean) enable function documentation display (default: true) :indent - (boolean) enable auto indentation (default: true) :redirect-output - (boolean) rebinds output during read (default: true) :key-bindings - map of key bindings to apply after others ``` -------------------------------- ### Use Rebel Readline as Clojure REPL Read Function Source: https://github.com/bhauman/rebel-readline/blob/master/README.md Replace clojure.main/repl-read behavior with Rebel Readline's core functionality. Ensure prompt is handled by the line-reader. ```clojure (rebel-readline.core/with-line-reader (rebel-readline.clojure.line-reader/create (rebel-readline.clojure.service.local/create {:highlight false})) (clojure.main/repl :prompt (fn []) ;; prompt is handled by line-reader :read (rebel-readline.clojure.main/create-repl-read))) ``` -------------------------------- ### Launch Rebel Readline as a Standalone Tool Source: https://github.com/bhauman/rebel-readline/blob/master/README.md This command launches Rebel Readline as a standalone tool, useful for quick testing or when not working within a specific project context. ```shell clojure -T:rebel ``` -------------------------------- ### rebel-readline.clojure.line-reader/create Source: https://context7.com/bhauman/rebel-readline/llms.txt Creates a configured line reader with Clojure-specific features including syntax highlighting, completion, and auto-indentation. ```APIDOC ## rebel-readline.clojure.line-reader/create ### Description Creates a configured line reader with Clojure-specific features including syntax highlighting, completion, and auto-indentation. ### Method (require '[rebel-readline.clojure.line-reader :as line-reader]) ### Endpoint N/A (Function call) ### Parameters None explicitly defined as parameters in the function signature, but accepts service implementations and configuration maps. ### Request Example ```clojure ;; Create with local service (full features) (def reader (line-reader/create (local-service/create))) ;; Create with custom options (def reader-custom (line-reader/create (local-service/create {:highlight true ; syntax highlighting :completion true ; TAB completion :eldoc true ; show function signatures :indent true ; auto-indentation :redirect-output true ; protect prompt from concurrent output :key-map :emacs ; or :viins for vi mode :color-theme :dark-screen-theme}))) ; or :light-screen-theme ;; Create with simple service (fewer features, works without eval) (def reader-simple (line-reader/create (simple-service/create))) ;; Override specific components (def reader-custom-completer (line-reader/create (local-service/create) {:completer my-custom-completer :highlighter my-custom-highlighter :parser my-custom-parser})) ``` ### Response #### Success Response (200) A configured line reader instance. #### Response Example ```clojure ;; Example of a created reader instance (internal representation) #object[rebel_readline.clojure.line_reader$reify__1234 0x12345678 "rebel_readline.clojure.line_reader$reify__1234@12345678"] ``` ``` -------------------------------- ### Configure Rebel Readline in deps.edn Source: https://context7.com/bhauman/rebel-readline/llms.txt Add Rebel Readline as an alias in your `~/.clojure/deps.edn` for convenient access. This configuration enables Rebel Readline with specified main options and JVM options for Java 22+. ```clojure ;; ~/.clojure/deps.edn {:aliases {:rebel {:extra-deps {com.bhauman/rebel-readline {:mvn/version "0.1.7"}} :exec-fn rebel-readline.tool/repl :exec-args {} :main-opts ["-m" "rebel-readline.main"] ;; For Java 22+ :jvm-opts ["--enable-native-access=ALL-UNNAMED"]}}} ;; Launch with: ;; clojure -M:rebel (using main-opts) ;; clojure -X:rebel (using exec-fn) ;; clojure -T:rebel (as a tool) ``` -------------------------------- ### Create Rebel Readline Alias in Leiningen Source: https://github.com/bhauman/rebel-readline/blob/master/README.md Define a Leiningen alias in project.clj for simplified REPL launching. ```clojure :aliases {"rebl" ["trampoline" "run" "-m" "rebel-readline.main"]} ``` -------------------------------- ### Wrap REPL with Rebel-readline Input Stream Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/README.md Wrap a REPL call with rebel-readline.core/with-readline-in to bind *in* to an input-stream supplied by the line reader. ```clojure (rebel-readline.core/with-readline-in (rebel-readline.clojure.line-reader/create (rebel-readline.clojure.service.local/create)) (clojure.main/repl :prompt (fn[]))) ``` -------------------------------- ### Add rebel-readline globally to Leiningen profiles Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/README.md Configure rebel-readline as a global dependency in your ~/.lein/profiles.clj for use across projects. ```clojure { ... :user {:dependencies [[com.bhauman/rebel-readline "0.1.7"]]} } ``` -------------------------------- ### Debug REPL Macro with Local Context Source: https://context7.com/bhauman/rebel-readline/llms.txt Implement a `break` macro using `rebel-readline.clojure.main/break` to create a contextual debug REPL. This macro allows access to local bindings within the scope where it is called, inspired by techniques from 'Joy of Clojure'. ```clojure (require '[rebel-readline.clojure.main :as rebel-main]) ;; The break macro creates a debug REPL with access to local bindings (defn my-function [x y] (let [sum (+ x y) product (* x y)] ;; Insert a breakpoint - drops into REPL with local context (rebel-main/break) ;; In the debug REPL, you can access: x, y, sum, product {:sum sum :product product})) ;; When (my-function 3 4) is called, you'll get a debug=> prompt ;; where you can evaluate: x => 3, y => 4, sum => 7, product => 12 ;; Implementation details: (defmacro local-context [] (let [symbols (keys &env)] (zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols))) (defn contextual-eval [ctx expr] (eval `(let [~@(mapcat (fn [[k v]] [k `'~v]) ctx)] ~expr))) ``` -------------------------------- ### Integrate Rebel-readline with Clojure REPL Source: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/README.md Replace clojure.main/repl-read behavior to use rebel-readline. This ensures the line-reader is only engaged when the REPL loop is reading, avoiding interference with other input stream operations. ```clojure (rebel-readline.core/with-line-reader (rebel-readline.clojure.line-reader/create (rebel-readline.clojure.service.local/create)) (clojure.main/repl :prompt (fn []) ;; prompt is handled by line-reader :read (rebel-readline.clojure.main/create-repl-read))) ``` -------------------------------- ### Add Rebel Readline Dependency with Leiningen Source: https://github.com/bhauman/rebel-readline/blob/master/README.md Add this dependency to your project.clj file to include Rebel Readline in your project. ```clojure [com.bhauman/rebel-readline "0.1.5"] ```