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: Tue, 05 Feb 2019 14:21:46 +0100 Message-ID: <87y36u9xqt.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="246724"; 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 Tue Feb 05 14:22:02 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 1gr0fq-00120w-15 for ged-emacs-devel@m.gmane.org; Tue, 05 Feb 2019 14:22:02 +0100 Original-Received: from localhost ([127.0.0.1]:60276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr0fo-0001Dw-VZ for ged-emacs-devel@m.gmane.org; Tue, 05 Feb 2019 08:22:00 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr0fg-0001Do-Hp for emacs-devel@gnu.org; Tue, 05 Feb 2019 08:21:53 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:38891) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr0fe-0004IB-D9; Tue, 05 Feb 2019 08:21:50 -0500 Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:33241) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1gr0fe-0004pA-AJ; Tue, 05 Feb 2019 08:21:50 -0500 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 9EA4622268; Tue, 5 Feb 2019 08:21:49 -0500 (EST) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 05 Feb 2019 08:21:49 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrkeeigdegkecutefuodetggdotefrodftvf 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 63CA0100E5; Tue, 5 Feb 2019 08:21:48 -0500 (EST) In-Reply-To: <878syubwv3.fsf@gnu.org> (Tassilo Horn's message of "Tue, 05 Feb 2019 06:57:52 +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:232987 Archived-At: Tassilo Horn writes: >> No, a function which directly returns the text to insert in the form >> of a string (or a buffer, I guess). > > Like so? > > (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))))))))) I just became aware of the fact that we cannot use `replace-buffer-contents' in its current state if the replacement is too large. It becomes unbearable slow. Therefore we cannot simply change `json-pretty-print' to use it, since e.g., restclient.el calls it to format possibly huge json snippets. I wonder where and how to fix that. Maybe `replace-buffer-contents' could fall back to recognize itself if it doesn't make sense to try to restore point and marks, e.g., trivial cases like point is on (point-min) or (point-max) and there are no marks, or the replacement buffer's content exceeds some maximum... Bye, Tassilo