feat(ai): send quick explanation to *gptel* buffer instead of message
This commit is contained in:
@@ -156,14 +156,28 @@
|
|||||||
;;; ============================================================================
|
;;; ============================================================================
|
||||||
|
|
||||||
(defun my/gptel-quick-explain-region ()
|
(defun my/gptel-quick-explain-region ()
|
||||||
"Quickly explain selected code region."
|
"Quickly explain selected code region in the gptel buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(when (use-region-p)
|
(when (use-region-p)
|
||||||
(let ((code (buffer-substring-no-properties (region-beginning) (region-end))))
|
(let* ((code (buffer-substring-no-properties (region-beginning) (region-end)))
|
||||||
(gptel-request code
|
(buf (get-buffer-create "*gptel*")))
|
||||||
:system "Explain this code concisely in 2-3 sentences."
|
;; Prepare the buffer and insert the query immediately
|
||||||
|
(with-current-buffer buf
|
||||||
|
(goto-char (point-max))
|
||||||
|
(unless (derived-mode-p 'gptel-mode)
|
||||||
|
(funcall gptel-default-mode)
|
||||||
|
(gptel-mode 1))
|
||||||
|
(insert "\n\n--- Code to Explain ---\n\n" code "\n\n### Explanation Request Sent...\n"))
|
||||||
|
(display-buffer buf)
|
||||||
|
;; Send the request
|
||||||
|
(gptel-request
|
||||||
|
(format "Explain this code concisely in 2-3 sentences:\n\n%s" code)
|
||||||
|
:system "You are an expert programmer explaining code."
|
||||||
:callback (lambda (response info)
|
:callback (lambda (response info)
|
||||||
(message "Explanation: %s" response))))))
|
(with-current-buffer (get-buffer "*gptel*")
|
||||||
|
(goto-char (point-max))
|
||||||
|
(insert "\n### Code Explanation\n\n" response "\n\n"))
|
||||||
|
(message "Explanation received in *gptel* buffer."))))))
|
||||||
|
|
||||||
(defun my/gptel-proofread-region ()
|
(defun my/gptel-proofread-region ()
|
||||||
"Proofread and improve selected text."
|
"Proofread and improve selected text."
|
||||||
|
|||||||
Reference in New Issue
Block a user