Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions eca-chat.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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.

(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.

(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)))))))

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)


(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


(provide 'eca-chat)
;;; eca-chat.el ends here
Loading