From b385249601893fa551dfa41224465dd2215eaa06 Mon Sep 17 00:00:00 2001 From: Sam Tavakoli Date: Sun, 7 Jun 2026 17:11:09 +0100 Subject: [PATCH] fix: prevent `balance-windows` from resizing chat As title, without this change, when running `balance-windows`, even if eca-chat window is a side window, it will try to balance it. An alternative is to not use side window, but the implication then is, your chat constantly is resized when opening/closing buffers. With this fix, your side window size is respected regardless of other buffers/windows. Without hindering any other window operations. --- eca-chat.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/eca-chat.el b/eca-chat.el index 4ba6042..3bfe7d7 100644 --- a/eca-chat.el +++ b/eca-chat.el @@ -4742,5 +4742,30 @@ Used by `eca-doctor'." (eca-chat--doctor-format src-buf) "No chat buffer found in any running session.\n")) +(defun eca-chat--balance-windows-advice (orig-fn &rest args) + "Prevent `balance-windows' from resizing chat windows. +Temporarily marks every live eca-chat buffer as fixed-size for +the duration of ORIG-FN, then clears it. +This lets `enlarge-window' and `shrink-window' still work." + (let (chat-bufs) + (dolist (buf (buffer-list)) + (when (buffer-live-p buf) + (with-current-buffer buf + ;; Only fix size for chat buffers shown in a side window. + (when (and (derived-mode-p 'eca-chat-mode) eca-chat-use-side-window) + (setq-local window-size-fixed + (if (memq eca-chat-window-side '(left right)) + 'width + 'height)) + (push buf chat-bufs))))) + (unwind-protect + (apply orig-fn args) + (dolist (buf chat-bufs) + (when (buffer-live-p buf) + (with-current-buffer buf + (setq-local window-size-fixed nil))))))) + +(advice-add 'balance-windows :around #'eca-chat--balance-windows-advice) + (provide 'eca-chat) ;;; eca-chat.el ends here