Fork me on GitHub
Ian Fernandez02:08:36

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))

emacs 1

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

emacs 1
Ian Fernandez17:08:13

I've stopped on nrepl-make-response-handler trying to understand

Ian Fernandez17:08:38

first steps on emacs-lisp 😅

Ian Fernandez17:08:45

thanks @dpsutton

cider 1

(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.

Ian Fernandez18:08:30

what is nrepl-dbind-response ?

Ian Fernandez18:08:18

wow, defmacro on elisp rs

Ian Fernandez18:08:34

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

Ian Fernandez18:08:16

yeah, I've put the entire dictionary on kill-new but it was not a stringp

Ian Fernandez18:08:32

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

🤯 1

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

✔️ 1

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)

emacs 1