Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cider-eval.el
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,22 @@ Optional argument DONE-HANDLER lambda will be run once load is complete."
(cider-emit-interactive-eval-err-output err))
'()))

(defun cider-eval-kill-ring-handler ()
"Make a handler for evaluating and storing the eval result in the kill ring."
(nrepl-make-response-handler (current-buffer)
(lambda (_buffer value)
(with-temp-buffer
(insert
(if (derived-mode-p 'cider-clojure-interaction-mode)
(format "\n%s\n" value)
value))
(copy-region-as-kill (point-min) (point-max))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look correct to me as you'll be adding to the clipboard each chunk of the response (provided it's big enough to the split into several response messages). Normally you'd want to collect all the chunks until you get "done" and only then copy something to the clipboard.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also - it seems to me it would still be a goo idea to echo somewhere the result, so you'd know what ended up in the kill-ring without having to check it.

(lambda (_buffer out)
(cider-emit-interactive-eval-output out))
(lambda (_buffer err)
(cider-emit-interactive-eval-err-output err))
'()))

(defun cider-eval-print-with-comment-handler (buffer location comment-prefix)
"Make a handler for evaluating and printing commented results in BUFFER.
LOCATION is the location marker at which to insert. COMMENT-PREFIX is the
Expand Down Expand Up @@ -933,6 +949,17 @@ buffer."
(cider-last-sexp 'bounds)
(cider--nrepl-pr-request-map)))

(defun cider-eval-last-sexp-to-kill-ring (&optional pretty)
"Evaluate the expression preceding point.
Store the evaluation result in the kill ring.
Pretty print the result if PRETTY is non-nil."
(interactive "P")
(cider-interactive-eval nil
(cider-eval-kill-ring-handler)
(cider-last-sexp 'bounds)
;; this says that it does NOT require pretty printing... add an option?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure what this is supposed to mean.

(when pretty (cider--nrepl-pr-request-map))))

(defun cider-eval-last-sexp-and-replace ()
"Evaluate the expression preceding point and replace it with its result."
(interactive)
Expand Down