-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
Implement cider-pprint-eval-last-sexp-to-comment #2111
Implement cider-pprint-eval-last-sexp-to-comment #2111
Conversation
AFAICT, some of those travis errors look like transient network issues on their end (e.g. "Opening TLS connection to ‘melpa.org’...failed"), while the other errors refer to a file I didn't change (cider-stacktrace.el). |
Or something to do with changes in Emacs 26. We have to investigate this. |
cider-interaction.el
Outdated
"The prefix to insert before the first line of pprint output." | ||
:type 'string | ||
:group 'cider | ||
:package-version '(cider . "0.15.2")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version should 0.16 everywhere. There won't be 0.15.2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I’ll fix that.
With respect to the TLS error in Travis... I think the difference is emacs versions <=25.2 fall back to Even in the failed Travis jobs, there's a point where evm successfully bootstraps itself using emacs-24.3-travis: https://travis-ci.org/clojure-emacs/cider/jobs/307715504#L485-L492 The build failure occurs later, as cask is installing dependencies for emacs-git-snapshot-travis: So I'm not sure why |
Thanks for looking into this. I guess the easiest think we can do is to switch to just Please mention your changes in the changelog and in the relevant parts of the manual. |
You should probably add the new command to some of the mode menus as well, otherwise no one will find it. |
Ok, will do. Want me to squash commits when all is said and done?
… On Nov 30, 2017, at 10:57 PM, Bozhidar Batsov ***@***.***> wrote:
You should probably add the new command to some of the mode menus as well, otherwise no one will find it.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@gonewest818 Yep, that'd be best. |
I made this feature invokable with a prefix argument on I updated the changelog and the docs to indicate this is the case. I didn't change README.md, as it seems more like a landing page with links off to those other docs I already changed. |
192e918
to
3835eca
Compare
cider-interaction.el
Outdated
bounds))) | ||
|
||
(defun cider-pprint-eval-last-sexp-to-comment (loc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess you should make loc
optional. And maybe name it insert-result-before
or something more meaningful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That matches the implementation of cider-eval-defun-to-comment
so I'l fix both.
cider-interaction.el
Outdated
(defun cider-pprint-eval-last-sexp-to-comment (loc) | ||
"Evaluate the last sexp and insert result as comment at LOC. | ||
|
||
With a prefix arg, LOC, insert before the form, otherwise afterwards." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you should mention here the configuration options related to this command.
cider-interaction.el
Outdated
"Evaluate the sexp preceding point and pprint its value in a popup buffer." | ||
(interactive) | ||
(cider--pprint-eval-form (cider-last-sexp 'bounds))) | ||
(defun cider-pprint-eval-last-sexp (&optional prefix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally I avoid the name prefix
and go for something like print-in-current-buffer
(or something).
1decb7e
to
67493a5
Compare
ok @bbatsov, code review comments are addressed and I squashed the commits again. |
cider-interaction.el
Outdated
(current-buffer) insertion-point ";; => ") | ||
(current-buffer) | ||
insertion-point | ||
cider-pprint-comment-prefix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a customizable variable called cider-pprint-comment-prefix
, but it's also used in cider-eval-defun-to-comment
.
Seems that the variables can be used in comment functions in general, not just the pprint
variants, so we can drop the pprint
from the names:
cider-comment-prefix
cider-comment-continued-prefix
cider-comment-postfix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that's a fair point. I'll do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. see commit.
cider-interaction.el
Outdated
bounds))) | ||
|
||
(defun cider-pprint-eval-last-sexp-to-comment (&optional insert-before) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, CIDER has only has cider-eval-defun-to-comment
. Seems asymmetric to add cider-pprint-eval-last-sexp-to-comment
instead of cider-pprint-eval-defun-to-comment
. Could we implement the latter instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can, but symmetry is arguably a larger issue than this, considering:
- cider-eval-sexp-at-point
- cider-eval-last-sexp
- cider-eval-print-last-sexp
- cider-eval-last-sexp-to-repl
- cider-eval-last-sexp-to-comment (Created cider-eval-last-sexp-to-comment #2101)
- cider-eval-defun-at-point
- cider-eval-defun-to-comment
- cider-pprint-eval-last-sexp
- cider-pprint-eval-last-sexp-to-repl
- cider-pprint-eval-last-sexp-to-comment (Implement cider-pprint-eval-last-sexp-to-comment #2111)
- cider-pprint-eval-defun-at-point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I didn't see #2101. But we'd still have no cider-pprint-eval-defun-to-comment
🤷♂️. Maybe add it in the next PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me take a look. I doubt the defun case is really all that different from what I have.
But, for the record there's a lot of overlapping functionality in this set. Everything amounts to "eval {some selected form} and send result to {some destination} {with/without pprint}". It seems clear to me this could be more aggressively refactored such that you don't actually have to write distinct functions for each of the combinatorial possibilities. I'm not proposing to do that now, mind you, that's too much scope for what was supposed to be an incremental feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. see the latest commit.
I found a bug in this implementation but I can't figure out how to resolve it. If I invoke these new functions by name, e.g. Whereas, if I invoke the same function through its keybinding |
cider-interaction.el
Outdated
If invoked with OUTPUT-TO-CURRENT-BUFFER, insert as comment in the current buffer." | ||
(interactive "P") | ||
(if output-to-current-buffer | ||
(cider-pprint-eval-last-sexp-to-comment nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to pass nil
here - now it's optional, which means the param is going to be nil by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right. thanks!
See the debugging section of the manual. Using the Elisp debugger is the best way to see what's going wrong. |
I couldn't reproduce the problem in the debugger, but I managed to find it anyway. In emacs 25.1 and newer (simple.el, in the function
https://github.com/emacs-mirror/emacs/blob/emacs-25/lisp/simple.el#L1722-L1730 A comment in the code mentions a caveat that the search for a shorter-but-unique string "can be slow". And so it seems, at least in this particular case. If the function has a keybinding, emacs suggests the available keybinding rather than trying to find a shorter string. And that is fast. If this bug is really objectionable to a user, one workaround would be |
Ah, yeah. Now I remembered about that feature. However, I don't recall ever using it in practice. I guess I don't use |
CHANGELOG.md
Outdated
@@ -5,6 +5,7 @@ | |||
### New Features | |||
|
|||
* [#2082](https://github.com/clojure-emacs/cider/pull/2082), [cider-nrepl#440](https://github.com/clojure-emacs/cider-nrepl/pull/440): Add specialized stacktraces for clojure.spec assertions. | |||
* [#2111](https://github.com/clojure-emacs/cider/pull/2111): Add `cider-pprint-eval-last-sexp-to-comment` and `cider-pprint-eval-defun-to-comment` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence should end with a .
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Seems we're finally ready to merge then. Address my tiny remark and update your commit message in light of the final state of the PR. |
4d98630
to
0bce19a
Compare
…-comment These functions have similar functionality to the other pprint interactions; however now we can also insert the result of evaluation directly in the current buffer. The comment prefix(es) used in output is now user-configurable, and for consistency, we also use same prefix in cider-eval-defun-to-comment.
0bce19a
to
89af027
Compare
Done. Thanks for your helpful (and patient) feedback. |
🎉 You're welcome! Looking forward to more contributions from you down the road! 😉 |
This function has similar functionality to the other pprint interactions;
however this variant inserts the result of the evaluation directly in the
current buffer.
The comment prefix used in the output is user-configurable, and for consistency
we also use same prefix in cider-eval-defun-to-comment.
By default the output will be commented like so
but by customizing the
cider-pprint-comment-*
variables you can also get output like thisor even
Before submitting the PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):
make test
)M-x checkdoc
warningsThanks!
If you're just starting out to hack on CIDER you might find this section of its
manual extremely useful.