Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect message/echo output to a buffer in Emacs?

Tags:

emacs

I'm writing a couple of helper functions for my use. They first call up org-publish-project and then call external scripts on that output. I'd like to collect all output from the execution in a temp buffer that pops up.

The external stuff is easier. The function shell-command accepts a second argument about a buffer where to send stdout. But org-publish-project only echoes stuff to minibuffer and it shows on *Messages* if anywhere. Could I somehow redirect all echoes to a given buffer?

like image 948
mike3996 Avatar asked Feb 13 '23 21:02

mike3996


1 Answers

No, there's no such redirect, sadly. You can try to advise the message function, which will catch many of those messages, tho not necessarily all of them.

(defvar my-message-output-buffer nil)

(defadvice message (around my-redirect activate)
  (if my-message-output-buffer
      (with-current-buffer my-message-output-buffer
        (insert (apply #'format (ad-get-args 0))))
    ad-do-it))
like image 198
Stefan Avatar answered Feb 23 '23 00:02

Stefan