I can define a custom option with:

(transient-define-infix my-option-infix ()
  :description "My Option"
  :class 'transient-option
  :shortarg "-o"
  :argument "--my-option=")

But how can I initialize the value depending of the current buffer ?



In the original code, the value of the :value keyword gets evaluated when the prefix is defined, so it sets the value to a fixed buffer.

To set the value at the moment of running the prefix, replace the :value keyword (line) in the prefix definition with the following line:

:init-value 'my-prefix-init

and define the my-prefix-init function as follows:

(defun my-prefix-init (obj)
  (oset obj value `(,(concat "--foo=" (buffer-name)))))


It is, not very clearly, described in this reddit post.

I guess this is best answered with an example. I have commented out the simple way of setting the value and replaced it by a backquote syntax method to show how to set the current buffer name:

(transient-define-prefix test ()
  ;; :value '("--foo=bar")
  :value `(,(concat "--foo=" (buffer-name)))
  [("p" "print value" print-essentials)])

(transient-define-infix test-option-infix ()
  :class 'transient-option
  :key "-f"
  :description "My option"
  :argument "--foo="
  :choices '("some-alt-value" "etc"))

You can retrieve the value directly from the infix-object as follows.

(defun print-essentials ()
  (pp (transient-args 'test))
  (pp (transient-arg-value "--foo=" (transient-args 'test))))

To read more about this solution I refer to the reddit post. And the documentation of EIEIO (as I am not very familiar with neither transient nor EIEIO).

  • Thanks a lot. It also works for multiple infix with a list as : value.
    – Balaïtous
    Jun 24 at 17:48
  • Thanks for the edit, I was facing to the problem. I will try to merge answer.
    – Balaïtous
    Jun 25 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.