Skip to content

fix: prevent balance-windows from resizing chat#220

Open
sata wants to merge 1 commit into
editor-code-assistant:masterfrom
sata:sata-fix-balance-window
Open

fix: prevent balance-windows from resizing chat#220
sata wants to merge 1 commit into
editor-code-assistant:masterfrom
sata:sata-fix-balance-window

Conversation

@sata
Copy link
Copy Markdown
Contributor

@sata sata commented Apr 13, 2026

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.

Addresses the issue raised with #205

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.
Comment thread eca-chat.el
(with-current-buffer buf
(setq-local window-size-fixed nil)))))))

(advice-add 'balance-windows :around #'eca-chat--balance-windows-advice)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sata I don't think adding a adivce in the top level is a good idea, we should add this adivice lazily in eca-chat-mode and remove it when buffer killed

Comment thread eca-chat.el
(dolist (buf chat-bufs)
(when (buffer-live-p buf)
(with-current-buffer buf
(setq-local window-size-fixed nil)))))))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 This unconditionally resets window-size-fixed to nil, which would stomp on any pre-existing value set by the user or another package. Consider saving the previous value before overwriting and restoring it here instead:

;; when collecting chat-bufs, save the old value:
(let ((old-val (buffer-local-value 'window-size-fixed buf)))
  (push (cons buf old-val) chat-bufs)
  ...)

;; in cleanup, restore it:
(setq-local window-size-fixed old-val)

Comment thread eca-chat.el
(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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 eca-chat-use-side-window is a global defcustom, not per-buffer state. If a user toggles it after a chat is already displayed as a side window, this check won't reflect reality. Consider checking the actual window parameter instead:

(when (and (derived-mode-p 'eca-chat-mode)
           (window-parameter (get-buffer-window buf) 'window-side))
  ...)

This way the advice protects exactly the windows that are side windows, regardless of the current setting.

Comment thread eca-chat.el
This lets `enlarge-window' and `shrink-window' still work."
(let (chat-bufs)
(dolist (buf (buffer-list))
(when (buffer-live-p buf)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Nit: this buffer-live-p check is redundant — buffer-list only returns live buffers. The one in the cleanup dolist below (line 3694) is the one that matters, since a buffer could theoretically be killed during balance-windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants