Custom middleware broke last update
The lateset update to 0.56.0 broke some custom middleware I have been using (shown below)
(:require
[cider.nrepl.middleware]
[nrepl.middleware]
[nrepl.server]
[refactor-nrepl.middleware]
[taoensso.telemere :as t])
(defn wrap-print-limit
[handler]
(fn [{:as msg
:nrepl.middleware.print/keys [options]
:keys [op session]}]
(when (and (#{"eval"} op)
session)
(if (instance? clojure.lang.IAtom session)
(swap! session
(fn [state]
(-> state
(assoc #'clojure.core/*print-length*
(or (get options :length)
(get options :max-length)
52))
(assoc #'clojure.core/*print-level*
(or (get options :level)
(get options :max-depth)
10)))))
(t/error! {:data session
:msg "session is not an atom"})))
(handler msg)))
(nrepl.middleware/set-descriptor! #'wrap-print-limit
{:description "overwrites *print-length* and *print-level* in :session"
:expects #{"eval"}
:requires #{"session"}})
(defn nrepl-handler
[]
(apply nrepl.server/default-handler
(into cider.nrepl.middleware/cider-middleware
[#'refactor-nrepl.middleware/wrap-refactor
#'wrap-print-limit])))
Using Zprint, I have been using this setup for a while, it broke in the last update (55.7 to 56.0 I think) (the error condition is being hit, and session is not an atom)
I use this setup so that I can dynamically set print options in emacs and have it immedately work in the repl, also I have some custom eval code that I bind that uses print-length and print-level so I want that updated along with the zprint variables.
Is there something fundamentally I am doing wrong, or did something change in regards to :expects and :requires?
Everything is absolute latest (emacs git-master + doom, java is 24.0.1, OS arch-linux current)
Thanks, Chris Rosengren
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed soon if no further activity occurs. Thank you for your contribution and understanding!
How are you using Zprint exactly? I'm guessing that's something to do with us removing it from the bundled dependencies in cider-nrepl, but I'll have to take a closer look to be sure. //cc @alexander-yakushev
@archaic The reason it doesn't work now is because now the session middleware establishes all dynamic bindings early. You modifying the session object afterwards has no effect.
Instead, you can directly set! the variables in your middleware:
(defn wrap-print-limit
[handler]
(fn [{:as msg
:nrepl.middleware.print/keys [options]
:keys [op]}]
(when (#{"eval"} op)
(set! *print-length* (or (get options :length)
(get options :max-length)
52))
(set! *print-level* (or (get options :level)
(get options :max-depth)
10)))
(handler msg)))
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed soon if no further activity occurs. Thank you for your contribution and understanding!