[Top][All Lists]

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

How to write the current buffer into some file?

From: Marcin Borkowski
Subject: How to write the current buffer into some file?
Date: Fri, 10 Oct 2014 02:44:38 +0200

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 "./"; I want /some
stuff/ to happen in "./test-output/".  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)

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


Marcin Borkowski
Adam Mickiewicz University

reply via email to

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