Skip to content

Commit dbf41f9

Browse files
committed
respect eca-chat-window-side for non-side-window chat display
1 parent f91296c commit dbf41f9

3 files changed

Lines changed: 49 additions & 32 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- Respect `eca-chat-window-side` (and width/height) even when `eca-chat-use-side-window` is nil, displaying the chat on that side via `display-buffer-in-direction`. To avoid overlapping/duplicate windows, placement now reuses the window already showing the chat, otherwise replaces another visible chat window in place (new-tab behavior), and only opens a new window when there is nothing to reuse.
56
- Bugfix: keep the `:usage` and `:trust` mode-line segments visible after adding the context-usage bar. The right-alignment reserved space from `(length right)`, which counts the bar's pixel-width `display` spaces (and wide glyphs) as ~1 char each, so the segments overflowed off the right edge. It now measures the real rendered width via `string-pixel-width` and aligns flush to the right edge in pixels (Emacs 29+ only; on Emacs 28 right segments follow left without alignment).
67
- Bugfix: closing a chat (`kill-buffer`, `C-c C-k`, or the tab close button) now switches the chat window to a sibling chat (the previous tab, or the only one left) instead of falling back to an unrelated buffer like the settings buffer, and drops the dead chat from the session registry. `C-c C-k` (`eca-chat-reset`) only starts a fresh chat when the closed chat was the last one.
78
- Add `eca-chat-copy-at-point`, bound to `C-c C-w`. It copies the fenced code block at point, the assistant response at point, or the latest response as a fallback.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ Chat
134134
- `eca-chat-parent-mode`: Set major-mode of chat parent, can be `markdown-mode`, `markdown-view-mode` or `gfm-view-mode` (default)
135135
- `eca-chat-mode-hook`: Hooks to run after entering `eca-chat-mode`.
136136
- `eca-chat-finished-hook`: Hooks to run after finishing a chat prompt.
137-
- `eca-chat-use-side-window`: Whether the chat buffer is displayed in a side window or a normal window.
138-
- `eca-chat-window-side`: On which side (`left`, `right`, `top`, `bottom`) the chat side window appears.
139-
- `eca-chat-window-width`: Width of the chat side window when on the left or right.
140-
- `eca-chat-window-height`: Height of the chat side window when on the top or bottom.
137+
- `eca-chat-use-side-window`: Whether the chat buffer is displayed in a dedicated side window or a normal window. Either way it is placed on `eca-chat-window-side`.
138+
- `eca-chat-window-side`: On which side (`left`, `right`, `top`, `bottom`) the chat window appears (respected for both side and normal windows).
139+
- `eca-chat-window-width`: Width of the chat window when on the left or right.
140+
- `eca-chat-window-height`: Height of the chat window when on the top or bottom.
141141
- `eca-chat-focus-on-open`: Whether to focus the chat window when it opens.
142142
- `eca-chat-auto-add-repomap`: Whether to automatically include repoMap context when opening ECA.
143143
- `eca-chat-auto-add-cursor`: Whether to automatically track the cursor position and add it as context.

eca-chat.el

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ such as the Doom workspaces tabline to refresh external indicators.")
5757

5858
(defcustom eca-chat-window-side 'right
5959
"Side of the frame where the ECA chat window should appear.
60-
Can be `'left', `'right', `'top', or `'bottom'. This setting will only
61-
be used when `eca-chat-use-side-window' is non-nil."
60+
Can be `'left', `'right', `'top', or `'bottom'. This setting is respected
61+
both when `eca-chat-use-side-window' is non-nil (dedicated side window)
62+
and when it is nil (regular window displayed in the corresponding
63+
direction)."
6264
:type '(choice (const :tag "Left" left)
6365
(const :tag "Right" right)
6466
(const :tag "Top" top)
@@ -76,11 +78,13 @@ be used when `eca-chat-use-side-window' is non-nil."
7678
:group 'eca)
7779

7880
(defcustom eca-chat-use-side-window t
79-
"Whether to display ECA chat in a side window.
81+
"Whether to display ECA chat in a dedicated side window.
8082
When non-nil (default), ECA chat opens in a dedicated side window
8183
controlled by `eca-chat-window-side' and related settings. When nil,
82-
ECA chat opens in a regular buffer that follows standard
83-
`display-buffer' behavior."
84+
ECA chat opens in a regular window, still placed on the side given by
85+
`eca-chat-window-side' with the corresponding width/height, but without
86+
the side-window restrictions (so it can be split or replaced like any
87+
other window)."
8488
:type 'boolean
8589
:group 'eca)
8690

@@ -2642,30 +2646,42 @@ available, falling back to `string-width' on Emacsen without it."
26422646
(select-window (get-buffer-window (buffer-name))))
26432647

26442648
(defun eca-chat--display-buffer (buffer)
2645-
"Display BUFFER in a side window according to customization.
2646-
The window is displayed on the side specified by
2647-
`eca-chat-window-side' with dimensions from
2648-
`eca-chat-window-width' or `eca-chat-window-height'.
2649+
"Display BUFFER according to customization.
2650+
BUFFER is displayed on the side given by `eca-chat-window-side'
2651+
with the size from `eca-chat-window-width' or
2652+
`eca-chat-window-height'. When `eca-chat-use-side-window' is
2653+
non-nil a dedicated side window is used, otherwise a regular
2654+
window in the same direction.
26492655
If `eca-chat-focus-on-open' is non-nil, the window is selected."
2650-
(let ((window
2651-
(if eca-chat-use-side-window
2652-
;; Use side window
2653-
(let* ((side eca-chat-window-side)
2654-
(slot 0)
2655-
(window-parameters '((no-delete-other-windows . t)))
2656-
(display-action
2657-
`((display-buffer-in-side-window)
2658-
(side . ,side)
2659-
(slot . ,slot)
2660-
(dedicated . side)
2661-
,@(when (memq side '(left right))
2662-
`((window-width . ,eca-chat-window-width)))
2663-
,@(when (memq side '(top bottom))
2664-
`((window-height . ,eca-chat-window-height)))
2665-
(window-parameters . ,window-parameters))))
2666-
(display-buffer buffer display-action))
2667-
;; Use regular buffer
2668-
(display-buffer buffer))))
2656+
(let* ((side eca-chat-window-side)
2657+
(size (if (memq side '(left right))
2658+
`((window-width . ,eca-chat-window-width))
2659+
`((window-height . ,eca-chat-window-height))))
2660+
(display-action
2661+
(if eca-chat-use-side-window
2662+
;; Dedicated side window.
2663+
`((display-buffer-in-side-window)
2664+
(side . ,side)
2665+
(slot . 0)
2666+
(dedicated . side)
2667+
,@size
2668+
(window-parameters . ((no-delete-other-windows . t))))
2669+
;; Regular window in the same direction.
2670+
`((display-buffer-in-direction)
2671+
(direction . ,(pcase side ('top 'above) ('bottom 'below) (_ side)))
2672+
,@size)))
2673+
(window
2674+
(or
2675+
;; Already visible: keep it where it is.
2676+
(get-buffer-window buffer)
2677+
;; Another chat is visible: replace it (new-tab behavior).
2678+
(when-let* ((win (get-window-with-predicate
2679+
(lambda (w)
2680+
(buffer-local-value 'eca-chat--id (window-buffer w))))))
2681+
(set-window-buffer win buffer)
2682+
win)
2683+
;; Nothing to reuse: open a new window.
2684+
(display-buffer buffer display-action))))
26692685
;; Select the window to give it focus if configured to do so
26702686
(when (and window eca-chat-focus-on-open)
26712687
(select-window window))

0 commit comments

Comments
 (0)