Skip to content

Commit 57098da

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 03086af commit 57098da

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
@@ -3672,5 +3672,30 @@ Resteps selected message plist or nil if no messages or cancelled."
36723672
(save-buffer))
36733673
(eca-info (format "Saved chat to '%s'" file)))))
36743674

3675+
(defun eca-chat--balance-windows-advice (orig-fn &rest args)
3676+
"Prevent `balance-windows' from resizing chat windows.
3677+
Temporarily marks every live eca-chat buffer as fixed-size for
3678+
the duration of ORIG-FN, then clears it.
3679+
This lets `enlarge-window' and `shrink-window' still work."
3680+
(let (chat-bufs)
3681+
(dolist (buf (buffer-list))
3682+
(when (buffer-live-p buf)
3683+
(with-current-buffer buf
3684+
;; Only fix size for chat buffers shown in a side window.
3685+
(when (and (derived-mode-p 'eca-chat-mode) eca-chat-use-side-window)
3686+
(setq-local window-size-fixed
3687+
(if (memq eca-chat-window-side '(left right))
3688+
'width
3689+
'height))
3690+
(push buf chat-bufs)))))
3691+
(unwind-protect
3692+
(apply orig-fn args)
3693+
(dolist (buf chat-bufs)
3694+
(when (buffer-live-p buf)
3695+
(with-current-buffer buf
3696+
(setq-local window-size-fixed nil)))))))
3697+
3698+
(advice-add 'balance-windows :around #'eca-chat--balance-windows-advice)
3699+
36753700
(provide 'eca-chat)
36763701
;;; eca-chat.el ends here

0 commit comments

Comments
 (0)