-
I've long wanted to make a "universal" transient that allows me to activate shortcuts based on the things that are active in the current buffer. Yep, that sounds like context-transient, except multiple contexts can be active for a buffer at the same time (say, it could be both in rust-ts-mode and could be eglot-managed, as well as under git version control), which context-transient solves by prompting for the context's transient menu to show... I'd like instead to have a single transient menu with columns that get activated or deactivated based on the context. I thought something like the following could work: (defvar asf--transient-groups (make-hash-table))
(cl-defmacro asf-transient-define-group (name (&key major-mode) group)
`(setf (gethash ',name asf--transient-groups)
(lambda ()
(when (and ,@(when major-mode `((eq major-mode ,major-mode))))
',group))))
(defun asf--transient-setup-general-children (g)
(list
(eval (transient--parse-group
'asf-transient
`[:class transient-subgroups
,@(cl-loop for group-fn being the hash-values of asf--transient-groups
for maybe-group = (funcall group-fn)
if maybe-group collect maybe-group)]))
t))
(transient-define-prefix asf-transient ()
[[("q" "quit" transient-quit-all)]
[
:class transient-subgroups
:setup-children asf--transient-setup-general-children
;; content to compare with in the debugger:
["hi" ("b" "nothing" text-mode)]
["ho" ("d" "nothing 2" text-mode)]]])
(defun asf--cargo-process-doc ()
(interactive)
(let ((cargo-process--command-doc "+nightly doc"))
(cargo-process-doc)))
(defun asf--cargo-process-doc-open ()
(interactive)
(let ((cargo-process--command-doc-open "+nightly doc --open"))
(cargo-process-doc-open)))
(asf-transient-define-group rust-cargo (:major-mode 'rust-ts-mode)
["Cargo"
:class transient-column
("d" "doc" asf--cargo-process-doc)
("D" "doc --open" asf--cargo-process-doc-open)
("r" "run" cargo-process-run)]) But when invoking that transient in rust-ts-mode, I get the error ...or something else is wrong. So, how do I set things up such that I can have these dynamic columns? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
That's what the (transient-define-prefix demo ()
[["Rust"
:if-derived rust-ts-mode
("a" "A" transient-echo-arguments)
("b" "B" transient-echo-arguments)]
["Elisp"
:if-derived emacs-lisp-mode
("c" "C" transient-echo-arguments)
("d" "D" transient-echo-arguments)]
["Outline-Minor"
:if-non-nil outline-minor-mode
("c" "C" transient-echo-arguments)
("d" "D" transient-echo-arguments)]]) Instead of hiding the commands that are currently not useful, you can alternatively disable and dim them, by using, e.g., For an example for when it is appropriate and necessary to use |
Beta Was this translation helpful? Give feedback.
That too is possible without doing it dynamically: