Fork me on GitHub
#emacs
<
2021-11-16
>
bozhidar17:11:44

Not really a Clojure article, but some of you here might find it interesting https://batsov.com/articles/2021/11/16/why-emacs-redux/

🆒 3
emacs 14
👑 1
Young-il Choo20:11:37

Nice retrospective! My two cents: Emacs is the ultimate user interface to your computer, because every interaction with the computer should have all the editing capabilities of a powerful editor.

👍 1
ericdallo20:11:37

Any way to eval something with cider, and copy the result to clipboard?

ericdallo20:11:18

Since cider-eval-last-sexpr is async, not sure how to get the result to then create some custom elisp code

vemv20:11:57

while there's an elisp approach, you could also wrap the evaled code with clojure code that performed the clipboarding 'server-side' https://github.com/exupero/clipboard has worked just fine for me

ericdallo20:11:01

oh, Interesting project

ericdallo20:11:46

yeah, it should work, although I'd like a more elisp way, even so thank you for the suggestion :)

vemv20:11:55

simpleclip also worked for me for elisp stuff, for a long time. can't offer help myself with cider handlers unfortunately (I use an odd stack). digging into their source shouldn't be too hard

👀 1
ericdallo20:11:08

Do you know how can I get the cider eval output sync via elisp?

ericdallo20:11:19

or pass some callback

vemv20:11:50

sure there's cider-nrepl-sync-request:eval , you'll have to study a bit how to call it. it's not too hard iirc

ericdallo20:11:17

I'll give it a try

ericdallo20:11:51

I just found a easier way that IMO could go to cider code :)

(defun cider-eval-clipboard-handler ()
  (nrepl-make-response-handler
   (current-buffer)
   (lambda (buffer value)
     (with-current-buffer buffer
       (with-temp-buffer
         (insert value)
         (clipboard-kill-region (point-min) (point-max)))))
   (lambda (_buffer out)
     (cider-emit-interactive-eval-output out))
   (lambda (_buffer err)
     (cider-emit-interactive-eval-err-output err))
   '()))

(defun cider-eval-last-sexpr-and-copy-to-clipboard ()
  (interactive)
  (cider-interactive-eval nil
                         (cider-eval-clipboard-handler)
                         (cider-last-sexp 'bounds)
                         (cider--nrepl-pr-request-map)))

ericdallo20:11:14

it needs some improvements, like copy to clipboard and print as well, but it works

🙂 1
vemv22:11:27

nice! You might want to favor a temp buffer over the current one? IDK

bozhidar08:11:40

Just keep in mind that the this gets called once for each chunk of the response, so for a bigger result you might end up with only part of the response in the clipboard.

bozhidar08:11:48

Probably not a big deal in the most cases, but it might surprise you in certain situations.

bozhidar08:11:17

Perhaps you can gather the result in a temp buffer and copy it to the clipboard on "done"?

ericdallo12:11:06

Yes, that sounds better indeed