Skip to content

Commit ec4e68d

Browse files
authored
Merge pull request #6 from r0man/tab-expand
Add TAB key support for expanding tool calls
2 parents e1a939f + 1159389 commit ec4e68d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

eca-chat.el

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ Must be a valid model supported by server, check `eca-chat-select-model`."
170170
(define-key map (kbd "C-k") #'eca-chat-clear)
171171
(define-key map (kbd "C-t") #'eca-chat-talk)
172172
(define-key map (kbd "<return>") #'eca-chat--key-pressed-return)
173+
(define-key map (kbd "<tab>") #'eca-chat--key-pressed-tab)
173174
map)
174175
"Keymap used by `eca-chat-mode'.")
175176

@@ -255,6 +256,13 @@ Must be a valid model supported by server, check `eca-chat-select-model`."
255256
(when (eq (line-beginning-position) (eca-chat--prompt-field-start-point))
256257
(insert "\n")))
257258

259+
(defun eca-chat--key-pressed-tab ()
260+
"Expand tool call if point is inside expandable content, otherwise use default tab behavior."
261+
(interactive)
262+
(if-let ((ov (eca-chat--expandable-content-at-point)))
263+
(eca-chat--expandable-content-toggle (overlay-get ov 'eca-chat--expandable-content-id))
264+
(call-interactively 'markdown-cycle)))
265+
258266
(defun eca-chat--prompt-field-start-point ()
259267
"Return the metadata overlay for the prompt field start point."
260268
(overlay-start
@@ -323,8 +331,7 @@ This is similar to `backward-delete-char' but protects the prompt/context line."
323331
(setq-local eca-chat--id (plist-get res :chatId)))))
324332

325333
;; check is inside a expandable text
326-
(when-let* ((ov (-first (-lambda (ov) (overlay-get ov 'eca-chat--expandable-content-id))
327-
(overlays-in (line-beginning-position) (point)))))
334+
(when-let* ((ov (eca-chat--expandable-content-at-point)))
328335
(eca-chat--expandable-content-toggle (overlay-get ov 'eca-chat--expandable-content-id)))))
329336

330337
(defun eca-chat--point-at-new-context-p ()
@@ -471,6 +478,11 @@ Applies LABEL-FACE to label and CONTENT-FACE to content."
471478
""
472479
key-vals))
473480

481+
(defun eca-chat--expandable-content-at-point ()
482+
"Return expandable content overlay at point, or nil if none."
483+
(-first (-lambda (ov) (overlay-get ov 'eca-chat--expandable-content-id))
484+
(overlays-in (line-beginning-position) (point))))
485+
474486
(defun eca-chat--expandable-content-toggle (id)
475487
"Toggle the expandable-content of ID."
476488
(when-let* ((ov (-first (-lambda (ov) (string= id (overlay-get ov 'eca-chat--expandable-content-id)))

0 commit comments

Comments
 (0)