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: Mon, 04 Feb 2019 06:23:07 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Stefan Monnier <address@hidden> 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



reply via email to

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