From: Marcin Borkowski <mbork@wmi.amu.edu.pl>
To: "help-gnu-emacs\@gnu.org" <help-gnu-emacs@gnu.org>
Subject: How to write the current buffer into some file?
Date: Fri, 10 Oct 2014 02:44:38 +0200 [thread overview]
Message-ID: <87lhookb2h.fsf@wmi.amu.edu.pl> (raw)
Hello list,
I'd like to do /some stuff/ on the current buffer. /Some stuff/
includes creating a new file, similar to the current buffer, with some
modifications. Say that I'm visiting file "./test.org"; I want /some
stuff/ to happen in "./test-output/test-output.org". I can handle the
filename change (easy), creation of the directory (easy), but here's
where I'm (a bit) stuck: how to create a new buffer, do the
modifications, save it, and close/bury so that after my function
returns, the user sees the same buffer as before? I can't just
write-file, since this will change the file I'm visiting. Here's what
I've come up with:
I can clone the existing buffer (too bad that clone-buffer doesn't let
me do this if I'm visiting a file; why is that so?) by means of manually
creating it, copying the contents (by means of insert-buffer-substring,
for instance), doing my modifications, saving it, and (possibly)
burying.
Question 1: did I forget about something? Should I wrap all this in
some (with-current-buffer ...)? (I guess that if I call all this
interactively, and do not change the buffer of the selected window,
(with-current-buffer) is not necessary - but maybe (a) it's bad style
and/or (b) it can backfire when e.g. I decide to run my function
non-interactively (or maybe in some other circumstances)?
Question 2: What would happen if I didn't (bury-buffer) after all that
stuff? Would it end up "just below" the current buffer in the buffer
list?
TIA,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Adam Mickiewicz University
next reply other threads:[~2014-10-10 0:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-10 0:44 Marcin Borkowski [this message]
2014-10-10 1:23 ` How to write the current buffer into some file? John Mastro
2014-10-10 1:41 ` John Mastro
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=87lhookb2h.fsf@wmi.amu.edu.pl \
--to=mbork@wmi.amu.edu.pl \
--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.