0
  • I use transient.el
  • Press key a but (insert "B") is executed
;; NG case
;; desc is same
;; press a -> B
(progn
  (transient-define-prefix my-test1 ()
    [("a" "desc" (lambda () (interactive) (insert "A")))
     ("b" "desc" (lambda () (interactive) (insert "B")))])
  (my-test1))

;; OK
;; desc is unique
;; press a -> A
(progn
  (transient-define-prefix my-test1 ()
    [("a" "desc_a" (lambda () (interactive) (insert "A")))
     ("b" "desc_b" (lambda () (interactive) (insert "B")))])
  (my-test1))

;; OK
;; desc is same and lamda not use
;; press a -> A
(progn
  (defun insert-A () (interactive) (insert "A"))
  (defun insert-B () (interactive) (insert "B"))
  (transient-define-prefix my-test1 ()
    [("a" "desc" insert-A)
     ("b" "desc" insert-B)])
  (my-test1))

Why?

This case, Desc may be the same because distinguished by category.

(progn
  (transient-define-prefix my-test1 ()
    ["Ruby" ("a" "Test" (lambda () (interactive) (insert "A")))]
    ["Rust" ("b" "Test" (lambda () (interactive) (insert "B")))])
  (my-test1))
JeanPierre
  • 7,323
  • 1
  • 18
  • 37
megeton
  • 27
  • 4

1 Answers1

1

EDIT (in response to change in question)

With transient its current design, there is no other good way than just naming the commands yourself (like in your third example). Fixing it requires changes to the transient code (currently transient--parse-suffix does not even 'receive' the category via its arguments). However, fixing it for yourself would be very easy, you could exchange the arguments in

(or (plist-get args :description)
    (plist-get args :key))

in the transient--parse-suffix definition (so :key comes before :description), but this would only be a local fix that works for you personally only (you could even create a PR with this fix, and explain that 'descriptions' could be 'non-unique').

END EDIT

If you place your cursor right after the transient-define-prefix and do pp-macroexpand-last-sexp, then you'll find that transient actually assigns names to the anonymous functions and uses the named commands for the suffixes;. You will also find that transient uses the name of the prefix and the description to construct the command names. Because all your suffixes have the same description, all commands get the same name and the last assignment overwrites the earlier assignments .

If you dig a little deeper into the code of the transient-define-prefix macro, then you will find that the names are constructed using the transient--parse-suffixfunction.

I am not that familiar with the transient package that I know why it is designed like this, but I would say this explanation somewhat answers your question.

dalanicolai
  • 6,108
  • 7
  • 23