Skip to content

Commit c3c903a

Browse files
committed
[Fix #2572] Make it possible to a start a one-off ClojureScript REPL without defining a new REPL type
1 parent 91e4767 commit c3c903a

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Changes
66

77
* [#2711](https://github.com/clojure-emacs/cider/pull/2711): `cider-selector` has more robust handling for edge cases.
8+
* [#2572](https://github.com/clojure-emacs/cider/issues/2572): Make it possible to a start a one off ClojureScript REPL without defining a new REPL type.
89

910
### Bugs fixed
1011

cider.el

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -770,15 +770,30 @@ Figwheel for details."
770770
(read-from-minibuffer "Select figwheel-main build (e.g. :dev): ")))))
771771
(format form (cider-normalize-cljs-init-options options))))
772772

773+
(defcustom cider-custom-cljs-repl-init-form nil
774+
"The form used to start a custom ClojureScript REPL.
775+
When set it becomes the return value of the `cider-custom-cljs-repl-init-form'
776+
function, which normally prompts for the init form.
777+
778+
This defcustom is mostly intended for use with .dir-locals.el for
779+
cases where it doesn't make sense to register a new ClojureScript REPL type."
780+
:type 'string
781+
:safe (lambda (s) (or (null s) (stringp s)))
782+
:package-version '(cider . "0.23.0"))
783+
773784
(defun cider-custom-cljs-repl-init-form ()
774-
"Prompt for a form that would start a ClojureScript REPL.
785+
"The form used to start a custom ClojureScript REPL.
786+
Defaults to the value of `cider-custom-cljs-repl-init-form'.
787+
If it's nil the function will prompt for a form.
775788
The supplied string will be wrapped in a do form if needed."
776-
(let ((form (read-from-minibuffer "Please, provide a form to start a ClojureScript REPL: ")))
777-
;; TODO: We should probably make this more robust (e.g. by using a regexp or
778-
;; parsing the form).
779-
(if (string-prefix-p "(do" form)
780-
form
781-
(format "(do %s)" form))))
789+
(or
790+
cider-custom-cljs-repl-init-form
791+
(let ((form (read-from-minibuffer "Please, provide a form to start a ClojureScript REPL: ")))
792+
;; TODO: We should probably make this more robust (e.g. by using a regexp or
793+
;; parsing the form).
794+
(if (string-prefix-p "(do" form)
795+
form
796+
(format "(do %s)" form)))))
782797

783798
(defvar cider-cljs-repl-types
784799
'((nashorn "(do (require 'cljs.repl.nashorn) (cider.piggieback/cljs-repl (cljs.repl.nashorn/repl-env)))"

doc/modules/ROOT/pages/basics/clojurescript.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ You can also modify the known ClojureScript REPLs on a per-project basis using
113113
(cider-default-cljs-repl . super-cljs)))
114114
----
115115

116+
For one-off REPLs you can also use the custom REPL init form like this:
117+
118+
[source,lisp]
119+
----
120+
;; modify the list of known REPLs and set some default
121+
((nil
122+
(cider-custom-cljs-repl-init-form . "(do (foo) (bar))"
123+
(cider-default-cljs-repl . custom)))
124+
----
125+
116126
If you already have a Clojure REPL running and want to add a
117127
ClojureScript REPL, you can invoke
118128
`cider-jack-in-sibling-clojurescript` to add it.

0 commit comments

Comments
 (0)