Fix top-buffer snippets not being added

This commit is contained in:
daedsidog 2024-03-16 02:13:57 +02:00
parent 21b5a22c7e
commit 4e8b91670a

View file

@ -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 ;; We do not need to insert a line number indicator on
;; inline regions. ;; inline regions.
(unless (or region-inline region-continuous (unless (or region-inline region-continuous
(insert (format " (Line %d)" lineno)))) (insert (format " (Line %d)" lineno))))))
(setq is-top-snippet nil)) (if is-top-snippet
(if is-top-snippet (setq is-top-snippet nil)
(setq is-top-snippet nil) (when (and (not region-inline)
(when (and (not region-inline) (not region-continuous))
(not region-continuous)) (insert "\n")))
(insert "\n"))) (let (substring)
(let (substring) (with-current-buffer buffer
(with-current-buffer buffer (setq substring
(setq substring (if compress-code
(if compress-code (gptel--compress-code
(gptel--compress-code (buffer-substring start end)
(buffer-substring start end) major-mode)
major-mode) (buffer-substring start end))))
(buffer-substring start end)))) (let (ss-start ss-end)
(let (ss-start ss-end) (setq ss-start (point))
(setq ss-start (point)) (insert substring)
(insert substring) (setq ss-end (point))
(setq ss-end (point)) ;; Save the context as a text property, so
;; Save the context as a text property, so ;; that we may later be able to delete the
;; that we may later be able to delete the ;; context snippet from the context buffer.
;; context snippet from the context buffer. (put-text-property
(put-text-property ss-start ss-end
ss-start ss-end 'gptel--context
'gptel--context (cons buffer
(cons buffer (list
(list (list start end)))))))
(list start end))))))) (setq previous-region (cons start end))))
(setq previous-region (cons start end)))))
(unless (= (cl-second (car (last regions))) buffer-point-max) (unless (= (cl-second (car (last regions))) buffer-point-max)
(insert "\n...")) (insert "\n..."))
(insert "\n```")) (insert "\n```"))