Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Use with-temp-file To Write To A File In Emacs

Quick example of how to write out to a file by making a temporary buffer. You write whatever contents you want to the tmp buffer which then outputs to the file and drops the temporary buffer when it's done.

Code

(with-temp-file "test-file.txt"
  (insert "here is some stuff")
  (insert "\n")
  (insert "and some more stuff")
  )