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

Stefan Monnier <address@hidden> writes:

>> --8<---------------cut here---------------start------------->8---
>> (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)))))))))
>> --8<---------------cut here---------------end--------------->8---
>
> LGTM

How would I actually use that version with a replace-fn returning a
buffer and not a string?  It looks to me that I need to do the whole
ceremony of creating a temporary buffer, setting buffers, and ensuring
that the temporary buffer is killed even in the case of an abnormal exit
myself.  That's the hassle my original version tried to eliminate in the
first place...

Bye,
Tassilo



reply via email to

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