emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/gptel a84461245e: gptel-context: Add a menu command to rem


From: ELPA Syncer
Subject: [nongnu] elpa/gptel a84461245e: gptel-context: Add a menu command to remove all context
Date: Thu, 28 Nov 2024 22:06:47 -0500 (EST)

branch: elpa/gptel
commit a84461245edb95372e7d8dedda7706525242047e
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>

    gptel-context: Add a menu command to remove all context
    
    * gptel-context.el (gptel-context-remove-all): Add a function to
    clear all context.  Requested in #486, #487.
    
    * gptel-transient.el (gptel-menu, gptel--infix-track-response,
    gptel--infix-context-remove-all): Add `gptel-menu' item and
    keybinding ("-d") to invoke `gptel-context-remove-all'.
---
 gptel-context.el   |  9 +++++++++
 gptel-transient.el | 15 ++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/gptel-context.el b/gptel-context.el
index a133dbe19c..bd3e3529f5 100644
--- a/gptel-context.el
+++ b/gptel-context.el
@@ -210,6 +210,15 @@ If selection is active, removes all contexts within 
selection."
     (when-let ((ctx (gptel-context--at-point)))
       (delete-overlay ctx)))))
 
+(defun gptel-context-remove-all ()
+  "Remove all gptel context."
+  (cl-loop
+   for (source . ovs) in gptel-context--alist
+   if (bufferp source) do               ;Buffers and buffer regions
+   (mapc #'gptel-context-remove ovs)
+   else do (gptel-context-remove source) ;files or other types
+   finally do (setq gptel-context--alist nil)))
+
 (defun gptel-context--make-overlay (start end &optional advance)
   "Highlight the region from START to END.
 
diff --git a/gptel-transient.el b/gptel-transient.el
index 10390466c8..d8a7aa849e 100644
--- a/gptel-transient.el
+++ b/gptel-transient.el
@@ -315,6 +315,7 @@ Also format its value in the Transient menu."
     (gptel--infix-context-add-region)
     (gptel--infix-context-add-buffer)
     (gptel--infix-context-add-file)
+    (gptel--infix-context-remove-all)
     (gptel--suffix-context-buffer)]]
   [["Request Parameters"
     :pad-keys t
@@ -624,7 +625,7 @@ querying the LLM."
   :set-value #'gptel--set-with-scope
   :display-if-true "Yes"
   :display-if-false "No"
-  :key "-d")
+  :key "-v")
 
 (transient-define-infix gptel--infix-track-media ()
   "Send media from \"standalone\" links in the prompt.
@@ -676,6 +677,7 @@ supports.  See `gptel-track-media' for more information."
   (transient-setup))
 
 (declare-function gptel-add-file "gptel-context")
+(declare-function gptel-context-remove-all "gptel-context")
 
 (transient-define-suffix gptel--infix-context-add-file ()
   "Add a file to gptel's context."
@@ -686,6 +688,17 @@ supports.  See `gptel-track-media' for more information."
   (call-interactively #'gptel-add-file)
   (transient-setup))
 
+(transient-define-suffix gptel--infix-context-remove-all ()
+  "Clear gptel's context."
+  :if (lambda () gptel-context--alist)
+  :transient 'transient--do-stay
+  :key "-d"
+  :description "Remove all"
+  (interactive)
+  (when (y-or-n-p "Remove all context? ")
+    (gptel-context-remove-all)
+    (transient-setup)))
+
 ;; ** Infix for the refactor/rewrite system message
 
 (transient-define-infix gptel--infix-add-directive ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]