Subject: bug#32850: 27.0.50; window-swap-states doesn't swap window prev/next-buffers

From: Juri Linkov <[email-masked]>
Date: Sun, 28 Oct 2018 00:11:46 +0300

>>> The most simple way to find out is to define such a list in window.c
>>> and have 'set-window-prev-buffers' holler if the prev_buffers argument
>>> is equal to that list.
>>
>> I can't find out how '(nil nil nil)' gets into the prev-buffers,
>
> Did you try what I proposed?  If that doesn't catch it, I have no
> idea.  IIUC mark_discard_killed_buffers just removes entries from that
> list, it cannot introduce any nil valued elements.
>
>> so to avoid the error, I propose to install this patch:
>
> Well this will just cache the underlying problem.  But I have no good
> idea how to investigate this issue any furher, so install if you like.

I tried this advice:

(advice-add 'set-window-prev-buffers :before
	    (lambda (window prev-buffers)
	      (when (member '(nil nil nil) prev-buffers)
	        (let (frames)
		  (mapbacktrace (lambda (evald fun args flags)
				  (push fun frames)))
		  (display-warning 'prev-buffers
				   (format "%S %S" prev-buffers (nreverse frames))
				   :warning))))
	    '((name . debug)))

but it still doesn't catch (nil nil nil) added to prev-buffers
and here is a new backtrace:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  get-buffer(nil)
  #f(compiled-function (entry) #<bytecode 0x22c73d>)((nil nil nil))
  mapcar(#f(compiled-function (entry) #<bytecode 0x22c73d>) (("*Help*" 1 112) (nil nil nil)))
  window--state-put-2(safe 737)
  window-state-put((... (buffer "isearch.el" ...) (prev-buffers ("*Help*" 1 112) (nil nil nil))) #<window 3 on isearch.el> safe)
  frameset--restore-frame(... t)
  frameset-restore([frameset ...] :reuse-frames t :cleanup-frames t :force-display t :force-onscreen t)
  desktop-restore-frameset()
  desktop-read()
  #f(compiled-function () #<bytecode 0x13ecc2d>)()
  run-hooks(after-init-hook delayed-warnings-hook)
  command-line()
  normal-top-level()