From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: How to write the current buffer into some file? Date: Thu, 9 Oct 2014 18:23:33 -0700 Message-ID: References: <87lhookb2h.fsf@wmi.amu.edu.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1412904255 13919 80.91.229.3 (10 Oct 2014 01:24:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 10 Oct 2014 01:24:15 +0000 (UTC) To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 10 03:24:09 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XcOwC-0006lt-Dj for geh-help-gnu-emacs@m.gmane.org; Fri, 10 Oct 2014 03:24:08 +0200 Original-Received: from localhost ([::1]:45708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcOwC-0002nr-0Z for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Oct 2014 21:24:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcOw0-0002nk-Pw for help-gnu-emacs@gnu.org; Thu, 09 Oct 2014 21:23:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XcOvz-0005D9-Pb for help-gnu-emacs@gnu.org; Thu, 09 Oct 2014 21:23:56 -0400 Original-Received: from mail-oi0-x22e.google.com ([2607:f8b0:4003:c06::22e]:49433) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcOvz-0005Co-Iz for help-gnu-emacs@gnu.org; Thu, 09 Oct 2014 21:23:55 -0400 Original-Received: by mail-oi0-f46.google.com with SMTP id h136so5123070oig.5 for ; Thu, 09 Oct 2014 18:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=uV12o7JvrvMLso9EEy2KBy+dE5CRpC3CA8rqB4vknUI=; b=Px0P18PTZW7RyS6dHQ8xBlm4jhiYfzXRrAa2NE24Y//HJh0XeiIr2vFxidhDXyQmy8 S8eTiVeg2KxxZfXqtpK0P29iQjys1Y8nODBupseqimMw7zygwsELedV4ZomY3FepJTo9 zbgeS2UJ7v4Mp8mem68n1YR6Sxf96Npx2lP5tQrrUSu7UaVjUTtjOyF8xrXRXnhw8yut g0GKcDysCw2PB69YDs/Ci2svVjkGuFrTW2ijJw0ZnwK9O1FQZeyfgkjygAmi2ardH6t3 WWMiCHzXaWf/t+PUBUDgPHShFZmXn6N7C7v5lqrJ063/37q9oiEyBB3SztleC8/ZXwDm HuOg== X-Received: by 10.182.96.202 with SMTP id du10mr1485710obb.9.1412904233790; Thu, 09 Oct 2014 18:23:53 -0700 (PDT) Original-Received: by 10.76.125.194 with HTTP; Thu, 9 Oct 2014 18:23:33 -0700 (PDT) In-Reply-To: <87lhookb2h.fsf@wmi.amu.edu.pl> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c06::22e X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100360 Archived-At: Hi Marcin, Marcin Borkowski 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