From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: How to write the current buffer into some file? Date: Fri, 10 Oct 2014 02:44:38 +0200 Message-ID: <87lhookb2h.fsf@wmi.amu.edu.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1412901913 21111 80.91.229.3 (10 Oct 2014 00:45:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 10 Oct 2014 00:45:13 +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 02:45:05 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 1XcOKP-0008Ls-3W for geh-help-gnu-emacs@m.gmane.org; Fri, 10 Oct 2014 02:45:05 +0200 Original-Received: from localhost ([::1]:45589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcOKO-0004al-ND for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Oct 2014 20:45:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41692) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcOKB-0004aU-AA for help-gnu-emacs@gnu.org; Thu, 09 Oct 2014 20:44:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XcOK6-000385-Ow for help-gnu-emacs@gnu.org; Thu, 09 Oct 2014 20:44:51 -0400 Original-Received: from msg.wmi.amu.edu.pl ([2001:808:114:2::50]:52977) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcOK6-00037v-Hw for help-gnu-emacs@gnu.org; Thu, 09 Oct 2014 20:44:46 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by msg.wmi.amu.edu.pl (Postfix) with ESMTP id 105D75B84B for ; Fri, 10 Oct 2014 02:44:45 +0200 (CEST) Original-Received: from msg.wmi.amu.edu.pl ([127.0.0.1]) by localhost (msg.wmi.amu.edu.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9Fg2NgaVXM3X for ; Fri, 10 Oct 2014 02:44:44 +0200 (CEST) Original-Received: from localhost (111-128.echostar.pl [213.156.111.128]) by msg.wmi.amu.edu.pl (Postfix) with ESMTPSA id B7FB75B846 for ; Fri, 10 Oct 2014 02:44:44 +0200 (CEST) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:808:114:2::50 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:100358 Archived-At: 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