Subject: bug#17893: 24.4.50; (error "Marker does not point anywhere")

From: [email-masked] (Charles A. Roelli)
Date: Sun, 12 Nov 2017 11:41:27 +0100

> Date: Tue, 15 Jul 2014 09:19:34 -0700 (PDT)
> From: Drew Adams <[email-masked]>
> 
> > That's probably the pop-mark that's in mouse-drag-track.  It has
> > a `push-mark' before, so naively it seems like the mark should be set.
> > 
> > > I was in Info at the time.
> > 
> > I think we need more data to figure out why the mark isn't set and hence
> > what to do about it.  A reproducible test case would obviously be best,
> > but otherwise maybe some indication of what kind of mouse gesture you
> > did, or what kind of customizations you might have that could interact
> > with that code and could unset the mark (maybe from
> > a pre/post-command-hook?).
> 
> Happened again.  Here's a bit more info.  I did M-n in Info
> and got the backtrace:
> 
> Debugger entered--Lisp error: (error "Marker does not point anywhere")
>   pop-mark()
>   #[0 "\303\300\304 \210\305 \207" [t track-mouse auto-hscroll-mode nil deactivate-mark pop-mark] 1 "\n\n(fn)"]()
>   #[0 "\301\204...
>   funcall(#[0 "\301\204...
>   clear-transient-map()
> 
> [Really wish you would fix bug #6991.  Each report of a
> backtrace requires manual editing.  Users should be able to
> just copy & paste.]
> 
> And this is the tail end of C-h l, showing that I really didn't do much after M-n:
> 
> <switch-frame> <down-mouse-1>
> <mouse-1> <help-echo> <down-mouse-1> <mouse-1> M-n
> <help-echo> <down-mouse-2> <mouse-movement> <mouse-2>
> <help-echo> <help-echo> <switch-frame> <switch-frame>
> <down-mouse-1> <mouse-movement> <mouse-1> C-s <help-echo>
> <down-mouse-1> <mouse-movement> <mouse-1> <help-echo>
> <help-echo> <help-echo> C-h l

I recently triggered a similar backtrace after testing some of my own
code that I submitted in Bug#28852, and I suspect the root cause is
similar.  It can be reproduced as follows:

1. Apply the patch at https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28852#8 to emacs-26.
2. src/emacs -q
3. C-x v D RET
4. Click twice with mouse-1, roughly in the middle of the window showing buffer *vc-diff*.
5. M-g c 326 RET
6. C-c C-c RET C-x C-s C-x o g

Now click again in the window showing *vc-diff* and the error is triggered:

  set-transient-map PCH: (error "Marker does not point anywhere")

After M-x toggle-debug-on-error RET and evaluating `pop-mark' manually
with C-M-x, I see this backtrace:

Debugger entered--Lisp error: (error "Marker does not point anywhere")
  +(0 #<marker in no buffer>)
  (set-marker (mark-marker) (+ 0 (car mark-ring)) (current-buffer))
  (progn (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker))))) (set-marker (mark-marker) (+ 0 (car mark-ring)) (current-buffer)) (move-marker (car mark-ring) nil) (if (null (mark t)) (ding)) (setq mark-ring (cdr mark-ring)))
  (if mark-ring (progn (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker))))) (set-marker (mark-marker) (+ 0 (car mark-ring)) (current-buffer)) (move-marker (car mark-ring) nil) (if (null (mark t)) (ding)) (setq mark-ring (cdr mark-ring))))
  pop-mark()
  #f(compiled-function () #<bytecode 0x4124aadd>)()
  #f(compiled-function () #<bytecode 0x4124ab01>)()
  clear-transient-map()

The error happens when the marker at the head of the mark ring no
longer points into a buffer.  In this case, we could either delete the
dead marker until we find a live one, and then pop that, or just not
pop any mark at all.