unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to write the current buffer into some file?
@ 2014-10-10  0:44 Marcin Borkowski
  2014-10-10  1:23 ` John Mastro
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Marcin Borkowski @ 2014-10-10  0:44 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-10-10  3:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2014-10-10  1:24 ` Stefan Monnier
2014-10-10  3:42 ` Drew Adams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).