From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Jean-Christophe Helary Newsgroups: gmane.emacs.help Subject: safe way to add contents to a file ? Date: Wed, 18 Dec 2019 09:03:52 +0900 Message-ID: <0FE61EAF-672C-4348-8107-F4C3D176FCF4@traduction-libre.org> Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3601.0.10\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="234580"; mail-complaints-to="usenet@blaine.gmane.org" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 18 01:04:18 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ihMp7-000yu4-Nv for geh-help-gnu-emacs@m.gmane.org; Wed, 18 Dec 2019 01:04:17 +0100 Original-Received: from localhost ([::1]:47470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihMp6-0008PU-FE for geh-help-gnu-emacs@m.gmane.org; Tue, 17 Dec 2019 19:04:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45445) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihMor-0008PM-OT for help-gnu-emacs@gnu.org; Tue, 17 Dec 2019 19:04:02 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihMoq-0005mn-8u for help-gnu-emacs@gnu.org; Tue, 17 Dec 2019 19:04:01 -0500 Original-Received: from relay9-d.mail.gandi.net ([217.70.183.199]:44947) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihMoq-0005js-2I for help-gnu-emacs@gnu.org; Tue, 17 Dec 2019 19:04:00 -0500 X-Originating-IP: 210.160.37.46 Original-Received: from [10.251.103.135] (unknown [210.160.37.46]) (Authenticated sender: jean.christophe.helary@traduction-libre.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id C87B7FF806 for ; Wed, 18 Dec 2019 00:03:56 +0000 (UTC) X-Mailer: Apple Mail (2.3601.0.10) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.70.183.199 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.org gmane.emacs.help:122056 Archived-At: I'm struggling with what is the ideal "elispy" way of adding contents to = a file at a given position. What I want it: - create some content - put that content at a specific location in a file saved on disk (current use case: add an xml block to an RSS file) I thought write-region would do the trick but there are 2 issues with it 1) if APPEND is a number, that's the position from which my contents = will *overwrite* the rest of the file (I want to *insert* my contents) 2) there are weird things like the whole code where I call this function = is actually copied to the target file buffer and I have no idea how to = prevent that. So, I thought of something a bit convoluted: use a temporary buffer insert the contents of the file there find the point where I want to insert my contents find the end of the file copy that region to a different buffer write my contents from the point I specified above append the copied region to that write all that to the original file But I thought, it's not like such things don't happen all the time in = emacs, so there must be a better workflow. But the reference is incredibly cryptic regarding that and the Intro = does not address any file i/o at all... Jean-Christophe Helary ----------------------------------------------- http://mac4translators.blogspot.com @brandelune