Skip to content
Merged
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
26 changes: 23 additions & 3 deletions eca-chat.el
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,18 @@ If `eca-chat-focus-on-open' is non-nil, the window is selected."
(goto-char eca-chat--last-user-message-pos)
(eca-chat--insert content))))

(defun eca-chat--align-tables ()
"Align all markdown tables in the chat content area."
(save-excursion
(goto-char (or eca-chat--last-user-message-pos (point-min)))
(let ((end (eca-chat--prompt-area-start-point)))
(while (and (< (point) end)
(re-search-forward markdown-table-line-regexp end t))
(when (markdown-table-at-point-p)
(markdown-table-align)
;; Move past this table to avoid re-processing
(goto-char (markdown-table-end)))))))

(defun eca-chat--add-text-content (text &optional overlay-key overlay-value)
"Add TEXT to the chat current position.
Add a overlay before with OVERLAY-KEY = OVERLAY-VALUE if passed."
Expand Down Expand Up @@ -1788,7 +1800,10 @@ Call ORIG-FUN with ARGS if not media."
"Major mode for ECA chat sessions.
\\{eca-chat-mode-map}"
:group 'eca
(visual-line-mode)
;; Use word-wrap instead of visual-line-mode to preserve table formatting.
;; visual-line-mode wraps all lines including tables, breaking their layout.
(setq-local word-wrap t)
(setq-local truncate-lines nil)
(hl-line-mode -1)
(setq-local eca-chat--history '())
(setq-local eca-chat--history-index -1)
Expand Down Expand Up @@ -1869,6 +1884,10 @@ Call ORIG-FUN with ARGS if not media."
(face-remap-add-relative 'markdown-line-break-face
'(:underline nil))

;; Ensure tables use a monospace font for proper alignment.
(face-remap-add-relative 'markdown-table-face
'(:inherit fixed-pitch))

(goto-char (point-max)))

(defun eca-chat-eldoc-function (cb &rest _ignored)
Expand Down Expand Up @@ -2091,8 +2110,8 @@ Append STATUS, TOOL-CALL-NEXT-LINE-SPACING and ROOTS"
'font-lock-face 'eca-chat-system-messages-face
'line-height 20)))
(_
(eca-chat--add-text-content text))))
(setq-local eca-chat--empty nil))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why removed this, but I believe it's not being used anymore, so it's safe to remove this variable

(eca-chat--add-text-content text)
(font-lock-ensure)))))
("url"
(eca-chat--add-header
(concat "🌐 "
Expand Down Expand Up @@ -2284,6 +2303,7 @@ Append STATUS, TOOL-CALL-NEXT-LINE-SPACING and ROOTS"
(setq-local eca-chat--progress-text "")
(eca-chat--spinner-stop)
(eca-chat--add-text-content "\n")
(eca-chat--align-tables)
(eca-chat--set-chat-loading session nil)
(eca-chat--refresh-progress chat-buffer)
(eca-chat--send-queued-prompt session))))
Expand Down