gptel: Add post-response hook and fix org converter
* gptel.el (gptel--convert-playback-markdown->org, gptel-post-response-hook): Add a hook that runs after the response is received. This will allow for custom actions like moving the cursor to the next prompt. The markdown->org stream converter now cleans up after itself using this hook.
This commit is contained in:
parent
c9795fe9e8
commit
c22c59d20a
1 changed files with 23 additions and 4 deletions
25
gptel.el
25
gptel.el
|
@ -104,6 +104,14 @@ return the transformed string."
|
|||
:group 'gptel
|
||||
:type 'hook)
|
||||
|
||||
(defcustom gptel-post-response-hook nil
|
||||
"Hook run after inserting ChatGPT's response into the current buffer.
|
||||
|
||||
This hook is called in the buffer from which the prompt was sent
|
||||
to ChatGPT. Note: this hook runs even if the request fails."
|
||||
:group 'gptel
|
||||
:type 'hook)
|
||||
|
||||
(defvar gptel-default-session "*ChatGPT*")
|
||||
(defvar gptel-default-mode (if (featurep 'markdown-mode)
|
||||
'markdown-mode
|
||||
|
@ -551,10 +559,21 @@ elements."
|
|||
(buffer-string)))
|
||||
|
||||
(defun gptel--convert-playback-markdown->org ()
|
||||
""
|
||||
(let ((in-src-block)
|
||||
"Return a Markdown to Org converter.
|
||||
|
||||
This function parses a stream of Markdown text to Org
|
||||
continuously when it is called with successive chunks of the
|
||||
text stream."
|
||||
(letrec ((in-src-block)
|
||||
(temp-buf (generate-new-buffer-name "*gptel-temp*"))
|
||||
(start-pt (make-marker)))
|
||||
(start-pt (make-marker))
|
||||
(cleanup-fn
|
||||
(lambda ()
|
||||
(when (buffer-live-p (get-buffer temp-buf))
|
||||
(set-marker start-pt nil)
|
||||
(kill-buffer temp-buf))
|
||||
(remove-hook 'gptel-post-response-hook cleanup-fn))))
|
||||
(add-hook 'gptel-post-response-hook cleanup-fn)
|
||||
(lambda (str)
|
||||
(let ((noop-p))
|
||||
(with-current-buffer (get-buffer-create temp-buf)
|
||||
|
|
Loading…
Add table
Reference in a new issue