unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Andrea Corallo <acorallo@gnu.org>
Cc: Adam Porter <adam@alphapapa.net>,
	71370@debbugs.gnu.org, Ihor Radchenko <yantar92@posteo.net>
Subject: bug#71370: 30.0.50; Please un-obsolete buffer-substring as a generalized variable
Date: Sat, 22 Jun 2024 00:52:43 +0200	[thread overview]
Message-ID: <87ed8pnc1w.fsf@web.de> (raw)
In-Reply-To: <yp1r0cqekut.fsf@fencepost.gnu.org> (Andrea Corallo's message of "Fri, 21 Jun 2024 04:55:06 -0400")

Andrea Corallo <acorallo@gnu.org> writes:

> [...]
> Interesting, I took the time to apply your methodology to all GV
> obsoleted by the same commit and this is the result:
>
> | GV                           | file occurrences |
> |                              |        in github |
> |------------------------------+------------------|
>   [... I picked the lines with 100+ matches ...]
> | buffer-string                |              142 |
> | buffer-substring             |              512 |
> | current-buffer               |              234 |
> [...]

> While some of them are rarely/not used some others looks quite popular.
> This is an indication that the popular ones are probably a good
> abstraction or they are just convenient.

More of the latter I would say.  Nonetheless that's one aspect that
counts.

But especially `buffer-substring' doesn't convince me as a gv because
semantics are very doubtful:

- You say (setf (buffer-substring START END) STRING).  The first thing
  that is not crystal clear is the question whether STRING will be
  added, or will replace, existing text.

- The END argument is either redundant, or, if text is replaced (which
  is what the current implementation does), it is unclear what happens
  if STRING has a length different from (- END START).  The current
  implementation doesn't even fulfill the most _basic_ assumption about
  places: if STRING has a different length, after
  (setf (buffer-substring START END) STRING),
  (buffer-substring START END) will _not_ be equal to STRING.  This is
  very bad, conceptually.

- For this reason resetting the place to the old "value" will not
  always restore the old situation.

- With `cl-letf' the generalized variable gets even more doubtful: if
  you edit the buffer contents inside the scope of the binding,
  reverting a `buffer-substring' gv binding will give surprising
  results, especially if START and END were specified as integers then
  pointing to unrelated positions.

These were exactly the kind of problems why those place expressions had
been obsoleted.  Adding a little helper function with clear semantics
really looks more appropriate in this case in my opinion, even if you
have to remember one more name.


Michael.





  reply	other threads:[~2024-06-21 22:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-05  1:33 bug#71370: 30.0.50; Please un-obsolete buffer-substring as a generalized variable Adam Porter
2024-06-05 11:52 ` Eli Zaretskii
2024-06-05 12:09   ` Ihor Radchenko
2024-06-05 14:16   ` Adam Porter
2024-06-05 14:58     ` Eli Zaretskii
2024-06-05 17:35       ` Adam Porter
2024-06-19 23:44 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-20  4:05   ` Adam Porter
2024-06-20 15:33     ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-20 15:46       ` Ihor Radchenko
2024-06-21  8:55         ` Andrea Corallo
2024-06-21 22:52           ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-06-22  6:05             ` Ihor Radchenko
2024-06-22  8:16               ` Eli Zaretskii
2024-06-22  8:39                 ` Ihor Radchenko
2024-06-22  9:45                   ` Eli Zaretskii
2024-06-22  7:13             ` Eli Zaretskii
2024-06-27 15:09   ` Adam Porter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ed8pnc1w.fsf@web.de \
    --to=bug-gnu-emacs@gnu.org \
    --cc=71370@debbugs.gnu.org \
    --cc=acorallo@gnu.org \
    --cc=adam@alphapapa.net \
    --cc=michael_heerdegen@web.de \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).