-
Notifications
You must be signed in to change notification settings - Fork 51
fix: prevent balance-windows from resizing chat
#220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| (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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 (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))))))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 This unconditionally resets ;; 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 Nit: this
buffer-live-pcheck is redundant —buffer-listonly returns live buffers. The one in the cleanupdolistbelow (line 3694) is the one that matters, since a buffer could theoretically be killed duringbalance-windows.