[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
- Re: [RFC]: replace-region-contents, (continued)
- Re: [RFC]: replace-region-contents, Stefan Monnier, 2019/02/03
- Re: [RFC]: replace-region-contents, Tassilo Horn, 2019/02/04
- Re: [RFC]: replace-region-contents, Stefan Monnier, 2019/02/04
- Re: [RFC]: replace-region-contents, Tassilo Horn, 2019/02/05
- Re: [RFC]: replace-region-contents,
Tassilo Horn <=
- Re: [RFC]: replace-region-contents, Eli Zaretskii, 2019/02/05
- Re: [RFC]: replace-region-contents, Tassilo Horn, 2019/02/05
- Re: [RFC]: replace-region-contents, Eli Zaretskii, 2019/02/06
- Re: [RFC]: replace-region-contents, Tassilo Horn, 2019/02/06
- Re: [RFC]: replace-region-contents, Eli Zaretskii, 2019/02/06
- Re: [RFC]: replace-region-contents, Tassilo Horn, 2019/02/06
- Re: [RFC]: replace-region-contents, Tassilo Horn, 2019/02/08
- Re: [RFC]: replace-region-contents, Stefan Monnier, 2019/02/08
- Re: [RFC]: replace-region-contents, Tassilo Horn, 2019/02/08
- Re: [RFC]: replace-region-contents, Eli Zaretskii, 2019/02/08