Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware on cljs-repl launch #71

Closed
divs1210 opened this issue Feb 22, 2016 · 1 comment
Closed

Middleware on cljs-repl launch #71

divs1210 opened this issue Feb 22, 2016 · 1 comment

Comments

@divs1210
Copy link

I basically started out trying to find a fix to this issue.

Could we modify cljs-repl in the following manner to allow loading middleware once the REPL has launched and entered the cljs.user namespace?

(defmacro functionize [macro]
  `(fn [& args#] (eval (cons '~macro args#))))

(defmacro apply-macro [macro args]
   `(apply (functionize ~macro) ~args))

(defn cljs-repl
  "Starts a ClojureScript REPL on top of an nREPL session.  Accepts
   all options usually accepted by e.g. cljs.repl/repl."
  [repl-env & {:as options}]
  ; TODO I think we need a var to set! the compiler environment from the REPL
  ; environment after each eval
  (try
    (let [repl-env (delegating-repl-env repl-env nil)
          on-start (apply list   ;; <= HERE!
                          '(ns cljs.user
                             (:require [cljs.repl :refer-macros [source doc find-doc
                                                                 apropos dir pst]]))
                          (:on-start-middleware options))] ;; <= HERE!
      (set! ana/*cljs-ns* 'cljs.user)
      ; this will implicitly set! *cljs-compiler-env*
      (run-cljs-repl (assoc ieval/*msg* ::first-cljs-repl true)
        (apply-macro nrepl/code on-start)
        repl-env nil options)
      ; (clojure.pprint/pprint (:options @*cljs-compiler-env*))
      (set! *cljs-repl-env* repl-env)
      (set! *cljs-repl-options* options)
      ; interruptible-eval is in charge of emitting the final :ns response in this context
      (set! *original-clj-ns* *ns*)
      (set! *ns* (find-ns ana/*cljs-ns*))
      (println "To quit, type:" :cljs/quit))
    (catch Exception e
      (set! *cljs-repl-env* nil)
      (throw e))))

Then we could pass middleware like this:

(cljs-repl env {:on-start-middleware '((defn debug-reader [form]
                                         (comment Handler code))
                                       (cljs.reader/register-tag-parser! 'dbg debug-reader)
                                       (println "middleware launched"))})

I don't even know if I'm talking sense over here.

@cemerick
Copy link
Collaborator

cemerick commented Jun 2, 2017

Yeah, this seems sorta confused. First, the functionalize thing is a little eye-popping; but beyond that, you're talking about middleware, which is a Clojure nREPL thing, completely related to ClojureScript.

@cemerick cemerick closed this as completed Jun 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants