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
Add eval-top-level-to-comment
command.
#1536
Conversation
(interactive) | ||
(let ((defun-at-point (cider-defun-at-point)) | ||
(point-at-defun (cider-defun-at-point-start-pos))) | ||
(goto-char point-at-defun) |
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 think we should wrap all this in a save-excursion
I don't like it when commands move point when they don't have to.
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.
Tried this. If you surround the whole thing in save-excursion then it prints
results-of-eval;; =>
rather than
;; => results of-eval
Why? Don't know. I am guessing that the call-back cider-eval-print-handler
happens asynchronously? save-excursion has already emptied?
This looks a little roundabout. Why does it need to goto-char and insert two separate times? |
@@ -1050,6 +1050,22 @@ If invoked with a PREFIX argument, print the result in the current buffer." | |||
(backward-kill-sexp) | |||
(cider-interactive-eval last-sexp (cider-eval-print-handler)))) | |||
|
|||
(defun cider-eval-top-level-to-comment () | |||
"Evaluate the \"top-level\" form at point and insert result as pre-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.
Why a pre-comment? Maybe there should be some option to choose either a pre or a post comment?
Also, is there a reason to insert above? When you see code samples the results comment is usually below the snippet. |
I agree that having the result above the form is non-standard. In many examples you also see a marker signifying evaluation like: (+ 1 1)
;;=> 2 I prefer this style, but I'm probably not going to use this feature a lot so I'm good either way. |
Why comments before? Because comments always come before the thing to which they refer. That's how I've always seen it anyway. |
Why the two In this case, we move the form forward first, then add the eval result (otherwise, we loose the end of the eval result. There are other ways, of course. |
Oh, yeah, wanted to ask. At the moment, this misbehaves when the eval errors. |
All changed. All the insertion logic is in the callback now. point is preserved, errors are handled, comments after or before on prefix arg and generally everything is cool and froody. |
@@ -664,7 +664,7 @@ can be used to display the evaluation result." | |||
(funcall nrepl-err-handler))))) | |||
|
|||
(defun cider-eval-print-handler (&optional buffer) | |||
"Make a handler for evaluating and printing result in BUFFER." | |||
"Make a handler for evaluating and printing result in BUFFER at LOCATION." |
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 changed this docstring, but I think you meant to add this to the function below.
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.
Oh dear. I keep forgetting to check the overall diff.
f2b5947
to
2c0858a
Compare
@@ -1050,6 +1067,21 @@ If invoked with a PREFIX argument, print the result in the current buffer." | |||
(backward-kill-sexp) | |||
(cider-interactive-eval last-sexp (cider-eval-print-handler)))) | |||
|
|||
(defun cider-eval-defun-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.
LOC should appear somewhere in the docstring.
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 is still not addressed.
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.
Will be this evening now...
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.
Complete now
You'll have to rebase on top of the current master. Please drop the |
2c0858a
to
2039c16
Compare
All done. Travis failure seems to be an existing problem with master. |
@@ -678,6 +678,23 @@ can be used to display the evaluation result." | |||
(cider-emit-interactive-eval-err-output err)) | |||
'())) | |||
|
|||
(defun cider-eval-print-with-comment-handler (buffer location 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.
comment -> comment-prefix
2039c16
to
24947fb
Compare
24947fb
to
c22f883
Compare
Add `cider-eval-defun-to-comment` command.
As discussed ages ago!