GNU bug report logs -
#71370
30.0.50; Please un-obsolete buffer-substring as a generalized variable
Previous Next
Full log
Message #56 received at 71370 <at> debbugs.gnu.org (full text, mbox):
Hi Michael,
On 6/19/24 18:44, Michael Heerdegen wrote:
> Adam Porter <adam <at> alphapapa.net> writes:
>
>> ┌────
>> │ (let ((inhibit-read-only t))
>> │ (setf (buffer-substring (oref (magit-current-section) start)
>> │ (oref (magit-current-section) end))
>> │ "foobar\n"))
>> └────
>>
>> Otherwise, one would have to use `delete-region' and then `insert',
>> which is more cumbersome and error-prone.
>
> I guess alternatively you could define a helper function and make that
> `setf'able, like
>
> #+begin_src emacs-lisp
> (defalias 'magit-buffer-substring #'buffer-substring)
> (gv-define-simple-setter magit-buffer-substring
> cl--set-buffer-substring)
> #+end_src
One could, but it would seem tedious and wasteful to have do that across
tens or hundreds of Elisp packages that use this setter and have for years.
The minor ambiguities you point out in one of your later messages are
fair to note; however, they aren't new, and they don't appear to have
discouraged use of this form in practice. On the contrary, the form
appears to be widely useful and understood easily enough.
Given that Emacs is full of idiosyncrasies which are much more impactful
and challenging to understand, I'd think that it would be sufficient to
document this one in the Elisp manual, like others are. I'd certainly
rather do that than deprive users of this useful, simple idiom which is
already widely used.
--Adam
This bug report was last modified 85 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.