Skip to content

Commit e71763d

Browse files
committed
Toggle all tools key setting
Adds 'a' switch to toggle all tools at once Moves the other switches to come from the range b-z I have 50-odd tools with mcp servers active, across several categories. Even with the category toggles, it was a bit of a bother activating all my tools. Claude wrote thisÉ
1 parent 5b21ef9 commit e71763d

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

gptel-transient.el

+24-2
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,26 @@ Customize `gptel-directives' for task-specific prompts."
752752
:pad-keys t])
753753

754754
;; ** Prefix for selecting tools
755+
(defun gptel--toggle-all-tools ()
756+
"Toggle the selection state of all tools in the transient menu.
755757
758+
If any tool is currently selected, deselect all tools.
759+
If no tools are selected, select all tools."
760+
(interactive)
761+
(let ((all-selected t)
762+
(has-tools nil))
763+
;; Check if any tools are not selected
764+
(dolist (suffix transient-current-suffixes)
765+
(when (cl-typep suffix 'gptel--switch)
766+
(setq has-tools t)
767+
(when (null (oref suffix value))
768+
(setq all-selected nil))))
769+
;; If we have tools but not all are selected, select all; otherwise deselect all
770+
(when has-tools
771+
(dolist (suffix transient-current-suffixes)
772+
(when (cl-typep suffix 'gptel--switch)
773+
(transient-infix-set suffix (unless all-selected (oref suffix argument))))))
774+
(transient--redisplay)))
756775
;;;###autoload (autoload 'gptel-tools "gptel-transient" nil t)
757776
(transient-define-prefix gptel-tools ()
758777
"Select tools to include with gptel requests.
@@ -785,6 +804,9 @@ only (\"oneshot\")."
785804
(cl-delete-if-not #'consp args))
786805
gptel--set-buffer-locally))
787806
:transient transient--do-return)
807+
("a" "Toggle all tools" gptel--toggle-all-tools
808+
:transient t)
809+
788810
("q" "Cancel" transient-quit-one)]]
789811
[:class transient-column
790812
:setup-children
@@ -794,14 +816,14 @@ only (\"oneshot\")."
794816
(cdr
795817
(cl-loop ;loop through gptel--known tools and collect categories
796818
for (category . tools-alist) in gptel--known-tools
797-
with unused-keys = (delete ?q (number-sequence ?a ?z))
819+
with unused-keys = (delete ?q (number-sequence ?b ?z))
798820
for category-key = (seq-find (lambda (k) (member k unused-keys)) category
799821
(seq-first unused-keys))
800822
do (setq unused-keys (delete category-key unused-keys))
801823
nconc
802824
(cl-loop ;for each category, collect tools as infixes
803825
for (name . tool) in tools-alist
804-
with tool-keys = (delete category-key (number-sequence ?a ?z))
826+
with tool-keys = (delete category-key (number-sequence ?b ?z))
805827
for tool-key = (seq-find (lambda (k) (member k tool-keys)) name
806828
(seq-first tool-keys))
807829
do (setq tool-keys (delete tool-key tool-keys))

0 commit comments

Comments
 (0)