Skip to content

Commit b385249

Browse files
committed
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.
1 parent 8f60746 commit b385249

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

eca-chat.el

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4742,5 +4742,30 @@ Used by `eca-doctor'."
47424742
(eca-chat--doctor-format src-buf)
47434743
"No chat buffer found in any running session.\n"))
47444744

4745+
(defun eca-chat--balance-windows-advice (orig-fn &rest args)
4746+
"Prevent `balance-windows' from resizing chat windows.
4747+
Temporarily marks every live eca-chat buffer as fixed-size for
4748+
the duration of ORIG-FN, then clears it.
4749+
This lets `enlarge-window' and `shrink-window' still work."
4750+
(let (chat-bufs)
4751+
(dolist (buf (buffer-list))
4752+
(when (buffer-live-p buf)
4753+
(with-current-buffer buf
4754+
;; Only fix size for chat buffers shown in a side window.
4755+
(when (and (derived-mode-p 'eca-chat-mode) eca-chat-use-side-window)
4756+
(setq-local window-size-fixed
4757+
(if (memq eca-chat-window-side '(left right))
4758+
'width
4759+
'height))
4760+
(push buf chat-bufs)))))
4761+
(unwind-protect
4762+
(apply orig-fn args)
4763+
(dolist (buf chat-bufs)
4764+
(when (buffer-live-p buf)
4765+
(with-current-buffer buf
4766+
(setq-local window-size-fixed nil)))))))
4767+
4768+
(advice-add 'balance-windows :around #'eca-chat--balance-windows-advice)
4769+
47454770
(provide 'eca-chat)
47464771
;;; eca-chat.el ends here

0 commit comments

Comments
 (0)