Last active
November 9, 2017 19:21
-
-
Save gonewest818/5f68a092994ba135d915bf14c807329f to your computer and use it in GitHub Desktop.
cider-pprint-eval-last-sexp-to-buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(setq lexical-binding t) | |
(defun cider-eval-pprint-to-multiline-comment-handler (buffer location arrow-prefix comment-prefix) | |
"Make a handler for evaluating and printing commented results in BUFFER. | |
LOCATION is the location at which to insert. | |
COMMENT-PREFIX is the comment prefix to use." | |
(cl-flet ((multiline-comment-handler (buffer value) | |
(with-current-buffer buffer | |
(save-excursion | |
(goto-char location) | |
(let ((lines (split-string value "[\n]+" t))) | |
;; only the first line gets arrow-prefix | |
(insert (concat arrow-prefix (pop lines) "\n")) | |
(dolist (elem lines) | |
(insert (concat comment-prefix elem "\n")))))))) | |
(nrepl-make-response-handler buffer | |
'() | |
#'multiline-comment-handler | |
#'multiline-comment-handler | |
'()))) | |
(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." | |
(interactive "P") | |
(let* ((bounds (cider-last-sexp 'bounds)) | |
(insertion-point (nth (if loc 0 1) bounds))) | |
(cider-interactive-eval nil | |
(cider-eval-pprint-to-multiline-comment-handler | |
(current-buffer) insertion-point ";; => " ";; ") | |
bounds | |
(cider--nrepl-pprint-request-plist (cider--pretty-print-width))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment