branch: elpa/gptel
commit 3f1026ecff8ebf1862af28d589d77231ead5cfa8
Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>

    gptel: Set prompt-end correctly when creating prompts
    
    * gptel.el (gptel--create-prompt): Set the prompt end correctly
    before parsing the buffer to create the prompt.  This fixes the
    error where Org buffers were scanned from the beginning up to the
    cursor instead of to a point specified to `gptel--create-prompt`.
---
 gptel.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gptel.el b/gptel.el
index e642c00cf6..9f947dd282 100644
--- a/gptel.el
+++ b/gptel.el
@@ -1130,6 +1130,7 @@ there."
     (save-restriction
       (let* ((max-entries (and gptel--num-messages-to-send
                                (* 2 gptel--num-messages-to-send)))
+             (prompt-end (or prompt-end (point-max)))
              (prompts
               (cond
                ((use-region-p)
@@ -1139,8 +1140,9 @@ there."
                 (gptel--parse-buffer gptel-backend max-entries))
                ((derived-mode-p 'org-mode)
                 (require 'gptel-org)
-                (gptel-org--create-prompt (or prompt-end (point-max))))
-               (t (goto-char (or prompt-end (point-max)))
+                (goto-char prompt-end)
+                (gptel-org--create-prompt prompt-end))
+               (t (goto-char prompt-end)
                   (gptel--parse-buffer gptel-backend max-entries)))))
         ;; Inject context chunks into the last user prompt if required
         ;; NOTE: prompts is modified in place

Reply via email to