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: Sat, 02 Feb 2019 14:57:52 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Marcin Borkowski <address@hidden> 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



reply via email to

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