Skip to content

Commit 2aa82cd

Browse files
author
xenodium
committed
Adds auto-transient menu display for compose buffer
1 parent fa89c18 commit 2aa82cd

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

chatgpt-shell-prompt-compose.el

+31-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
(require 'ring)
3333
(require 'flymake)
3434
(require 'shell-maker)
35+
(require 'transient)
3536

3637
(declare-function chatgpt-shell-previous-source-block "chatgpt-shell")
3738
(declare-function chatgpt-shell-next-source-block "chatgpt-shell")
@@ -50,6 +51,12 @@
5051
(declare-function chatgpt-shell--pretty-smerge-insert "chatgpt-shell")
5152
(declare-function chatgpt-shell-markdown-block-at-point "chatgpt-shell")
5253
(declare-function chatgpt-shell-view-block-at-point "chatgpt-shell")
54+
(declare-function chatgpt-shell-copy-block-at-point "chatgpt-shell")
55+
56+
(defcustom chatgpt-shell-compose-auto-transient t
57+
"When non-nil automatically display transient menu post compose submission."
58+
:type 'boolean
59+
:group 'chatgpt-shell)
5360

5461
(defvar-local chatgpt-shell-prompt-compose--exit-on-submit nil
5562
"Whether or not compose buffer should close after submission.
@@ -109,6 +116,27 @@ t if invoked from a transient frame (quitting closes the frame).")
109116
map)
110117
"Keymap for `chatgpt-shell-prompt-compose-view-mode'.")
111118

119+
(transient-define-prefix chatgpt-shell-prompt-compose-transient ()
120+
"ChatGPT Shell Compose Transient."
121+
[["Navigation"
122+
("n" "Next item" chatgpt-shell-prompt-compose-next-item :transient t)
123+
("p" "Previous item" chatgpt-shell-prompt-compose-previous-item :transient t)
124+
("f" "Next interaction" chatgpt-shell-prompt-compose-next-interaction :transient t)
125+
("b" "Previous interaction" chatgpt-shell-prompt-compose-previous-interaction :transient t)
126+
("o" "View other shell buffer" chatgpt-shell-prompt-compose-other-buffer)]
127+
["Prompts"
128+
("g" "Retry" chatgpt-shell-prompt-compose-retry)
129+
("r" "Reply with followup" chatgpt-shell-prompt-compose-reply)
130+
("m" "Request more" chatgpt-shell-prompt-compose-request-more)
131+
("e" "Request entire snippet" chatgpt-shell-prompt-compose-request-entire-snippet)]
132+
["Blocks"
133+
("v" "View block at point" chatgpt-shell-view-block-at-point)
134+
("i" "Insert block at point" chatgpt-shell-prompt-compose-insert-block-at-point)
135+
("w" "Copy block at point" chatgpt-shell-copy-block-at-point)
136+
("C-c C-c" "Execute block at point" chatgpt-shell-execute-block-action-at-point)]
137+
["Quit"
138+
("q" "Quit shell compose buffer" chatgpt-shell-prompt-compose-quit-and-close-frame)]])
139+
112140
(define-minor-mode chatgpt-shell-prompt-compose-view-mode
113141
"Like `view-mode`, but extended for ChatGPT Compose."
114142
:lighter " ChatGPT view"
@@ -366,7 +394,9 @@ Optionally set its PROMPT."
366394
(lambda (_input _output _success)
367395
(with-current-buffer (chatgpt-shell-prompt-compose-buffer)
368396
(let ((inhibit-read-only t))
369-
(chatgpt-shell--put-source-block-overlays))))
397+
(chatgpt-shell--put-source-block-overlays)))
398+
(when chatgpt-shell-compose-auto-transient
399+
(chatgpt-shell-prompt-compose-transient)))
370400
'inline))
371401
;; Point should go to beginning of response after submission.
372402
(goto-char (point-min))

chatgpt-shell.el

+11
Original file line numberDiff line numberDiff line change
@@ -2911,6 +2911,17 @@ For example \"elisp\" -> \"emacs-lisp\"."
29112911
:on-finished #'identity)
29122912
(user-error "No block at point")))
29132913

2914+
(defun chatgpt-shell-copy-block-at-point ()
2915+
"Copy code block at point to the kill ring."
2916+
(interactive)
2917+
(if-let ((block (chatgpt-shell-markdown-block-at-point)))
2918+
(let ((code (buffer-substring-no-properties
2919+
(map-elt block 'start)
2920+
(map-elt block 'end))))
2921+
(kill-new code)
2922+
(message "Copied block to kill ring"))
2923+
(user-error "No block at point")))
2924+
29142925
(cl-defun chatgpt-shell--view-code (&key edit language code on-finished)
29152926
"Open a temporary buffer for editing CODE in LANGUAGE major mode.
29162927
When done, invoke the FINISHED function with the resulting code.

0 commit comments

Comments
 (0)