1

I want to customize the title of a transient group based on the value of some variable, my--current-section. The following doesn't work

(transient-define-prefix my--prefix ()
  "Sample docstring"
  `[,(format "Manage (current section: %s)" my--current-section)
   ("c" "Configure" my--configure)
   ("o" "Open" my--open)
   ("s" "Submit" my--submit)
  ])

IIUC because transient-define-prefix is a macro, and it doesn't eval its arguments. Neither using (eval ...) works. Is this possible?


EDIT: What I want is to have the title of the transient group contain a string. To do this, the usual (?) way is to provide the title as the first element of the vector passed to transient-define-prefix, say

(transient-define-prefix my--prefix ()
  "Sample docstring"
  `["Group title"
   ("c" "Configure" my--configure)
   ("o" "Open" my--open)
   ("s" "Submit" my--submit)
  ])

If I try to use, in place of the string, some elisp code, this doesn't get evaluated, and instead interpreted as a generic transient option. Therefore

(transient-define-prefix my--prefix ()
  "Sample docstring"
  [,(format "Manage (current section: %s)" my--current-section)
   ("c" "Configure" my--configure)
   ("o" "Open" my--open)
   ("s" "Submit" my--submit)
  ])

interprets the , as the character to use as key, so I get the error (error "No key for ,").

Using eval like this

(transient-define-prefix my--prefix ()
  "Sample docstring"
  [(eval
    (format "Manage (current section: %s)" my--current-section))
   ("c" "Configure" my--configure)
   ("o" "Open" my--open)
   ("s" "Submit" my--submit)
  ])

similarly, triggers (error "No key for eval").

Using backquoting

(transient-define-prefix my--prefix ()
  "Sample docstring"
  `[,(format "Manage (current section: %s)" my--current-section)
   ("c" "Configure" my--configure)
   ("o" "Open" my--open)
   ("s" "Submit" my--submit)
  ])

instead returns nil, and doesn't install the function.

  • 1
    Please say what you mean by "doesn't work", show what you tried with `eval`, etc. E.g., provide a recipe to reproduce the problem, saying what you see and what you expected to see instead. – Drew Dec 14 '22 at 23:36

1 Answers1

1

The following works:

(setq my--current-section "XXX")

(defun my--set-section ()
  (format "Manage (current section: %s)" my--current-section))

(transient-define-prefix my--prefix ()
  "Sample docstring"
  [:description my--set-section
    ("c" "Configure" (lambda () (interactive) nil))
    ("o" "Open" (lambda () (interactive) nil))
    ("s" "Submit" (lambda () (interactive) nil))
    ])

Or like this:

(setq my--current-section "Manage (current section: XXX)")

(transient-define-prefix my--prefix ()
  "Sample docstring"
  [ my--current-section
   ("c" "Configure" (lambda () (interactive) nil))
   ("o" "Open" (lambda () (interactive) nil))
   ("s" "Submit" (lambda () (interactive) nil))
   ])
orgtre
  • 1,012
  • 4
  • 15