Skip to content

Commit 4da9004

Browse files
authored
Merge pull request #259 from shohi/feat/chat-window-side
respect eca-chat-window-side for non-side-window chat display
2 parents 351e5aa + ffb580c commit 4da9004

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: `eca-chat-add-context-to-user-prompt` and `eca-chat-add-filepath-to-user-prompt` no longer error with `window-live-p, nil` when the chat buffer is not visible; the chat window is now displayed first. With a prefix arg (`C-u`) they add the context without selecting the chat window, leaving point where it was. #266
67
- Bugfix: don't move the cursor while the chat is streaming. `eca-chat-content-received` rendered without a `save-excursion`, so content streamed above the prompt (e.g. while "thinking") dragged point up to the middle of the buffer; point is now preserved.
78
- 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).

‎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

@@ -2685,30 +2689,42 @@ available, falling back to `string-width' on Emacsen without it."
26852689
(select-window window))))
26862690

26872691
(defun eca-chat--display-buffer (buffer)
2688-
"Display BUFFER in a side window according to customization.
2689-
The window is displayed on the side specified by
2690-
`eca-chat-window-side' with dimensions from
2691-
`eca-chat-window-width' or `eca-chat-window-height'.
2692+
"Display BUFFER according to customization.
2693+
BUFFER is displayed on the side given by `eca-chat-window-side'
2694+
with the size from `eca-chat-window-width' or
2695+
`eca-chat-window-height'. When `eca-chat-use-side-window' is
2696+
non-nil a dedicated side window is used, otherwise a regular
2697+
window in the same direction.
26922698
If `eca-chat-focus-on-open' is non-nil, the window is selected."
2693-
(let ((window
2694-
(if eca-chat-use-side-window
2695-
;; Use side window
2696-
(let* ((side eca-chat-window-side)
2697-
(slot 0)
2698-
(window-parameters '((no-delete-other-windows . t)))
2699-
(display-action
2700-
`((display-buffer-in-side-window)
2701-
(side . ,side)
2702-
(slot . ,slot)
2703-
(dedicated . side)
2704-
,@(when (memq side '(left right))
2705-
`((window-width . ,eca-chat-window-width)))
2706-
,@(when (memq side '(top bottom))
2707-
`((window-height . ,eca-chat-window-height)))
2708-
(window-parameters . ,window-parameters))))
2709-
(display-buffer buffer display-action))
2710-
;; Use regular buffer
2711-
(display-buffer buffer))))
2699+
(let* ((side eca-chat-window-side)
2700+
(size (if (memq side '(left right))
2701+
`((window-width . ,eca-chat-window-width))
2702+
`((window-height . ,eca-chat-window-height))))
2703+
(display-action
2704+
(if eca-chat-use-side-window
2705+
;; Dedicated side window.
2706+
`((display-buffer-in-side-window)
2707+
(side . ,side)
2708+
(slot . 0)
2709+
(dedicated . side)
2710+
,@size
2711+
(window-parameters . ((no-delete-other-windows . t))))
2712+
;; Regular window in the same direction.
2713+
`((display-buffer-in-direction)
2714+
(direction . ,(pcase side ('top 'above) ('bottom 'below) (_ side)))
2715+
,@size)))
2716+
(window
2717+
(or
2718+
;; Already visible: keep it where it is.
2719+
(get-buffer-window buffer)
2720+
;; Another chat is visible: replace it (new-tab behavior).
2721+
(when-let* ((win (get-window-with-predicate
2722+
(lambda (w)
2723+
(buffer-local-value 'eca-chat--id (window-buffer w))))))
2724+
(set-window-buffer win buffer)
2725+
win)
2726+
;; Nothing to reuse: open a new window.
2727+
(display-buffer buffer display-action))))
27122728
;; Select the window to give it focus if configured to do so
27132729
(when (and window eca-chat-focus-on-open)
27142730
(select-window window))

0 commit comments

Comments
 (0)