Skip to content

Commit 70e4201

Browse files
committed
Impls close afterward
1 parent 7810f86 commit 70e4201

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

chatgpt.el

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
(const :tag "Read inside new window" window))
6767
:group 'chatgpt)
6868

69+
(defcustom chatgpt-inhibit-input-afterward t
70+
"Stop input after sending one."
71+
:type 'boolean
72+
:group 'chatgpt)
73+
6974
(defconst chatgpt-buffer-name-format "*ChatGPT: <%s>*"
7075
"Name of the buffer to use for the `chatgpt' instance.")
7176

@@ -311,9 +316,14 @@ The data is consist of ROLE and CONTENT."
311316
(defvar chatgpt-input-instance nil
312317
"The current instance; there is only one instance at a time.")
313318

319+
(defun chatgpt-input-exit ()
320+
"Exit the input."
321+
(interactive)
322+
(chatgpt--kill-buffer chatgpt-input-buffer-name))
323+
314324
(defun chatgpt--start-input (instance)
315325
"Start input from INSTANCE."
316-
(chatgpt--kill-buffer chatgpt-input-buffer-name) ; singleton
326+
(chatgpt-input-exit)
317327
(let ((dir (if (window-parameter nil 'window-side)
318328
'bottom 'down))
319329
(buffer (get-buffer-create chatgpt-input-buffer-name)))
@@ -338,13 +348,15 @@ The data is consist of ROLE and CONTENT."
338348
((not (eq major-mode #'chatgpt-input-mode)) ) ; does nothing
339349
(chatgpt-requesting-p
340350
(message "[BUSY] Waiting for OpanAI to response..."))
351+
((region-active-p)
352+
(delete-region (region-beginning) (region-end)))
341353
(t
342-
(if (region-active-p)
343-
(delete-region (region-beginning) (region-end))
344-
(let ((response (buffer-string)))
345-
(chatgpt-with-instance chatgpt-input-instance
346-
(chatgpt-send-response response))
347-
(erase-buffer))))))
354+
(let ((response (buffer-string)))
355+
(chatgpt-with-instance chatgpt-input-instance
356+
(chatgpt-send-response response))
357+
(erase-buffer))
358+
(when chatgpt-inhibit-input-afterward
359+
(chatgpt-input-exit)))))
348360

349361
(defun chatgpt-input--post-command ()
350362
"Execution after input."

0 commit comments

Comments
 (0)