Skip to content

Commit c5ffae2

Browse files
committed
gptel-org: Fix branching context prompt creation bug
* gptel-org.el (gptel-org--create-prompt): When using branching context, we always want to include text from (point-min) before the first headline, as we consider it part of the lineage of the org element that point is in. However, if there is a headline at (point-min), it should only be included if it's part of the lineage. This distinction was lost in the recent changes to branching context handling. Introduce it again. * test: Update with tests for the bug fixed in this commit.
1 parent 913e9db commit c5ffae2

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

gptel-org.el

+9-6
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,15 @@ value of `gptel-org-branching-context', which see."
226226
(org-element-at-point) #'gptel-org--element-begin
227227
'(headline) 'with-self) )
228228
;; lineage-map returns the full lineage in the unnarrowed
229-
;; buffer. Remove heading start positions at or before
230-
;; (point-min) that are invalid due to narrowing, and add
231-
;; (point-min) explicitly
232-
(start-bounds (nconc (cl-delete-if (lambda (p) (<= p (point-min)))
233-
full-bounds)
234-
(list (point-min))))
229+
;; buffer. Remove heading start positions before (point-min)
230+
;; that are invalid due to narrowing, and add (point-min) if
231+
;; it's not already included in the lineage
232+
(start-bounds
233+
(nconc (cl-delete-if (lambda (p) (< p (point-min)))
234+
full-bounds)
235+
(unless (save-excursion (goto-char (point-min))
236+
(looking-at-p outline-regexp))
237+
(list (point-min)))))
235238
(end-bounds
236239
(cl-loop
237240
;; (car start-bounds) is the begining of the current element,

0 commit comments

Comments
 (0)