all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Mastro <john.b.mastro@gmail.com>
To: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: How to write the current buffer into some file?
Date: Thu, 9 Oct 2014 18:41:42 -0700	[thread overview]
Message-ID: <CAOj2CQRj9CAbVPmuvgYQer4m1n_ANt5+v5X8qtb40fKFKwcC_A@mail.gmail.com> (raw)
In-Reply-To: <CAOj2CQR=NuYkdccwbNt19yTKD=cz=9FBkXtXOQQPTR=TyFeZJQ@mail.gmail.com>

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	other threads:[~2014-10-10  1:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10  0:44 How to write the current buffer into some file? Marcin Borkowski
2014-10-10  1:23 ` John Mastro
2014-10-10  1:41   ` John Mastro [this message]
2014-10-10  1:24 ` Stefan Monnier
2014-10-10  3:42 ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOj2CQRj9CAbVPmuvgYQer4m1n_ANt5+v5X8qtb40fKFKwcC_A@mail.gmail.com \
    --to=john.b.mastro@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.