Subject: bug#49275: 28.0.50; [PATCH] improve-switch-to-prev-buffer-skip

From: Trust me I am a Doctor <[email-masked]>
Date: Wed, 21 Jul 2021 11:59:52 +0200

martin rudalics <[email-masked]> writes:

> Sorry but this is still not right.  It now gets me
>
> In switch-to-prev-buffer:
> ../../lisp/window.el:4724:27: Warning: ‘not’ called with 2 args, but requires
>     1
> ../../lisp/window.el:4724:27: Warning: reference to free variable ‘functionp’
> ../../lisp/window.el:4724:27: Warning: reference to free variable
>     ‘switch-to-prev-buffer-skip-p’
>
> In switch-to-next-buffer:
> ../../lisp/window.el:4846:27: Warning: ‘not’ called with 2 args, but requires
>     1
> ../../lisp/window.el:4846:27: Warning: reference to free variable ‘functionp’
> ../../lisp/window.el:4846:27: Warning: reference to free variable
>     ‘switch-to-prev-buffer-skip-p’
>
> martin

Sorry that was the same buggy one.

>From b1375219d247d87ac72a41fb4f1887a9a40039fc Mon Sep 17 00:00:00 2001
From: Trust me I am a doctor <[email-masked]>
Date: Sun, 27 Jun 2021 02:27:48 +0200
Subject: [PATCH] Make switch-to-prev-buffer-skip more reliable

* lisp/window.el (switch-to-prev-buffer): It was fall-backing to the
first skipped buffer, what I know is it is most probably undesirable
when 'switch-to-prev-buffer-skip' is a function. So we only do it when
it is not a function.
(switch-to-next-buffer): Tiddo, and also fix a bug where this function
was returning the same buffer, as it never should do.
---
 lisp/window.el | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lisp/window.el b/lisp/window.el
index c0511bec4c..9315107f1f 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -4721,8 +4721,8 @@ switch-to-prev-buffer
 	       window new-buffer (nth 1 entry) (nth 2 entry))
 	      (throw 'found t)))))
 
-      (when skipped
-        ;; Show first skipped buffer.
+      (when (and skipped (not (functionp switch-to-prev-buffer-skip)))
+        ;; Show first skipped buffer, unless skip was a function.
 	(setq new-buffer skipped)
 	(set-window-buffer-start-and-point window new-buffer)))
 
@@ -4831,6 +4831,7 @@ switch-to-next-buffer
       ;; nreverse here!)
       (dolist (entry (reverse (window-prev-buffers window)))
 	(when (and (not (eq new-buffer (car entry)))
+                   (not (eq old-buffer (car entry)))
                    (setq new-buffer (car entry))
 		   (or (buffer-live-p new-buffer)
 		       (not (setq killed-buffers
@@ -4842,8 +4843,8 @@ switch-to-next-buffer
 	     window new-buffer (nth 1 entry) (nth 2 entry))
 	    (throw 'found t))))
 
-      (when skipped
-        ;; Show first skipped buffer.
+      (when (and skipped (not (functionp switch-to-prev-buffer-skip)))
+        ;; Show first skipped buffer, unless skip was a function.
 	(setq new-buffer skipped)
 	(set-window-buffer-start-and-point window new-buffer)))
 
-- 
2.20.1

--