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

Created cider-eval-last-sexp-to-comment #2101

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,18 @@ If invoked with a PREFIX argument, print the result in the current buffer."
(goto-char (cadr (cider-sexp-at-point 'bounds)))
(cider-eval-last-sexp prefix)))

(defun cider-eval-last-sexp-to-comment (loc)
"Evaluate the expression preceding point and insert result as comment at LOC.

With a prefix arg, LOC, insert before the form, otherwise afterwards."
(interactive "P")
(let* ((bounds (cider-defun-at-point 'bounds))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to me you just copy pasted the code of the other function here. :-)

The repetition between the two functions should be factored out into some common helper.

(insertion-point (nth (if loc 0 1) bounds)))
(cider-interactive-eval nil
(cider-eval-print-with-comment-handler
(current-buffer) insertion-point ";; => ")
(cider-last-sexp 'bounds))))

(defun cider-eval-defun-to-comment (loc)
"Evaluate the \"top-level\" form and insert result as comment at LOC.

Expand Down
2 changes: 1 addition & 1 deletion cider-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ Configure `cider-cljs-*-repl' to change the ClojureScript REPL to use for your b
(define-key map (kbd "C-x C-e") #'cider-eval-last-sexp)
(define-key map (kbd "C-c C-e") #'cider-eval-last-sexp)
(define-key map (kbd "C-c C-v") 'cider-eval-commands-map)
(define-key map (kbd "C-c M-;") #'cider-eval-defun-to-comment)
(define-key map (kbd "C-c M-;") #'cider-eval-last-sexp-to-comment)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unbinding functions like this is never a good idea. Try to think of a new binding for this function. Also mention it in the command listings in menus and documents.

(define-key map (kbd "C-c M-e") #'cider-eval-last-sexp-to-repl)
(define-key map (kbd "C-c M-p") #'cider-insert-last-sexp-in-repl)
(define-key map (kbd "C-c C-p") #'cider-pprint-eval-last-sexp)
Expand Down