From: Bryan Hoyt
Subject: Redirecting output to file with elisp
Date: 
Message-ID: <slrn9a4qs5.288.bryhoyt@mailandnews.com>
Hello,

	I'm writing a little program in emacs lisp, and I need to
redirect the output of, say, the print function to a file WITHOUT
executing a shell command to do it. Just pure elisp. Kind of the
equivalent of the shell command:

echo "arbitrary output" > /some_file.whatever

Except with pure elisp. How is this done?

Thanks very much.

-- 

Bryan Hoyt

-----------------------------------

Rock'n'Roll is to music what Etch-A-Sketch is to art.
From: Hannu Koivisto
Subject: Re: Redirecting output to file with elisp
Date: 
Message-ID: <87ofvhjftd.fsf@lynx.ionific.com>
·······@clear.net.nz (Bryan Hoyt) writes:

| 	I'm writing a little program in emacs lisp, and I need to

You should ask Emacs Lisp questions in Emacs newsgroups such as
gnu.emacs.help.  Followups set.

| redirect the output of, say, the print function to a file WITHOUT
| executing a shell command to do it. Just pure elisp. Kind of the

I wrote the following convenience macro for this purpose:

(defmacro with-output-to-file (file &rest body)
  `(with-temp-file ,file
    (let ((standard-output (current-buffer)))
      ,@body)))

Study the documentation of with-temp-file, standard-output and
print to see how/why this works if it's not obvious to you.  With
that you can say, for example:

(with-output-to-file "foo"
  (print '(bar baz)))

-- 
Hannu