Function: gptel--handle-post-insert
gptel--handle-post-insert is a natively compiled function defined in
gptel.el.
Signature
(gptel--handle-post-insert FSM)
Documentation
Tasks after successfully inserting the LLM response with state FSM.
Indicate gptel status, pulse the inserted text and run post-response hooks.
No state transition here since that's handled by the process sentinels.
Source Code
;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel.el
(defun gptel--handle-post-insert (fsm)
"Tasks after successfully inserting the LLM response with state FSM.
Indicate gptel status, pulse the inserted text and run post-response hooks.
No state transition here since that's handled by the process sentinels."
(let* ((info (gptel-fsm-info fsm))
(start-marker (plist-get info :position))
(tracking-marker (or (plist-get info :tracking-marker)
start-marker))
;; start-marker may have been moved if :buffer was read-only
(gptel-buffer (marker-buffer start-marker)))
(with-current-buffer gptel-buffer
(if (not tracking-marker) ;Empty response
(when gptel-mode (gptel--update-status " Empty response" 'success))
(set-marker-insertion-type tracking-marker nil) ;Lock tracking-marker
(when gptel-mode
(unless (plist-get info :in-place)
(save-excursion (goto-char tracking-marker)
(insert gptel-response-separator
(gptel-prompt-prefix-string))))
(gptel--update-status " Ready" 'success)
(gptel--update-token-usage (plist-get info :tokens)
(plist-get info :tokens-full)))))
;; Run hook in visible window to set window-point, BUG #269
(if-let* ((gptel-window (get-buffer-window gptel-buffer 'visible)))
(with-selected-window gptel-window
(mapc (lambda (f) (funcall f info)) (plist-get info :post))
(run-hook-with-args
'gptel-post-response-functions
(marker-position start-marker) (marker-position tracking-marker)))
(with-current-buffer gptel-buffer
(mapc (lambda (f) (funcall f info)) (plist-get info :post))
(run-hook-with-args
'gptel-post-response-functions
(marker-position start-marker) (marker-position tracking-marker))))))