Skip to content

Converting popup modifications to transient modifications

hokomo edited this page Sep 13, 2022 · 11 revisions

Transient comes with a manual

It is available inside Emacs and here.

The sections that are most relevant to what is being discussed here are

Suffix specifications are quite flexible, which results in the documentation being a bit complicated. The below examples should make it possible for you to convert your customizations from Magit-Popup to Transient without having to understand all that.

You might not have to write any code

It is possible that you can remove the code that implements your Magit-Popup customizations without having to replace it with any code that customizes Transient.

This is likely the case if you got your customizations from Additional proposed infix arguments and suffix commands.

In that case remove your customizations. And then invoke the transient command that you wish had more infix arguments and/or suffix commands. Then type C-x l to enter "edit mode".

You will likely see the thing that you want to be available now. But it is prefixed with a red number, unlike the commands that are usually shown, which are prefixed by a green number.

Type the key that would normally invoke that command. Since we are in edit mode this does not actually invoke it. Instead you are asked to enter a number. Enter 4. That number should now appear in front of the key binding and it should be green.

Type C-g to exit edit mode. The command should be available now.

This is documented in more detail in Enabling and Disabling Suffixes.

The "popup commands" have been renamed

The commands formerly known as "popups" or "popup commands" are now called "transients" or "transient prefix commands" and they have been renamed. Previously they were named magit-SOMETHING-popup and now they are named just magit-SOMETHING.

Adding and modifying bindings

One thing to note is that you previously did not have to specify where a new command is supposed to be inserted. If you left out that information, then it was inserted at the end. Now you have to specify where to insert the new command, relative to some existing binding.

If you haven't done so yet, then you might want to read Modifying-Existing-Transients now.

You might also want to look at the changes Kyle (one of the maintainers) had to make to his configuration. That should give you quite a few examples.

Changing a key binding

magit-popup

(magit-change-popup-key 'magit-branch-popup :action ?c ?o)
(magit-change-popup-key 'magit-branch-popup :switch ?f ?F)

transient

(transient-suffix-put 'magit-branch "c" :key "o")
(transient-suffix-put 'magit-branch "-f" :key "-F")

Adding an action

magit-popup

(magit-define-popup-action 'magit-log-popup
  ?w "Wip" 'magit-wip-log-current)

transient

(transient-append-suffix 'magit-log "a"
  '("w" "Wip" magit-wip-log-current))

Adding a switch

magit-popup

(magit-define-popup-switch 'magit-log-popup
  ?1 "First parent" "--first-parent")

transient

(transient-append-suffix 'magit-log "-A"
  '("-1" "First parent" "--first-parent"))

Adding an option

magit-popup

(magit-define-popup-option 'magit-log-popup
  ?s "Since date" "--since=" #'magit-org-read-date)

transient

(transient-append-suffix 'magit-log "-A"
  '("=s" "Since date" "--since=" magit-org-read-date))

Note that the bindings for options no longer have to begin with "=". We use that here anyway because "-s" is already bound to another argument.