Subject: Re: bug#60333: [PATCH] whitespace: Update bob, eob markers in base and indirect buffers

From: Ihor Radchenko <[email-masked]>
Date: Wed, 28 Dec 2022 13:48:46 +0000

Stefan Monnier <[email-masked]> writes:
>>> +(defvar whitespace--indirect-buffers nil
>>> +  "Plist mapping a base buffer to a list of its indirect buffers.
>>> +Used to work around Bug#46982.")
>> Org uses a similar variable for similar purposes.
>> Would it make more sense to expose the list of indirect buffers for a
>> given buffer in more centralized way?
>
> "Expose" is the wrong term, because we don't have that info ready to
> be exposed.  We'd either have to create&maintain that list, or compute
> it on-demand when requested.
>
> We could export some way for ELisp to check if BUFFER is the base buffer
> of some other indirect buffers so as to skip the loop through
> `buffer-list` in the common case.  So that sane code (i.e. code which
> doesn't use indirect buffers) doesn't pay for the careless users of that
> anti-feature :-)
>
> If it weren't for backward compatibility, I'd suggest to make
> `buffer-base-buffer` return t (rather than nil) when BUFFER is the base
> buffer of other indirect buffers.

What about:

1. Maintain internal indirect buffer list associated with buffers in C
2. Every time an indirect buffer is created, add the new buffer to that list
3. Add a new function `buffer-indirect-buffers' that will return the
   list of indirect buffers associated with the current buffer.
   The function will do something like:

   (unless (buffer-base-buffer buf)
     (let (result)
      (dolist (indirect BUFFER_INDIRECT(buf))
        (when (buffer-live-p indirect) (push indirect result)))
      BUFFER_INDIRECT(buf) = result
      result))

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>