emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC]: replace-region-contents


From: Tassilo Horn
Subject: Re: [RFC]: replace-region-contents
Date: Tue, 05 Feb 2019 14:21:46 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Tassilo Horn <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]