fix: prevent balance-windows from resizing chat#220
Conversation
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.
| (with-current-buffer buf | ||
| (setq-local window-size-fixed nil))))))) | ||
|
|
||
| (advice-add 'balance-windows :around #'eca-chat--balance-windows-advice) |
There was a problem hiding this comment.
@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
| (dolist (buf chat-bufs) | ||
| (when (buffer-live-p buf) | ||
| (with-current-buffer buf | ||
| (setq-local window-size-fixed nil))))))) |
There was a problem hiding this comment.
🟡 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)| (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) |
There was a problem hiding this comment.
🟡 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.
| This lets `enlarge-window' and `shrink-window' still work." | ||
| (let (chat-bufs) | ||
| (dolist (buf (buffer-list)) | ||
| (when (buffer-live-p buf) |
There was a problem hiding this comment.
🟢 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.
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