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-prettify-sexp #535

Closed
gtrak opened this issue Apr 24, 2014 · 5 comments
Closed

cider-prettify-sexp #535

gtrak opened this issue Apr 24, 2014 · 5 comments

Comments

@gtrak
Copy link
Contributor

gtrak commented Apr 24, 2014

<devn> anyone know if there's a way to reformat something like '({:a 1 ...} {:b 2 ...} ...} like how clojure.pprint would print it?
<devn> for emacs?
<gtrak> devn: might be a good idea for a cider middleware
<gtrak> I end up reformatting edn manually a lot.. would be nice to select it and M-x cider-prettify-sexp or something
<arrdem> I'd throw money at a cider pprint middleware...
@arrdem
Copy link
Contributor

arrdem commented Apr 24, 2014

👍

@bbatsov
Copy link
Member

bbatsov commented Apr 25, 2014

Sounds like a good idea.

@dgtized
Copy link
Contributor

dgtized commented Jun 24, 2014

cider-pprint-eval-last-sexp, and cider-pprint-eval-defun-at-point appear to partially do this. In a cider minor mode enabled buffer these are bound to C-c C-p and C-c C-f respectively. Would it make sense to bind C-c C-f to cider-pprint-eval-defun-at-point in the repl? C-c C-p is not available as it is used to move to previous prompt.

Unfortunately both of these functions are a little odd to use, since it's always evaluating the form. If the form can't evaluate (as is the case in unquoted lists in output), it throws an error. For the case above it is quoted, but it seems like a generic method for pretty print replacing without evaluating would be really useful for the edn case. Then again, I'm not sure how to deal with #inst and friends.

dgtized added a commit to dgtized/cider that referenced this issue Jun 24, 2014
Per discussion at clojure-emacs#535, I tried using `cider-pprint-eval-defun-at-point` bound
to `C-c C-f` as it is in the interactive minor mode. Unfortunately
defun-at-point is not as well defined at the repl for some reason, I noticed
similar while experimenting with `cider-eval-defun-at-point` at the repl. So I
tried it with `cider-pprint-eval-last-sexp`, as that seemed more useful. I
guess the mnemonic would be see form?

This at least improves the case where the repl returns a very large vector, map
or quoted list and it needs to be inspected visually. It doesn't reformat it
in-place but it is reformatted in the popup buffer. I also think this plays well
with the exiting pprint toggle in the repl as a shortcut.
@bbatsov
Copy link
Member

bbatsov commented Jun 24, 2014

I'm pretty sure the point of the issue is to reformat structures in the source code, instead of simply pretty-printing them somewhere.

@dgtized
Copy link
Contributor

dgtized commented Jun 24, 2014

Yea, I gathered that. So my though on that is that currently cider-pprint-eval-* do not have a prefix argument, so one approach would be to override that ala cider-eval-last-sexp, so it prints after on one prefix argument. I'm wondering if the 'replace at point' functionality for both could be a second prefix argument? That or maybe prefix argument to cider-eval-last-sexp-and-replace?

The reason I talked about the problems with evaluating the form is that is part of the problem with this approach. For a reformat case, lists should probably be quoted automatically and not evaluated. I'm also not quite clear how to grab the stdout of pprint instead of the eval result.

dgtized added a commit to dgtized/cider that referenced this issue Jul 28, 2014
Per discussion at clojure-emacs#535, I tried using `cider-pprint-eval-defun-at-point` bound
to `C-c C-f` as it is in the interactive minor mode. Unfortunately
defun-at-point is not as well defined at the repl for some reason, I noticed
similar while experimenting with `cider-eval-defun-at-point` at the repl. So I
tried it with `cider-pprint-eval-last-sexp`, as that seemed more useful. I
guess the mnemonic would be see form?

This at least improves the case where the repl returns a very large vector, map
or quoted list and it needs to be inspected visually. It doesn't reformat it
in-place but it is reformatted in the popup buffer. I also think this plays well
with the exiting pprint toggle in the repl as a shortcut.
@bbatsov bbatsov closed this as completed Feb 17, 2015
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

4 participants