>> This means that such calls should be wrapped with let-bind >> to handle the case when the list of prev/next-buffers becomes empty >> to switch to any other buffer not shown in that window before: >> >> @@ -4994,7 +5042,8 @@ bury-buffer >> (t >> ;; Switch to another buffer in window. >> (set-window-dedicated-p nil nil) >> - (switch-to-prev-buffer nil 'bury))) >> + (let ((switch-to-prev-buffer-wrap nil)) >> + (switch-to-prev-buffer nil 'bury)))) >> ;; Always return nil. >> nil)) > > You mean to avoid a "Could not replace buffer ..." error? Can't we > handle this problem in 'switch-to-prev-buffer' when BURY-OR-KILL and > 'switch-to-prev-buffer-wrap' are non-nil, here and in the other calls > you cite? Thanks, so the patch below ignores 'switch-to-prev-buffer-wrap' in 'switch-to-prev-buffer' when its argument BURY-OR-KILL is non-nil.