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

From: Eli Zaretskii <[email-masked]>
Date: Thu, 01 Dec 2022 14:06:19 +0200

> From: Stefan Kangas <[email-masked]>
> Date: Sat, 26 Nov 2022 22:54:25 -0800
> Cc: Eli Zaretskii <[email-masked]>, [email-masked], 
> 	Arsen Arsenović <[email-masked]>, 
> 	Richard Hansen <[email-masked]>
> 
> Stepping through `whitespace--update-bob-eob' with edebug shows that the
> `goto-char' in this fragment fails, because `whitespace-bob-marker' is
> nil:

Is it really nil or is it a marker that "points nowhere"?

This part:

> Here is the backtrace again, for reference:
> 
> Debugger entered--Lisp error: (error "Marker does not point anywhere")
>   whitespace--update-bob-eob(37 37 29)

seems to indicate the latter.

Anyway, it sounds like the changes in f47a5324f44e caused the two markers,
whitespace-bob-marker and whitespace-eob-marker to sometimes "point
nowhere".  The band-aid patch below avoids the error reported in this bug,
but redisplay still complains in *Messsages*:

  Error during redisplay: (jit-lock-function 45) signaled (error "Marker does not point anywhere")

Richard, please chime in.

Here's the band-aid patch I promised:

diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 25ea07e..bed2a82 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -2315,7 +2315,11 @@ whitespace-post-command-hook
   (unless (and (eq whitespace-point (point))
                (not whitespace-buffer-changed))
     (when (and (not whitespace-buffer-changed)
-               (memq 'empty whitespace-active-style))
+               (memq 'empty whitespace-active-style)
+               (markerp whitespace-bob-marker)
+               (bufferp (marker-buffer whitespace-bob-marker))
+               (markerp whitespace-eob-marker)
+               (bufferp (marker-buffer whitespace-eob-marker)))
       ;; No need to handle the `whitespace-buffer-changed' case here
       ;; because that is taken care of by the `font-lock-multiline'
       ;; text property.
@@ -2422,6 +2426,8 @@ whitespace--update-bob-eob
         (widen)
         (let ((inhibit-read-only t))
           (when (or (null beg)
+                    (and (markerp whitespace-bob-marker)
+                         (bufferp (marker-buffer whitespace-bob-marker))
                     (<= beg (save-excursion
                               (goto-char whitespace-bob-marker)
                               ;; Any change in the first non-`empty'
@@ -2431,7 +2437,7 @@ whitespace--update-bob-eob
                               ;; classified as `empty' (e.g., delete the
                               ;; "x" from " x").
                               (forward-line 1)
-                              (point))))
+                              (point)))))
             (goto-char 1)
             (set-marker whitespace-bob-marker (point))
             (save-match-data
@@ -2440,11 +2446,13 @@ whitespace--update-bob-eob
                 (put-text-property (match-beginning 1) (match-end 1)
                                    'font-lock-multiline t))))
           (when (or (null end)
+                    (and (markerp whitespace-eob-marker)
+                         (bufferp (marker-buffer whitespace-eob-marker))
                     (>= end (save-excursion
                               (goto-char whitespace-eob-marker)
                               ;; See above comment for the BoB case.
                               (forward-line -1)
-                              (point))))
+                              (point)))))
             (goto-char (1+ (buffer-size)))
             (set-marker whitespace-eob-marker (point))
             (save-match-data