help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to write the current buffer into some file?


From: John Mastro
Subject: Re: How to write the current buffer into some file?
Date: Thu, 9 Oct 2014 18:41:42 -0700

John Mastro <john.b.mastro@gmail.com> wrote:
> If you use a combination of `with-current-buffer' and `write-region', no
> call to `bury-buffer' will be necessary. Goofy example below:
>
>     (with-current-buffer (clone-buffer)
>       (insert "\nStuff happening!\n")
>       (write-region (point-min) (point-max) "~/destination.txt"))

I didn't address the fact that `clone-buffer' won't work with a
file-visiting buffer, as you noted. Also, `with-temp-buffer' is probably
an even better fit than `with-current-buffer', if you don't need that
buffer to stick around when you're done.

Here's another example approach, hopefully more useful:

    (let ((buffer (current-buffer)))
      (with-temp-buffer
        (insert-buffer-substring buffer)
        (insert "\nStuff happening!\n")
        (write-region (point-min) (point-max) "~/destination.txt")))

--
john



reply via email to

[Prev in Thread] Current Thread [Next in Thread]