Skip to content

Instantly share code, notes, and snippets.

@TeMPOraL
Created April 6, 2018 09:51
Show Gist options
  • Save TeMPOraL/8715c9dd9837e0b601d1cdce0592536e to your computer and use it in GitHub Desktop.
Save TeMPOraL/8715c9dd9837e0b601d1cdce0592536e to your computer and use it in GitHub Desktop.
Redirect a stream to Emacs buffer.
;;; Remember to set `slime-enable-evaluate-in-emacs' to t in Emacs.
;;; Also remember that it basically allows your Lisp to execute any code in your Emacs.
(defmacro with-output-to-emacs-buffer ((stream buffer-name) &body body)
`(let ((results (with-output-to-string (,stream)
,@body)))
(swank:eval-in-emacs `(with-current-buffer (get-buffer-create ,,buffer-name)
(erase-buffer)
(insert ,results)))))
;;; Use example:
(with-output-to-emacs-buffer (*standard-output* "Your Buffer Name") (some-call-that-prints-to-stdout))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment