Skip to content

Commit

Permalink
Ensure backwards compatibility for all users
Browse files Browse the repository at this point in the history
We check whether eval-and-grab-output caller presumes older interface
to it and return a legacy list of two elements instead of alist in
those cases.

It is certainly appropriate to drop this check when Emacs 27 becomes
history. It is very likely appropriate to drop when use of Org 9.4
becomes discouraged by Org developers.
  • Loading branch information
akater committed Nov 25, 2020
1 parent 78304a3 commit 859ff65
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions swank.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,8 @@ Errors are trapped and invoke our debugger."
(format-values-for-echo-area values)))))

(defslimefun eval-and-grab-output
(string &optional (targets-to-capture '(*standard-output* values)))
(string &optional (targets-to-capture '(*standard-output* values)
targets-provided-p))
"Evaluate contents of STRING, return alist of results including various output streams. Possible keys in the returned alist should be listed in the value of `slime-output-targets' variable in `slime.el'."
(with-buffer-syntax ()
(with-retry-restart (:msg "Retry SLIME evaluation request.")
Expand All @@ -1785,16 +1786,27 @@ Errors are trapped and invoke our debugger."
(*standard-output*
(maybe-make-string-output-stream *standard-output*))
(values (multiple-value-list (eval (from-string string)))))
;; It is not clear what would be the most natural order here.
;; We picked the reversed binding order.
(list (cons 'values
(maybe-value-string (format nil "~{~S~^~%~}" values)))
(cons '*standard-output*
(maybe-output-stream-string *standard-output*))
(cons '*error-output*
(maybe-output-stream-string *error-output*))
(cons '*trace-output*
(maybe-output-stream-string *trace-output*))))))))
(if targets-provided-p
;; It is not clear what would be the most natural order here.
;; We picked the reversed binding order.
(list
(cons 'values
(maybe-value-string (format nil "~{~S~^~%~}" values)))
(cons '*standard-output*
(maybe-output-stream-string *standard-output*))
(cons '*error-output*
(maybe-output-stream-string *error-output*))
(cons '*trace-output*
(maybe-output-stream-string *trace-output*)))
;; targets are not provided by callers
;; who presume older (pre-2.26) interface
;; to eval-and-grab-output
;; This check (and targets-provided-p argument itself)
;; - can certainly be dropped when Emacs 27 becomes unsupported
;; - can very likely be dropped when Org 9.4 becomes unsupported
(list (maybe-output-stream-string *standard-output*)
(maybe-value-string
(format nil "~{~S~^~%~}" values)))))))))

(defun eval-region (string)
"Evaluate STRING.
Expand Down

0 comments on commit 859ff65

Please sign in to comment.