Skip to content

Commit 4275350

Browse files
committed
gptel-context: Inspect buffer-local context correctly (#1091)
* gptel-context.el (gptel-context--collect, gptel-context--buffer-setup): Ensure that buffer-local `gptel-context' can be inspected correctly. This is done by passing the context-alist as an (optional) argument to `gptel-context--buffer-setup'. * gptel-transient.el (gptel--suffix-context-buffer): Adjust for new calling convention.
1 parent f47807f commit 4275350

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

gptel-context.el

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,15 @@ START and END signify the region delimiters."
441441
(overlays-at (point))))
442442

443443
;;;###autoload
444-
(defun gptel-context--collect ()
445-
"Get the list of all active context sources.
444+
(defun gptel-context--collect (&optional context-alist)
445+
"Get the list of all active context sources from CONTEXT-ALIST.
446+
447+
CONTEXT-ALIST defaults to the current value of `gptel-context'.
446448
447449
Ignore overlays, buffers and files that are not live or readable."
448450
;; Get only the non-degenerate overlays, collect them, and update the overlays variable.
449451
(let ((res))
450-
(dolist (entry gptel-context)
452+
(dolist (entry (or context-alist gptel-context))
451453
(pcase entry ;Context entry is:
452454
(`(,buf . ,ovs)
453455
(cond
@@ -556,8 +558,10 @@ context overlays, see `gptel-context'."
556558
nil t)
557559
(setq-local revert-buffer-function #'gptel-context--buffer-setup))
558560

559-
(defun gptel-context--buffer-setup (&optional _ignore-auto _noconfirm)
560-
"Set up the gptel context buffer."
561+
(defun gptel-context--buffer-setup (&optional _ignore-auto _noconfirm context-alist)
562+
"Set up the gptel context buffer.
563+
564+
CONTEXT-ALIST is the alist of contexts to use to populate the buffer."
561565
(with-current-buffer (get-buffer-create "*gptel-context*")
562566
(gptel-context-buffer-mode)
563567
(let ((inhibit-read-only t))
@@ -572,7 +576,7 @@ context overlays, see `gptel-context'."
572576
"\\[gptel-context-quit]: cancel, "
573577
"\\[quit-window]: quit")))
574578
(save-excursion
575-
(let ((contexts (gptel-context--collect)))
579+
(let ((contexts (gptel-context--collect context-alist)))
576580
(if (length= contexts 0)
577581
(insert "There are no active gptel contexts.")
578582
(let (beg ov l1 l2)

gptel-transient.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ whether the action is confirmed/cancelled."
19521952
:if (lambda () gptel-context)
19531953
:description "Inspect context"
19541954
(interactive)
1955-
(gptel-context--buffer-setup))
1955+
(gptel-context--buffer-setup nil nil gptel-context))
19561956

19571957
(provide 'gptel-transient)
19581958
;;; gptel-transient.el ends here

0 commit comments

Comments
 (0)