hello, there's a way to redirect output of cider-eval-print-last-sexp
to kill-new
?
@d.ian.b Currently no.
(cider-interactive-eval "(java.util.UUID/randomUUID)"
(nrepl-make-response-handler nil
(lambda (_buffer value)
(kill-new value)
(message "copied %s" value))
(lambda (_buffer out)
(kill-new out)
(message "copied %s" out))
(lambda (_ err)
(message "error evaluating: %s" err))
'()))
that copies both out and returned values. not sure if that's what you want. but read the docstring for nrepl-make-response-handler
. or you could check out the source of cider-interactive-eval
and pass a single handler in there that does what you want
I've stopped on nrepl-make-response-handler
trying to understand
first steps on emacs-lisp 😅
thanks @dpsutton
(cider-interactive-eval "(java.util.UUID/randomUUID)"
(lambda (response)
(nrepl-dbind-response response (value)
(when value
(kill-new (format "%s" value))
(message "copied %s" value)))))
Something like this will get the job done, but without the pprint that @d.ian.b asked for, so you might consider using its handler instead.
bit easier i suppose.
what is nrepl-dbind-response
?
wow, defmacro on elisp rs
I have to study more, thanks @dpsutton
your emacs should just go to definition if you hit m-.
you can also use m-x apropos
to read the docstring. but it should be a bit understandable: given a response from nrepl, bind the binding value
to some notion of value in the repsonse. its essentially a dictionary that's defined somewhere in CIDER
yeah, I've put the entire dictionary on kill-new
but it was not a stringp
newbie question, how can I see the type of some output on elisp? there is a (type output)
?
that would just be map destructuring in clojure. but emacs lisp doesn't have that functionality baked in. there are some macros that provide it but they are not super standard and have a bit of weird syntax
It has some destructuring support today ((e.g. pcase-let
), but it didn't have it 7 years ago. 😄
if you step through the function with the debugger it should be pretty visible. define the form above in a function and then instrument it and then call it
alternatively, check out nrepl-dict.el
and its just a simple hashmap i believe
if you check out nrepl-make-response-handler
you can see what it is using nrepl-dbind-response
to capture
(nrepl-dbind-response response (content-type content-transfer-encoding body
value ns out err status id)