Skip to content

Commit

Permalink
[Fix #1976] Add an interactive command for connecting to a running Cl…
Browse files Browse the repository at this point in the history
…ojureScript

REPL

This worked in the past as well, but someone had to toggle the type of the REPL
to "cljs" using `cider-repl-type` which was not obvious to most people. I also
added an interactive command for toggling the REPL type - `cider-repl-set-type`.

This fixes a mess I had created before - I had copy-pasted some code I planned
to tweak from the related issue and I committed this code upstream by mistake.
  • Loading branch information
bbatsov committed Jan 15, 2018
1 parent 7cb5d39 commit b31b5e3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* [#2161](https://github.com/clojure-emacs/cider/issues/2161): Add new interactive command `cider-eval-defun-to-point` which is bound to `C-c C-v (C-)z`. It evaluates the current top-level form up to the point.
* [#2113](https://github.com/clojure-emacs/cider/issues/2113): Add new interactive commands `cider-eval-last-sexp-in-context` (bound to `C-c C-v (C-)c`) and `cider-eval-sexp-at-point-in-context` (bound to `C-c C-v (C-)b`).
* Add new interactive command `cider-repl-set-type`.
* [#1976](https://github.com/clojure-emacs/cider/issues/1976): Add new interactive command `cider-connect-clojurescript`.

### Bugs Fixed

Expand Down
6 changes: 4 additions & 2 deletions cider-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,12 @@ Configure `cider-cljs-*-repl' to change the ClojureScript REPL to use for your b
"Menu for Clojure mode.
This is displayed in `clojure-mode' buffers, if `cider-mode' is not active."
`("CIDER" :visible (not cider-mode)
["Start a REPL" cider-jack-in
["Start a Clojure REPL" cider-jack-in
:help "Starts an nREPL server (with Leiningen, Boot, or Gradle) and connects a REPL to it."]
["Connect to a REPL" cider-connect
["Connect to a Clojure REPL" cider-connect
:help "Connects to a REPL that's already running."]
["Connect to a ClojureScript REPL" cider-connect-clojurescript
:help "Connects to a ClojureScript REPL that's already running."]
["Start a Clojure REPL, and a ClojureScript REPL" cider-jack-in-clojurescript
:help "Starts an nREPL server, connects a Clojure REPL to it, and then a ClojureScript REPL.
Configure `cider-cljs-lein-repl', `cider-cljs-boot-repl' and `cider-cljs-gradle-repl' to change the ClojureScript REPL to use."]
Expand Down
10 changes: 10 additions & 0 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,15 @@ namespace to switch to."
(cider-repl-switch-ns-handler connection)))
:both))

(defun cider-repl-set-type (&optional type)
"Set REPL TYPE to \"clj\" or \"cljs\"."
(interactive)
(let ((type (or type (completing-read
(format "Set REPL type (currently `%s') to: "
cider-repl-type)
'("clj" "cljs")))))
(setq cider-repl-type type)))


;;; Location References

Expand Down Expand Up @@ -1511,6 +1520,7 @@ constructs."
["Refresh loaded code" cider-refresh]
"--"
["Set REPL ns" cider-repl-set-ns]
["Set REPL type" cider-repl-set-type]
["Toggle pretty printing" cider-repl-toggle-pretty-printing]
["Require REPL utils" cider-repl-require-repl-utils]
"--"
Expand Down
19 changes: 9 additions & 10 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -671,19 +671,18 @@ gets associated with it."
;; associate if we're in a project, prompt otherwise
((eq cider-prompt-for-project-on-connect 'when-needed) (cider-assoc-project-with-connection project-dir conn))
;; always prompt
(t (cider-assoc-project-with-connection nil conn))))))))

(defun cider-repl-set-type (&optional type)
"Set REPL TYPE to \"clj\" or \"cljs\"."
(interactive)
(let ((type (or type (completing-read "Set REPL type to: " '("clj" "cljs")))))
(setq cider-repl-type type)))
(t (cider-assoc-project-with-connection nil conn)))))
conn)))

(defun cider-connect-clojurescript ()
"Connect to a clojurescript repl."
"Connect to a ClojureScript REPL.
It just delegates pretty much everything to `cider-connect' and just sets
the appropriate REPL type in the end."
(interactive)
(cider-connect)
(cider-repl-set-type "cljs"))
(when-let* ((conn (call-interactively #'cider-connect)))
(with-current-buffer conn
(setq cider-repl-type "cljs"))))

(defun cider-current-host ()
"Retrieve the current host."
Expand Down

0 comments on commit b31b5e3

Please sign in to comment.