Subject: bug#59618: 29.0.50; global-whitespace-mode + org-capture: "Marker does not point anywhere"

From: Stefan Monnier <[email-masked]>
Date: Wed, 14 Dec 2022 09:15:23 -0500

>> >> Sounds like setting CLONE to t does not clone markers.  That sounds like
>> >> a bug in `make-indirect-buffer', no?
>> > 
>> > AFAIK, it does clone markers. Also changing marker buffer appropriately.
>> 
>> Hmm, maybe not.  The following fails:
>> 
>> emacs -Q
>> 
>> (progn
>>    (whitespace-mode 1)
>>    (with-current-buffer (clone-indirect-buffer "foo" nil)
>>      (cl-assert (eq (current-buffer)
>>                     (marker-buffer whitespace-bob-marker)))))

the buffer cloning code can't know that a given marker is stored in a variable.
So when it clones the variables, both buffers's `whitespace-bob-marker`
variable will point to the same marker.

While we could try and solve it for this specific case by looking for
buffer-local variables that contains markers, the problem is much more
general (think of the case where the buffer var contains a list of
markers, or a hash-table containing markers, or ...), so `clone-buffer`
does not try to solve it.

Instead modes that use such variables are responsable to setup
a `clone-buffer-hook` that does the necessary work.

        Stefan