I've seen a discussion on someone trying to save the actual state of a Lisp Slime REPL. I just want to save a text version of a Geiser Racket REPL session, e.g., *ch1*, while using org-mode. (Then I can add it to my git.) Could someone point me to some elisp that would create the text file with a name that contains the session name, date-time stamp and file ending ".repl"? I've looked at elisp ref talk about "saving buffer," but it doesn't seem to have what I want.

I say all this because just trying to do a C-x C-s will indeed give me a text version of REPL session *ch1*, but it renames the live *ch1* REPL buffer to whatever I'm calling the text version, e.g. ch1-12112016-11:04.repl ... which is cool but not what I need. (BTW, the org-mode/geiser system doesn't get confused. It still uses that REPL session even though it's been renamed.) Again, I just want to save off a text version of what's in the REPL buffer with a timestamp and .repl ending.

1 Answer 1


Here is a starting point. Modify the date format and other components of the filename to taste.

(defun save-buffer-copy (filename)
   (list (let ((fn (concat
                    (buffer-name) "_"
                    (format-time-string "%Ft%T")
           (read-file-name "Save buffer to file: "
                           nil (concat default-directory fn) nil fn))))
  (write-region (point-min) (point-max) filename))

For added usability, you might wish to check the result of (region-active-p) and save the region instead of the whole buffer if true.

  • This worked beautifully. Still amazed/confused by C-x C-s behavior.
    – 147pm
    Dec 12, 2016 at 13:00
  • When the buffer is not associated with a file, C-x C-s appears to behave similarly to C-x C-w, which runs normal-mode after saving. Presumably, this is to ensure reasonable behaviour if the file type is being changed. But it is clearly not what you want in the present case. Perhaps this behaviour can be selectively turned off; I don't know. Dec 12, 2016 at 13:24
  • It's curious how geiser-racket-orgmode still talks just fine to the "session" REPL (multiple REPL sessions are possible with geiser-based Scheme), even after a C-x C-s has renamed it.
    – 147pm
    Dec 12, 2016 at 17:19
  • Well, I have never looked ad geiser-racket-orgmode, so I couldn't possibly say. But my guess is that they have either redefined C-x C-s, or more likely, utilized some hook variable to achieve what they want. If you really want to find out how, investigate the source yourself, or ask a new question if you can't figure it out. Dec 12, 2016 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.