gptel: Check header-line-format before updating

gptel.el: A header-line is not required for using `gptel-send'. gptel
can now be used from any buffer by selecting a region.
This commit is contained in:
Karthik Chikmagalur 2023-03-09 14:14:06 -08:00
parent 3f7c81012b
commit f98293f004

View file

@ -114,8 +114,9 @@ When set to nil, it is inserted all at once.
(if (and arg (featurep 'gptel-transient))
(call-interactively #'gptel-send-menu)
(message "Querying ChatGPT...")
(and header-line-format
(setf (nth 1 header-line-format)
(propertize " Waiting..." 'face 'warning))
(propertize " Waiting..." 'face 'warning)))
(let* ((gptel-buffer (current-buffer))
(full-prompt (gptel--create-prompt))
(response (aio-await
@ -142,9 +143,10 @@ When set to nil, it is inserted all at once.
(unless gptel-playback
(setf (nth 1 header-line-format)
(propertize " Ready" 'face 'success)))))
(and header-line-format
(setf (nth 1 header-line-format)
(propertize (format " Response Error: %s" status-str)
'face 'error))))))
'face 'error)))))))
(defun gptel--create-prompt ()
"Return a full conversation prompt from the contents of this buffer.
@ -305,9 +307,10 @@ Begin at START-PT."
(min content-length (+ idx 16))))
(setq idx (+ idx 16)))
(when start-pt (goto-char (- start-pt 2)))
(and header-line-format
(setf (nth 1 header-line-format)
(propertize " Ready" 'face 'success))
(force-mode-line-update)
(force-mode-line-update))
(accept-change-group (symbol-value handle))
(undo-amalgamate-change-group (symbol-value handle))
(cancel-timer (symbol-value playback-timer)))))))