From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: Re: [RFC]: replace-region-contents Date: Wed, 06 Feb 2019 09:07:59 +0100 Message-ID: <877eede3vk.fsf@gnu.org> References: <871s4rqk7u.fsf@gnu.org> <87o97syvno.fsf@gnu.org> <878syubwv3.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="87663"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Feb 06 09:08:52 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1grIGK-000MXJ-0d for ged-emacs-devel@m.gmane.org; Wed, 06 Feb 2019 09:08:52 +0100 Original-Received: from localhost ([127.0.0.1]:46754 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grIGC-0000SY-CK for ged-emacs-devel@m.gmane.org; Wed, 06 Feb 2019 03:08:44 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:56618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grIFY-0000SR-H5 for emacs-devel@gnu.org; Wed, 06 Feb 2019 03:08:05 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:34698) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grIFY-0000AA-Aj; Wed, 06 Feb 2019 03:08:04 -0500 Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:53239) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1grIFY-0004u6-8P; Wed, 06 Feb 2019 03:08:04 -0500 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id A1B9E21FC1; Wed, 6 Feb 2019 03:08:03 -0500 (EST) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Wed, 06 Feb 2019 03:08:03 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrkeejgdduudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhhtnecuuegrihhlohhuthemucef tddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufhffjg fkfgggtgesthdtredttdertdenucfhrhhomhepvfgrshhsihhlohcujfhorhhnuceothhs ughhsehgnhhurdhorhhgqeenucfkphepvdduvddrudekhedrvddtfedrudefgeenucfrrg hrrghmpehmrghilhhfrhhomhepthhhohhrnhdomhgvshhmthhprghuthhhphgvrhhsohhn rghlihhthidqkeeijeefkeejkeegqdeifeehvdelkedqthhsughhpeepghhnuhdrohhrgh esfhgrshhtmhgrihhlrdhfmhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Original-Received: from pchta-and (portal.shd.de [212.185.203.134]) by mail.messagingengine.com (Postfix) with ESMTPA id 5DA4910310; Wed, 6 Feb 2019 03:08:01 -0500 (EST) In-Reply-To: (Stefan Monnier's message of "Tue, 05 Feb 2019 08:43:25 -0500") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:233032 Archived-At: Stefan Monnier writes: >> --8<---------------cut here---------------start------------->8--- >> (defun replace-region-contents (beg end replace-fn) >> (save-excursion >> (save-restriction >> (narrow-to-region beg end) >> (goto-char (point-min)) >> (let ((repl (funcall replace-fn))) >> (if (bufferp repl) >> (replace-buffer-contents repl) >> (let ((source-buffer (current-buffer))) >> (with-temp-buffer >> (insert repl) >> (let ((tmp-buffer (current-buffer))) >> (set-buffer source-buffer) >> (replace-buffer-contents tmp-buffer))))))))) >> --8<---------------cut here---------------end--------------->8--- > > LGTM How would I actually use that version with a replace-fn returning a buffer and not a string? It looks to me that I need to do the whole ceremony of creating a temporary buffer, setting buffers, and ensuring that the temporary buffer is killed even in the case of an abnormal exit myself. That's the hassle my original version tried to eliminate in the first place... Bye, Tassilo