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.

Read Files Contents Into A Temporary Emacs Buffer With Lisp

This started as an example way to read file contents. It's also the code that is setup to use `__END__` in a file.

This reads a file into a temporary buffer, deletes everything up to the first occurance of the word `brown`, and then outputs what's left.

Code

(with-temp-buffer
 (insert-file-contents "input.txt")
 (goto-char (point-max))
 (delete-region
  (point-min) 
  (search-forward "__END__" nil nil -1))
 (delete-region
  (point-min) 
  (search-forward "__END__\n" nil nil))
 (append-to-file nil nil "output.txt"))