Subject: bug#51029: 28.0.60; Follow-up to Bug#51029: ibuffer-shrink-to-fit does not call fit-window-to-buffer

From: martin rudalics <[email-masked]>
Date: Thu, 7 Oct 2021 11:07:31 +0200

>> 1. emacs -Q
 >> 2. (setq ibuffer-default-shrink-to-minimum-size t)
 >> 3. M-x ibuffer-other-window
 >> 4. *Ibuffer* isn't shrinked
 >>
 >> [Because ibuffer-auto-mode is not bound and hence fit-window-to-buffer
 >> is not called.]
 >
 > Thanks for following up on this.  So the fix I installed avoided the
 > backtrace, but it didn't lead to the behavior you want, i.e. the one
 > promised by `ibuffer-default-shrink-to-minimum-size'.
 >
 >>From reading the code it seems here that the intention is that
 > `ibuffer-default-shrink-to-minimum-size' should only work when
 > `ibuffer-auto-mode' is also enabled?  But that is not documented, is it?
 >
 > Does anyone know how any of this is actually supposed to work?

I suppose the attached would fix it.

martin
diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el
index 046595a4d9..e5095455c2 100644
--- a/lisp/ibuffer.el
+++ b/lisp/ibuffer.el
@@ -1079,8 +1079,8 @@ ibuffer-shrink-to-fit
   ;; Make sure that redisplay is performed, otherwise there can be a
   ;; bad interaction with code in the window-scroll-functions hook
   (redisplay t)
-  (when (and (boundp 'ibuffer-auto-mode) ; ibuf-ext.el might not be loaded yet
-             (buffer-local-value 'ibuffer-auto-mode (window-buffer)))
+  (when (with-current-buffer (window-buffer)
+          (eq major-mode 'ibuffer-mode))
     (fit-window-to-buffer
      nil (and owin
               (/ (frame-height)