Fork me on GitHub
#cider
<
2020-08-16
>
Ian Fernandez02:08:36

hello, there's a way to redirect output of cider-eval-print-last-sexp to kill-new ?

dpsutton17:08:35

(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 3
dpsutton17:08:57

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 3
Ian Fernandez17:08:13

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

Ian Fernandez17:08:38

first steps on emacs-lisp 😅

dpsutton17:08:47

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

bozhidar07:08:04

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.

dpsutton17:08:15

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

dpsutton18:08:48

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

dpsutton18:08:34

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

🤯 3
bozhidar07:08:02

It has some destructuring support today ((e.g. pcase-let), but it didn't have it 7 years ago. 😄

dpsutton18:08:00

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

✔️ 3
dpsutton18:08:32

alternatively, check out nrepl-dict.el and its just a simple hashmap i believe

dpsutton18:08:24

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 3