home ~ projects ~ socials

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.

(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"))
-- end of line --