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:41:42 -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 1412905346 25291 80.91.229.3 (10 Oct 2014 01:42:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 10 Oct 2014 01:42:26 +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:42:20 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 1XcPDl-0005AG-JE for geh-help-gnu-emacs@m.gmane.org; Fri, 10 Oct 2014 03:42:17 +0200 Original-Received: from localhost ([::1]:45743 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcPDl-0005sp-9K for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Oct 2014 21:42:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcPDZ-0005sg-FB for help-gnu-emacs@gnu.org; Thu, 09 Oct 2014 21:42:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XcPDY-0003Y1-PI for help-gnu-emacs@gnu.org; Thu, 09 Oct 2014 21:42:05 -0400 Original-Received: from mail-oi0-x22d.google.com ([2607:f8b0:4003:c06::22d]:48684) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcPDY-0003XU-62 for help-gnu-emacs@gnu.org; Thu, 09 Oct 2014 21:42:04 -0400 Original-Received: by mail-oi0-f45.google.com with SMTP id i138so5193681oig.32 for ; Thu, 09 Oct 2014 18:42:02 -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=iraJACX6zT+abkA+55/M7P+nEzFXHqTjB+H7CHkE4Ws=; b=D7pcpEjQxZwZWRdk31vNaCFfE5hqThaHoepSkc5IacQpXojO1LslfNyjcGreXus2bC 1notJ1/MqmUBm6lEkn7RmAlM/WQ9o5TRPVLsz7ZJyRyIKaVNwnk0LFQMHrbDJ+3A+HHR EWWgyAyuh0y1CRU6/RwqW6phc3PKCgk9KG5uCNuANIeGXFNkJGiEwG4uECr6pswHMvah ZsZzeXdnRPjVWqW8hYsyDrJcwYJNHcP1LTY+Sg2ubKk9anRONkENJaZoPkNSRP9xmTP0 PiKfPmoHWVxVQZICHAENEZ4i5X9yag2/WMwlHVR2c2VOrYc7MMBE/G9ejwdUhQnu1N0r mZbA== X-Received: by 10.60.65.35 with SMTP id u3mr1513862oes.35.1412905322731; Thu, 09 Oct 2014 18:42:02 -0700 (PDT) Original-Received: by 10.76.125.194 with HTTP; Thu, 9 Oct 2014 18:41:42 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c06::22d 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:100362 Archived-At: John Mastro wrote: > 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")) I didn't address the fact that `clone-buffer' won't work with a file-visiting buffer, as you noted. Also, `with-temp-buffer' is probably an even better fit than `with-current-buffer', if you don't need that buffer to stick around when you're done. Here's another example approach, hopefully more useful: (let ((buffer (current-buffer))) (with-temp-buffer (insert-buffer-substring buffer) (insert "\nStuff happening!\n") (write-region (point-min) (point-max) "~/destination.txt"))) -- john