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:23:33 -0700

Hi Marcin,

Marcin Borkowski <mbork@wmi.amu.edu.pl> wrote:
> 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

Yes, I always use `with-current-buffer' when working with a buffer,
because there are many functions that operate on "the current buffer" by
default.

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"))

Hope that helps.

-- 
john



reply via email to

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