Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Commit

Permalink
Merge pull request #128 from blais/master
Browse files Browse the repository at this point in the history
Added ClojureScript support.
  • Loading branch information
technomancy committed May 25, 2012
2 parents 08972e8 + 41f39e5 commit 57844d3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/swank/commands/basic.clj
Expand Up @@ -72,7 +72,14 @@

(defslimefn interactive-eval [string]
(with-emacs-package
(pr-str (first (eval-region string)))))
(pr-str
(let [value (first (eval-region string))]
;; If the result is a seq, consume it here instead of getting evaluated
;; from pr-str to allow side-effects to go to the repl.
(if (instance? clojure.lang.LazySeq value)
(doall value)
value)
))))

(defslimefn listener-eval [form]
(with-emacs-package
Expand Down
47 changes: 47 additions & 0 deletions src/swank/commands/cljs.clj
@@ -0,0 +1,47 @@
(ns ^{:doc "Support for sending evaluation of forms into a ClojureScript repl."}
swank.commands.cljs
(:use [swank.core :only (with-emacs-package)]
[swank.commands :onlny (defslimefn)])
(:require [cljs.repl :as repl]
[cljs.compiler :as comp])
)

(def cljs-targets "A mapping of registered repl environments which can be used as targets." (atom {}))

(defn register-repl
"Register a new REPL environment for interactive-eval-with-target to dispatch to."
[key env]
(swap! cljs-targets assoc key env))

(defn eval-in-cljs
"Evaluate the given string in the provided ClojureScript repl environment."
[env form-string]
(binding [comp/*cljs-ns* comp/*cljs-ns*]
(let [form (read-string form-string),
;; Note: the following is lifted from cljs.repl.browser; FIXME: we
;; should add support there to do this without a repl thread.
context {:context :statement
:locals {}
:ns (@comp/namespaces comp/*cljs-ns*)}]

(repl/evaluate-form env context "<swank-cljs-repl>" form)
)))

(defslimefn ^{:doc "Evaluate a Clojure form in a ClojureScript environment."}
interactive-eval-with-target [target form-string]
(let [env (get @cljs-targets target)]
(if env
(eval-in-cljs env form-string)
(throw (Exception.
(format "Emacs eval abort; eval target '%s' not found" target)))
)))


;; Notes:
;;
;; You will need an Emacs customization that overrides
;; slime-interactive-eval tocall (swank:interactive-eval-with-target) instead of
;; (swank:interactive-eval), such as is provided in clojure-mode.el.
;;
;; Also, before you can eval to a target, you will need your VM to have a repl
;; instance registered via 'register-repl' (e.g. browser repl).

0 comments on commit 57844d3

Please sign in to comment.