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: Mon, 04 Feb 2019 06:23:07 +0100 Message-ID: <87o97syvno.fsf@gnu.org> References: <871s4rqk7u.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="246929"; 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 Mon Feb 04 06:39:20 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 1gqWyV-00128o-Am for ged-emacs-devel@m.gmane.org; Mon, 04 Feb 2019 06:39:19 +0100 Original-Received: from localhost ([127.0.0.1]:36262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqWyU-0001Vm-5P for ged-emacs-devel@m.gmane.org; Mon, 04 Feb 2019 00:39:18 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqWx3-0001I1-IZ for emacs-devel@gnu.org; Mon, 04 Feb 2019 00:37:50 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:57067) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqWis-0006k3-Ov; Mon, 04 Feb 2019 00:23:10 -0500 Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:50921) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1gqWir-0005S8-OL; Mon, 04 Feb 2019 00:23:10 -0500 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 2678A21FC3; Mon, 4 Feb 2019 00:23:09 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 04 Feb 2019 00:23:09 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrkeefgdekvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecufedt tdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhfffgjkf gfgggtsehttdertddtredtnecuhfhrohhmpefvrghsshhilhhoucfjohhrnhcuoehtshgu hhesghhnuhdrohhrgheqnecukfhppedvuddvrddukeehrddvtdefrddufeegnecurfgrrh grmhepmhgrihhlfhhrohhmpehthhhorhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgr lhhithihqdekieejfeekjeekgedqieefhedvleekqdhtshguhheppehgnhhurdhorhhgse hfrghsthhmrghilhdrfhhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Original-Received: from pchta-and (portal.shd.de [212.185.203.134]) by mail.messagingengine.com (Postfix) with ESMTPA id E0538E43B7; Mon, 4 Feb 2019 00:23:07 -0500 (EST) In-Reply-To: (Stefan Monnier's message of "Sat, 02 Feb 2019 10:42:00 -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:232954 Archived-At: Stefan Monnier writes: >> ;; in subr-x.el (or wherever you please) >> (defun replace-region-contents (beg end extract-fn inject-fn) >> "Replace the region between BEG and END using EXTRACT-FN and INJECT-FN. >> >> The current buffer is narrowed to the region between BEG and END, >> then EXTRACT-FN is called in order to extract some value. >> Thereafter, INJECT-FN is called with that value in a temporary >> buffer which it should populate. > > Why two functions instead of just one? You mean by copying the region from the source buffer to the temporary buffer, and then a single function could act just in there? Maybe a drawback could be that an EXTRACT-FN might need the original buffer's configuration, e.g., syntax table, etc. > Also, I think the docstring should hint at the fact that this is meant > for cases where the before and after text share significant parts (so > there's a chance of meaningfully preserving markers). It might do > that simply be referring to `replace-buffer-contents`. It does refer to `replace-buffer-contents'. >> (atomic-change-group > > Why? AFAICT the buffer is not modified until we get to calling > replace-buffer-contents which already has (or should have) the > atomicity property. Correct. I've extracted that from the original `json-pretty-print' and it's not required anymore. Bye, Tassilo