I use with-output-to-temp-buffer function, redirect the standard output to it, save it to a file, switch back to previous buffer, then kill the temp buffer.
(require 'find-lisp)
(with-output-to-temp-buffer "*my output*"
(mapc 'print (find-lisp-find-files "~/project/clisp" "\\.lisp$"))
(setq prev-buffer (buffer-name))
(switch-to-buffer "*my output*")
(write-region nil nil "test")
(switch-to-buffer prev-buffer)
(kill-buffer "*my output*")
)
But error below occur. I don't know why.
Debugger entered--Lisp error: (error "Selecting deleted buffer")
PS: Is there more elegant way to achieve this in elsip(redirect standard output to a file). Thanks