Fork me on GitHub
#cider
<
2020-02-24
>
EmmanuelOga02:02:41

Hi! I need to add a single additional middleware to the way cider-jack-in works. I'm reading this: https://docs.cider.mx/cider/basics/up_and_running.html#_auto_injecting_dependencies I already have a cider-clojure-cli-global-options customization on a .dir-locals.el file on my project that looks something like: -A:alias1:alias2:etc but I 'm not sure if there's a way to modify that option or some other to add something the the list of middleware cider jack in uses.

EmmanuelOga02:02:49

Specifically I'm trying to add nrepl-rebl to the middleware that is added when cider-jack-in is called

EmmanuelOga02:02:06

This seems promissing:

EmmanuelOga02:02:04

This is why long term logs rock:

EmmanuelOga02:02:02

copied here for convenience in case someone finds this log:

EmmanuelOga02:02:06

; .dir-locals.el
((clojure-mode
  (cider-clojure-cli-global-options . "-A:dev")
  (cider-jack-in-nrepl-middlewares . ("nrebl.middleware/wrap-nrebl"
                                      "cider.nrepl/cider-middleware"))))

EmmanuelOga02:02:40

as it turns out, if that list is defined, it replaces the standard list of whatever version of cider is being used

EmmanuelOga02:02:45

which is a bit inconvenient because I need to manually add the cider middleware and other stuff like the clj-refactor middleware, which previously just worked

EmmanuelOga02:02:22

this is what the list looks like before overriding it:

EmmanuelOga02:02:26

(("refactor-nrepl.middleware/wrap-refactor" :predicate cljr--inject-middleware-p) "cider.nrepl/cider-middleware")

EmmanuelOga02:02:50

unfortunately I don't know how to append to that list instead of replacing it

EmmanuelOga02:02:19

So I'm just gonna copy-paste it on my .dir-locals.el and add the rebl-wrapper ref for now

EmmanuelOga02:02:41

ohhhhh it worked

EmmanuelOga02:02:48

((nil
  (cider-jack-in-nrepl-middlewares . ("nrepl-rebl.core/wrap-rebl"
                                      ("refactor-nrepl.middleware/wrap-refactor"
                                       :predicate cljr--inject-middleware-p)
                                      "cider.nrepl/cider-middleware"))
  (cider-clojure-cli-global-options . "-A:cider:xml:rebl")
  (cider-default-cljs-repl . figwheel-main)
  (cider-figwheel-main-default-options . ":dev")))

EmmanuelOga02:02:53

my final setup

EmmanuelOga02:02:11

now I have both REBL and clj-refactor and the cider middleware all working together yaaaay 🙂

dpsutton05:02:34

one thing you could do is put all that in a function. (let ((.. ..)) (cider-jack-in-cljs))

EmmanuelOga05:02:05

interesting dpsutton. I have no idea how to do that though haha. I guess it will eventually come time for me to finally learn elisp 😛

EmmanuelOga05:02:12

I suspect there might be a way using add-hook-###-### since that's what clj-refactor does

bozhidar08:02:14

You might open a ticket about this, so we can discuss how we can improve this setup and the documentation surrounding it.

bozhidar08:02:42

Generally it’s better to use add-to-list than to just override the middleware config - e.g. https://github.com/clojure-emacs/sayid/blob/master/src/el/sayid.el#L151

bozhidar08:02:20

Of course, this was meant mostly for extensions to plug-in something extra. For end users it might also make sense to have an extra config that’s just gets appended to the “core” list.

EmmanuelOga00:02:17

thanks bozhidar! will collect my logs about this issue when I get home and put them on a cider issue.

zilti14:02:17

I also only stumbled upon Calva by accident when looking for tooling to recommend for newcomers. Though I have to say I find it a bit weird that it isn't implemented in ClojureScript.

pez14:02:37

Parts of it is. But yeah, it is a bit of a trauma.