Skip to content
Closed
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: 18 additions & 8 deletions eca-chat.el
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ Must be a positive integer."
(defmacro eca-chat--allow-write (&rest body)
"Execute BODY allowing write to buffer."
`(let ((inhibit-read-only t))
,@body))
(setq buffer-undo-list t)
,@body
(setq buffer-undo-list nil)))

(defmacro eca-chat--with-current-buffer (buffer &rest body)
"Eval BODY inside chat BUFFER."
Expand Down Expand Up @@ -581,15 +583,17 @@ Must be a positive integer."
(move-overlay context-area-ov (overlay-start context-area-ov) (1- (overlay-end context-area-ov))))
(let ((prompt-field-ov (make-overlay (line-beginning-position) (1+ (line-beginning-position)) (current-buffer))))
(overlay-put prompt-field-ov 'eca-chat-prompt-field t)
(overlay-put prompt-field-ov 'before-string (propertize eca-chat-prompt-prefix 'font-lock-face 'eca-chat-prompt-prefix-face))))
(overlay-put prompt-field-ov 'before-string (propertize eca-chat-prompt-prefix 'font-lock-face 'eca-chat-prompt-prefix-face)))
(setq buffer-undo-list t))

(defun eca-chat--clear ()
"Clear the chat for SESSION."
(erase-buffer)
(remove-overlays (point-min) (point-max))
(insert "\n")
(eca-chat--insert-prompt-string)
(eca-chat--refresh-context))
(eca-chat--refresh-context)
(setq buffer-undo-list nil))

(defun eca-chat--stop-prompt (session)
"Stop the running chat prompt for SESSION."
Expand All @@ -605,6 +609,7 @@ Otherwise to a not loading state."
(unless (eq eca-chat--chat-loading loading)
(setq-local eca-chat--chat-loading loading)
(setq-local buffer-read-only loading)
(setq buffer-undo-list t)
(let ((prompt-field-ov (eca-chat--prompt-field-ov))
(stop-text (eca-buttonize
eca-chat-mode-map
Expand All @@ -620,7 +625,8 @@ Otherwise to a not loading state."
(overlay-put prompt-field-ov 'before-string (propertize eca-chat-prompt-prefix 'font-lock-face 'eca-chat-prompt-prefix-face))
(save-excursion
(goto-char (overlay-start prompt-field-ov))
(delete-region (point) (+ (point) (length stop-text)))))))))
(delete-region (point) (+ (point) (length stop-text)))
(setq buffer-undo-list nil)))))))

(defun eca-chat--set-prompt (text)
"Set the chat prompt to be TEXT."
Expand Down Expand Up @@ -998,7 +1004,8 @@ Add a overlay before with OVERLAY-KEY = OVERLAY-VALUE if passed."
(when (eq overlay-key 'eca-chat--user-message-id)
(overlay-put ov 'eca-chat--timestamp (float-time)))))
(insert text)
(point))))
(point))
(setq buffer-undo-list nil)))

(defun eca-chat--expandable-content-at-point ()
"Return expandable content overlay at point, or nil if none."
Expand Down Expand Up @@ -1258,14 +1265,16 @@ If STATIC? return strs with no dynamic values."
(defun eca-chat--refresh-context ()
"Refresh chat context."
(save-excursion
(setq buffer-undo-list t)
(-some-> (eca-chat--prompt-context-field-ov)
(overlay-start)
(goto-char))
(delete-region (point) (line-end-position))
(seq-doseq (context eca-chat--context)
(insert (eca-chat--context->str context))
(insert " "))
(insert (propertize eca-chat-context-prefix 'font-lock-face 'eca-chat-context-unlinked-face))))
(insert (propertize eca-chat-context-prefix 'font-lock-face 'eca-chat-context-unlinked-face))
(setq buffer-undo-list nil)))

(defconst eca-chat--kind->symbol
'(("file" . file)
Expand Down Expand Up @@ -1562,7 +1571,7 @@ string."
(read-only-mode -1)
(setq-local eca-chat--history '())
(setq-local eca-chat--history-index -1)
(buffer-disable-undo)
(setq buffer-undo-list t)

;; Show diff blocks in markdown-mode with colors.
(setq-local markdown-fontify-code-blocks-natively t)
Expand Down Expand Up @@ -2036,7 +2045,8 @@ Calls CB with the resulting message."
(eca-chat--spinner-stop)
(eca-chat--add-text-content "\n")
(eca-chat--set-chat-loading session nil)
(eca-chat--refresh-progress chat-buffer))))
(eca-chat--refresh-progress chat-buffer)
(setq buffer-undo-list nil))))
("usage"
(setq-local eca-chat--message-input-tokens (plist-get content :messageInputTokens))
(setq-local eca-chat--message-output-tokens (plist-get content :messageOutputTokens))
Expand Down