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

Eval in buffer and pretty-print result in REPL as output #2617

Closed
stathissideris opened this issue Mar 29, 2019 · 8 comments
Closed

Eval in buffer and pretty-print result in REPL as output #2617

stathissideris opened this issue Mar 29, 2019 · 8 comments
Labels
feature request good first issue A simple tasks suitable for first-time contributors

Comments

@stathissideris
Copy link

stathissideris commented Mar 29, 2019

Is your feature request related to a problem? Please describe.

The workflow I’d like to try is typing long multi-line expressions in a .clj file and eval+pretty-print their results in the REPL where the results accumulate.

Describe the solution you'd like

I would like a function that is similar to cider-pprint-eval-last-sexp-to-repl but instead of inserting the result into the REPL as input, I would like it to be inserted as pretty-printed output instead. If the eval'ed expression is also added as if it was typed in the prompt of the REPL I think it would be even more usable (because then you'd see alternating input and output and it would be easier to follow what was executed and in what order) but I’d be happy with just the outputs.

Describe alternatives you've considered

I saw that something similar would be possible with getting the results in a popup buffer, but I prefer to see a “log” of results which accumulate.

Additional context

This mockup shows what the result of running this new command might look like. My cursor is on the left in dev.clj, and I've just ran the new command, which resulted in my s-exp being added as input in the REPL prompt and the result of the expression being pretty-printed just below.

Screenshot 2019-03-29 at 15 20 06

@paulojean
Copy link
Contributor

I was planning to do this, but I realised that cider-insert-last-sexp-in-repl already accepts an argument that will evaluate the sexp after sending it to the repl (resulting in something similar to what is shown in the screenshot).

@stale
Copy link

stale bot commented May 8, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@stale stale bot added the stale label May 8, 2019
@bbatsov bbatsov removed the good first issue A simple tasks suitable for first-time contributors label May 8, 2019
@stale stale bot removed the stale label May 8, 2019
@bbatsov bbatsov added good first issue A simple tasks suitable for first-time contributors and removed good first issue A simple tasks suitable for first-time contributors low hanging fruit labels May 8, 2019
suvratapte pushed a commit to suvratapte/cider that referenced this issue Feb 19, 2020
This is a solution for issue-2617 on cider github.
clojure-emacs#2617
@suvratapte
Copy link
Contributor

Hi @bbatsov and @stathissideris ,

As @paulojean has mentioned, C-u cider-insert-last-sexp-in-repl already does what is requested in this issue.

Do we still want to have a separate function for doing this?
If yes, please take a look at this: suvratapte@c177120#diff-3f8317548fccd07e43ee8e69be1b3171

Should I create a pull request with this?

@bbatsov
Copy link
Member

bbatsov commented Feb 19, 2020

I've added a small remark to your commit. In general it seems we need to have more of the special function behaviors added to menu bars and documented properly at docs.cider.mx.

@suvratapte
Copy link
Contributor

Okay, I will do that. Thanks! :)

suvratapte pushed a commit to suvratapte/cider that referenced this issue Feb 27, 2020
suvratapte pushed a commit to suvratapte/cider that referenced this issue Feb 27, 2020
- Add an entry in CHANGELOG.md.

This is a solution for issue-2617 on cider github.
clojure-emacs#2617
@stathissideris
Copy link
Author

stathissideris commented Feb 27, 2020

Hello again, cider-insert-last-sexp-in-repl does indeed do what I was asking about, but it leaves the REPL cursor in its original position. That means that after a few evaluations the screen gets completely filled and any new expressions and results move beyond the bottom of the frame. Is there any way to add advice to some function in order to get the buffer to scroll as the results of cider-insert-last-sexp-in-repl get added to it? I tried follow-mode but it didn't seem to do the trick.

@holtzermann17
Copy link

Here's something that works for my current setup, you can modify it to suit your need; I can't say it's pretty!

(defun cider-recenter (&rest args)
  (interactive)
  (other-frame 1)
  (goto-char (point-max))
  (recenter -2)
  (other-frame -1))

(define-key cider-mode-map (kbd "s-e")
  #'(lambda () (interactive)
     (advice-add 'make-progress-reporter :override (lambda (&rest args)))
     (save-window-excursion (cider-insert-last-sexp-in-repl 1))
     (cider-recenter)
     (advice-remove 'make-progress-reporter (lambda (&rest args)))))

Screenshot from 2021-06-01 13-49-59

@Quezion
Copy link

Quezion commented Feb 11, 2022

For anyone reading through -- the above commit with cider-insert-and-eval-last-sexp-in-repl was never merged. To get automatic output to REPL, you still need to make this customization in your own init.el.

Here's the user level code that worked for me to override the default cider-eval-last-sexp C-x C-e

(defun cider-insert-and-eval-last-sexp-in-repl (&rest args)
  "Insert the expression preceding point in the REPL buffer and eval."
  (interactive)
  (cider-insert-last-sexp-in-repl t))

(define-key cider-mode-map (kbd "C-x C-e") #'cider-insert-and-eval-last-sexp-in-repl)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request good first issue A simple tasks suitable for first-time contributors
Projects
None yet
Development

No branches or pull requests

6 participants