branch: elpa/gptel
commit 26bd253a0b099aa78c8bc0840bb7c04ab4eeef5a
Author: Karthik Chikmagalur <[email protected]>
Commit: Karthik Chikmagalur <[email protected]>
gptel-context: Fix context-buffer for new context spec
* gptel-context.el (gptel-context--insert-buffer-string): Fix bug
with nconc-ing nil.
(gptel-context--buffer-setup): Fix for `gptel-context's plist
spec. Only `:overlays' is handled so far, bounds/line ranges in
files/buffers are ignored. This needs to be fixed in the future.
* gptel-transient.el (gptel--describe-infix-context): Fix the
context chunk count for `gptel-context's new plist spec. Only
`:overlays' is handled so far, bounds/line ranges are ingored.
This needs to be fixed as well.
---
gptel-context.el | 14 ++++++++------
gptel-transient.el | 7 +++++--
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/gptel-context.el b/gptel-context.el
index ca460e4b45c..fb47a4cd8f2 100644
--- a/gptel-context.el
+++ b/gptel-context.el
@@ -507,8 +507,8 @@ HEADER is an optional header to insert before the contents."
;; Collect bounds (already in position format)
(when-let* ((bounds (plist-get context-data :bounds)))
(if (consp (car bounds))
- (nconc regions bounds) ;((start1 . end1) (start2 . end2) ...)
- (push bounds regions))) ;(start1 . end1)
+ (setq regions (nconc regions bounds)) ;((start1 . end1) (start2
. end2) ...)
+ (push bounds regions))) ;(start1 . end1)
;; Collect lines (convert line numbers to positions)
(when-let* ((line-bounds (plist-get context-data :lines)))
;; Convert singleton (start1 . end1) to ((start1 . end1))
@@ -618,6 +618,8 @@ context overlays, see `gptel-context'."
nil t)
(setq-local revert-buffer-function #'gptel-context--buffer-setup))
+;; FIXME(targeted-context): This does not handle :bounds and :lines. Reuse
+;; `gptel-context--insert-buffer-string'?
(defun gptel-context--buffer-setup (&optional _ignore-auto _noconfirm
context-alist)
"Set up the gptel context buffer.
@@ -640,10 +642,10 @@ CONTEXT-ALIST is the alist of contexts to use to populate
the buffer."
(if (length= contexts 0)
(insert "There are no active gptel contexts.")
(let (beg ov l1 l2)
- (pcase-dolist (`(,buf . ,ovs) contexts)
+ (pcase-dolist (`(,buf . ,spec) contexts)
(cond
((bufferp buf)
- (if (not ovs) ;BUF is a full buffer, not specific
overlays
+ (if (not spec) ;BUF is a full buffer, not specific
ranges
(progn
(insert (propertize (format "In buffer %s:\n\n"
(buffer-name buf))
@@ -652,7 +654,7 @@ CONTEXT-ALIST is the alist of contexts to use to populate
the buffer."
(insert-buffer-substring buf)
(insert "\n")
(setq ov (make-overlay beg (point))))
- (dolist (source-ov ovs) ;BUF is a buffer with some
overlay(s)
+ (dolist (source-ov (plist-get spec :overlays)) ;BUF is a
buffer with some overlay(s)
(with-current-buffer buf
(setq l1 (line-number-at-pos (overlay-start source-ov))
l2 (line-number-at-pos (overlay-end source-ov))))
@@ -672,7 +674,7 @@ CONTEXT-ALIST is the alist of contexts to use to populate
the buffer."
(insert (propertize (format "In file %s:\n\n"
(file-name-nondirectory buf))
'face 'bold))
(setq beg (point))
- (if-let* ((mime (plist-get ovs :mime))
+ (if-let* ((mime (plist-get spec :mime))
((not (string-match-p "^text/" mime)))) ;BUF is a
binary file
(if-let* (((string-match-p (image-file-name-regexp) buf))
(img (create-image buf)))
diff --git a/gptel-transient.el b/gptel-transient.el
index 4664d1c8e9e..3daf1963da7 100644
--- a/gptel-transient.el
+++ b/gptel-transient.el
@@ -393,16 +393,19 @@ which see."
(forward-line 1)))))
gptel--crowdsourced-prompts))
+;; FIXME(targeted-context): This does not handle :bounds and :lines.
(defun gptel--describe-infix-context ()
+ "Return a count of the number of context chunks."
(if (null gptel-context) "Context"
(pcase-let*
((buffer-count (length gptel-context))
(`(,file-count ,ov-count)
(if (> buffer-count 0)
(cl-loop for entry in gptel-context
- for (buf-file . ovs) = (ensure-list entry)
+ for (buf-file . spec) = (ensure-list entry)
if (bufferp buf-file)
- sum (if ovs (length ovs) 1) into ov-count
+ sum (max (length (plist-get spec :overlays)) 1)
+ into ov-count
else count (stringp buf-file) into file-count
finally return (list file-count ov-count))
(list 0 0))))