Skip to content

Commit 201811e

Browse files
yuhan0bbatsov
authored andcommitted
Save eval results into custom register
1 parent 7506cc4 commit 201811e

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

cider-eval.el

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ If t, save the file without confirmation."
167167
:group 'cider
168168
:package-version '(cider . "0.16.0"))
169169

170+
(defcustom cider-eval-register ?e
171+
"The text register assigned to the most recent evaluation result.
172+
When non-nil, the return value of all CIDER eval commands are
173+
automatically written into this register."
174+
:type '(choice character
175+
(const nil))
176+
:group 'cider
177+
:package-version '(cider . "1.4.0"))
178+
170179

171180
;;; Utilities
172181

@@ -651,7 +660,9 @@ The handler simply inserts the result value in BUFFER."
651660
(nrepl-make-response-handler (or buffer eval-buffer)
652661
(lambda (_buffer value)
653662
(with-current-buffer buffer
654-
(insert value)))
663+
(insert value))
664+
(when cider-eval-register
665+
(set-register cider-eval-register value)) )
655666
(lambda (_buffer out)
656667
(cider-repl-emit-interactive-stdout out))
657668
(lambda (_buffer err)
@@ -723,7 +734,9 @@ when `cider-auto-inspect-after-eval' is non-nil."
723734
(cider--make-fringe-overlays-for-region beg end)
724735
(setq fringed t))
725736
(cider--make-fringe-overlay end))
726-
(cider--display-interactive-eval-result value end))
737+
(cider--display-interactive-eval-result value end)
738+
(when cider-eval-register
739+
(set-register cider-eval-register value)))
727740
(lambda (_buffer out)
728741
(cider-emit-interactive-eval-output out))
729742
(lambda (_buffer err)
@@ -768,7 +781,9 @@ Optional argument DONE-HANDLER lambda will be run once load is complete."
768781
(insert
769782
(if (derived-mode-p 'cider-clojure-interaction-mode)
770783
(format "\n%s\n" value)
771-
value))))
784+
value)))
785+
(when cider-eval-register
786+
(set-register cider-eval-register value)))
772787
(lambda (_buffer out)
773788
(cider-emit-interactive-eval-output out))
774789
(lambda (_buffer err)
@@ -785,7 +800,9 @@ comment prefix to use."
785800
(save-excursion
786801
(goto-char (marker-position location))
787802
(insert (concat comment-prefix
788-
value "\n")))))
803+
value "\n"))))
804+
(when cider-eval-register
805+
(set-register cider-eval-register value)))
789806
(lambda (_buffer out)
790807
(cider-emit-interactive-eval-output out))
791808
(lambda (_buffer err)

0 commit comments

Comments
 (0)