Subject: bug#48337: Fwd: 28.0.50; Emacs crashing randomly (possibly minibuffer activity related)

From: Alan Mackenzie <[email-masked]>
Date: Thu, 13 May 2021 12:09:44 +0000

Hello, Martin.

On Thu, May 13, 2021 at 11:54:37 +0000, Alan Mackenzie wrote:

> How about the following functions, in which minibuf.c now bypasses
> record-window-buffer, instead calling push-window-buffer-onto-prev
> direct?  I'm still not convinced that the call to
> buffer-list-update-hooks belongs in record-window-buffer, but that
> doesn't seem too important any more.  On preliminary testing, these
> appear to work:

OK, I've wrongly moved the with-current-buffer form in the first
function.  I'm aware of this and will correct it.  Also, I've forgotten
to amend the doc string of record-window-buffer.  I'll correct that,
too.

> (defun push-window-buffer-onto-prev (&optional window)
>   "Push entry for WINDOW's buffer onto WINDOW's prev-buffers list.
> WINDOW must be a live window and defaults to the selected one.

> Any duplicate entries for the buffer in the list are removed."
>   (let* ((window (window-normalize-window window t))
>          (buffer (window-buffer window))
>          (w-list (window-prev-buffers window))
>          (entry (assq buffer w-list)))
>     (when entry
>       (setq w-list (assq-delete-all buffer w-list)))
>     (let ((start (window-start window))
>           (point (window-point window)))
>       (setq entry
>             (cons buffer
>                   (if entry
>                       ;; We have an entry, update marker position.
>                       (list (set-marker (nth 1 entry) start)
>                             (set-marker (nth 2 entry) point))
>                     (list (copy-marker start)
>                           (copy-marker
>                            ;; Preserve window-point-insertion-type
>                            ;; (Bug#12855)
>                            point (with-current-buffer buffer
>                                    window-point-insertion-type))))))
>       (set-window-prev-buffers window (cons entry w-list)))))

-- 
Alan Mackenzie (Nuremberg, Germany).