From 4e8b91670a940d9ec6eb8ff8fb7518e1d6b1f49b Mon Sep 17 00:00:00 2001 From: daedsidog <41439659+daedsidog@users.noreply.github.com> Date: Sat, 16 Mar 2024 02:13:57 +0200 Subject: [PATCH] Fix top-buffer snippets not being added --- gptel-contexter.el | 57 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/gptel-contexter.el b/gptel-contexter.el index 94ae3cc..3c7ffc2 100644 --- a/gptel-contexter.el +++ b/gptel-contexter.el @@ -409,35 +409,34 @@ REGIONS is a list of pairs of (start, end) lists." ;; We do not need to insert a line number indicator on ;; inline regions. (unless (or region-inline region-continuous - (insert (format " (Line %d)" lineno)))) - (setq is-top-snippet nil)) - (if is-top-snippet - (setq is-top-snippet nil) - (when (and (not region-inline) - (not region-continuous)) - (insert "\n"))) - (let (substring) - (with-current-buffer buffer - (setq substring - (if compress-code - (gptel--compress-code - (buffer-substring start end) - major-mode) - (buffer-substring start end)))) - (let (ss-start ss-end) - (setq ss-start (point)) - (insert substring) - (setq ss-end (point)) - ;; Save the context as a text property, so - ;; that we may later be able to delete the - ;; context snippet from the context buffer. - (put-text-property - ss-start ss-end - 'gptel--context - (cons buffer - (list - (list start end))))))) - (setq previous-region (cons start end))))) + (insert (format " (Line %d)" lineno)))))) + (if is-top-snippet + (setq is-top-snippet nil) + (when (and (not region-inline) + (not region-continuous)) + (insert "\n"))) + (let (substring) + (with-current-buffer buffer + (setq substring + (if compress-code + (gptel--compress-code + (buffer-substring start end) + major-mode) + (buffer-substring start end)))) + (let (ss-start ss-end) + (setq ss-start (point)) + (insert substring) + (setq ss-end (point)) + ;; Save the context as a text property, so + ;; that we may later be able to delete the + ;; context snippet from the context buffer. + (put-text-property + ss-start ss-end + 'gptel--context + (cons buffer + (list + (list start end))))))) + (setq previous-region (cons start end)))) (unless (= (cl-second (car (last regions))) buffer-point-max) (insert "\n...")) (insert "\n```"))