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

From: Stefan Kangas <[email-masked]>
Date: Sat, 26 Nov 2022 22:54:25 -0800

Ihor Radchenko <[email-masked]> writes:

> Stefan Kangas <[email-masked]> writes:
>
>> I fail to reproduce this bug using this recipe.
>>
>> Could you please clarify what exactly you did in step 5 and 6?
>
> Let me provide the detailed recipe I used:
>
> 1. rm ~/.notes (this is the default capture target)
> 2. emacs-29-vcs -Q --execute '(global-whitespace-mode)'
> 3. M-x org-capture <RET> t C-c C-c
> 4. M-x org-capture <RET> t
> 5. M-x toggle-debug-on-error
> 6. C-x b .notes
> 7. C-s %? <RET>
> 8. C-a
> 9. C-<SPC> M-> C-w

Thanks, I can reproduce the backtrace now.

Stepping through `whitespace--update-bob-eob' with edebug shows that the
`goto-char' in this fragment fails, because `whitespace-bob-marker' is
nil:

    (save-excursion
      (goto-char whitespace-bob-marker)
      ;; Any change in the first non-`empty'
      ;; line, even if it's not the first
      ;; character in the line, can potentially
      ;; cause subsequent lines to become
      ;; classified as `empty' (e.g., delete the
      ;; "x" from " x").
      (forward-line 1)
      (point))

The `whitespace--update-bob-eob' function is new in Emacs 29 and was
added in commit f47a5324f44e by Richard Hansen (in Cc).

Here is the backtrace again, for reference:

Debugger entered--Lisp error: (error "Marker does not point anywhere")
  whitespace--update-bob-eob(37 37 29)
  delete-and-extract-region(37 66)
  #f(compiled-function (beg end delete) #<bytecode
0x15337359c91d96f1>)(37 66 delete)
  apply(#f(compiled-function (beg end delete) #<bytecode
0x15337359c91d96f1>) (37 66 delete))
  #f(compiled-function (funs global args) #<bytecode
-0xf6c557b8176d62>)(nil nil (37 66 delete))
  buffer-substring--filter(37 66 delete)
  filter-buffer-substring(37 66 delete)
  #f(compiled-function (method) #<bytecode -0x2fb4b4ebabaf02c>)(delete)
  kill-region(37 66 region)
  funcall-interactively(kill-region 37 66 region)
  command-execute(kill-region)