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: Sat, 02 Feb 2019 14:57:52 +0100 Message-ID: <874l9mwavz.fsf@gnu.org> References: <871s4rqk7u.fsf@gnu.org> <875zu2ttzw.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="151357"; 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: Marcin Borkowski Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Feb 02 14:58:05 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 1gpvo4-000d6s-R9 for ged-emacs-devel@m.gmane.org; Sat, 02 Feb 2019 14:58:04 +0100 Original-Received: from localhost ([127.0.0.1]:42700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpvo3-0007Mb-SS for ged-emacs-devel@m.gmane.org; Sat, 02 Feb 2019 08:58:03 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpvnx-0007MU-Py for emacs-devel@gnu.org; Sat, 02 Feb 2019 08:57:58 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:38185) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpvnw-00054x-Rj; Sat, 02 Feb 2019 08:57:56 -0500 Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:57993) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1gpvnw-0000CK-P1; Sat, 02 Feb 2019 08:57:56 -0500 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id C98B620DDF; Sat, 2 Feb 2019 08:57:55 -0500 (EST) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Sat, 02 Feb 2019 08:57:55 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrkedtgdehkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecufedt tdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhfffgjkf gfgggtsehttdertddtredtnecuhfhrohhmpefvrghsshhilhhoucfjohhrnhcuoehtshgu hhesghhnuhdrohhrgheqnecukfhppeelfedrvdefiedruddvledrhedvnecurfgrrhgrmh epmhgrihhlfhhrohhmpehthhhorhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhi thihqdekieejfeekjeekgedqieefhedvleekqdhtshguhheppehgnhhurdhorhhgsehfrg hsthhmrghilhdrfhhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Original-Received: from thinkpad-t440p (p5dec8134.dip0.t-ipconnect.de [93.236.129.52]) by mail.messagingengine.com (Postfix) with ESMTPA id 15E0910087; Sat, 2 Feb 2019 08:57:53 -0500 (EST) In-Reply-To: <875zu2ttzw.fsf@mbork.pl> (Marcin Borkowski's message of "Sat, 02 Feb 2019 10:33:23 +0100") 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:232909 Archived-At: Marcin Borkowski writes: Hi Marcin, >> --8<---------------cut here---------------start------------->8--- >> ;; 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. >> >> Finally, the region in the source buffer is replaced with the >> contents of the temporary buffer prepared by INJECT-FN using >> `replace-buffer-contents'." > > It looks fairly interesting, and I can see quite a few uses for a > function like this. The docstring doesn't seem to explain a lot to > me, though. In particular, what are the arguments and return values > of EXTRACT-FN and INJECT-FN? EXTRACT-FN has no argument. It's just run in the source buffer. Whatever it returns is passed as the argument to INJECT-FN which is run in a temporary, empty buffer and which it should use to prepare the temporary buffer whose contents will replace the original region in the source buffer. Bye, Tassilo