Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cider-eval to kill-ring and pre-sexp comment. #1169

Closed
phillord opened this issue Jun 25, 2015 · 17 comments
Closed

cider-eval to kill-ring and pre-sexp comment. #1169

phillord opened this issue Jun 25, 2015 · 17 comments

Comments

@phillord
Copy link
Contributor

As a feature request, it would be lovely to have the ability to push the results of the last eval to the kill-ring.

I write quite a lot of tutorial material where I want to do something with the eval results of Clojure code, and currently I have to insert into buffer, then kill. Even better would be an "eval-last-sexp-and-insert-as-comment-before-the-sexp" (sorry, not a good name). So:

(+ 2 2)

Would become...

;; => 4

(+ 2 2)

I guess both of these could be layered onto cider-eval-last-sexp by extending the prefix argument support.

If you are interested, I can put a PR together.

@bbatsov
Copy link
Member

bbatsov commented Jun 26, 2015

Your suggestions sound reasonable. Put something together, so we can discuss some actual code.

@phillord
Copy link
Contributor Author

Will do!

@bbatsov
Copy link
Member

bbatsov commented Oct 17, 2015

@phillord Ping :-)

@phillord
Copy link
Contributor Author

Working on new command "M-x create-more-time" first...

Still think this is a good idea and will do it at some point. Not sure
when.

Bozhidar Batsov notifications@github.com writes:

@phillord Ping :-)


Reply to this email directly or view it on GitHub:
#1169 (comment)

@bkruczyk
Copy link
Contributor

bkruczyk commented Oct 19, 2016

@bbatsov There's already a cider-eval-defun-to-comment. Wouldn't it be apropriate to create custom variable like cider-eval-push-to-kill-ring instead of creating another eval function?

@bbatsov
Copy link
Member

bbatsov commented Oct 20, 2016

Yeah, probably this would be the best direction. I don't really want to add more prefix arguments to eval commands. But I think @phillord wanted to different things - a way to push results to the killring and a way to display results as comments.

@bkruczyk
Copy link
Contributor

a way to display results as comments.

Isn't that what cider-eval-defun-to-comment does?

@bbatsov
Copy link
Member

bbatsov commented Oct 20, 2016

Just for one type of evaluation (top-level expression evaluation). Which is probably enough. But with the results to kill-ring, you'd probably want for every eval op to push its result to the the kill-ring when this is enabled. On the other hand some people might want to push there only specific results...

@bkruczyk
Copy link
Contributor

I think eval to comment makes most sense for top-level expressions i.e. inserting comment "inside" sexp could be problematic/confusing.

For specific results I don't really know how to tackle it, but for every eval maybe it would be sufficent to put the kill-ring behaviour in somewhere in cider-interactive-eval.

@bbatsov
Copy link
Member

bbatsov commented Oct 20, 2016

Indeed.

@phillord
Copy link
Contributor Author

@bkruczyk Yes, that's is what cider-eval-defun-to-comment does -- I added that command:-)

My original issue was more generic, but what we have now fulfils my use case. I am happy to close, unless @bkruczyk needs the more generic solution.

@bkruczyk
Copy link
Contributor

Nope, feel free to close the issue.

@bbatsov
Copy link
Member

bbatsov commented Oct 20, 2016

@phillord so you don't want the ability to push eval results to the kill right anymore?

@phillord
Copy link
Contributor Author

Well, I wanted this as a way to get results as comments into the buffer. As that's been implemented instead, it seems the better solution. I'll close.

@jvillste
Copy link

jvillste commented May 27, 2020

Here is a function that would implement the evaluation to kill ring. I keep it in my init.el for now.

(defun juvi-eval-last-sexp-to-kill-ring ()
  (interactive)
  (cider-interactive-eval (cider-last-sexp)
                          (nrepl-make-response-handler (current-buffer)
                                                       (lambda (_buffer value)
                                                         (kill-new value))
                                                       (lambda (_buffer out)
                                                         (cider-emit-interactive-eval-output out))
                                                       (lambda (_buffer err)
                                                         (cider-emit-interactive-eval-err-output err))
                                                       '())
                          nil
                          (cider--nrepl-print-request-map fill-column)))

@olymk2
Copy link

olymk2 commented Oct 9, 2020

this would be a really nice feature, sat here evaluating html would be nice to get the result and format it in another buffer like html mode. perhaps even eval to new buffer for large results you want to format.

@matthew-piziak
Copy link

Thanks @jvillste! This is quite useful. I like putting an extra (cider-eval-last-sexp) as the last time of the defun so that I can see the result that gets copied to the kill ring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants