Skip to content

Comparison with other packages

Jonas Bernoulli edited this page Oct 28, 2023 · 1 revision

Magit-Popup

Transient is the successor to Magit-Popup.

One major difference between these two implementations of the same ideas is that while Transient uses transient keymaps and embraces the command-loop, Magit-Popup implemented an inferior mechanism that does not use transient keymaps and that instead of using the command-loop implements a naive alternative based on read-char.

Magit-Popup does not use classes and generic functions and defining a new command type is near impossible as it involves adding hard-coded special-cases to many functions. Because of that only a single new type was added, which was not already part of Magit-Popup’s initial release.

A lot of things are hard-coded in Magit-Popup. One random example is that the key bindings for switches must begin with - and those for options must begin with =.

Hydra

Hydra is another package that provides features similar to those of Transient.

Both packages use transient keymaps to make a set of commands temporarily available and show the available commands in a popup buffer.

A Hydra “body” is equivalent to a Transient “prefix” and a Hydra “head” is equivalent to a Transient “suffix”. Hydra has no equivalent of a Transient “infix”.

Both hydras and transients can be used as simple command dispatchers. Used like this they are similar to regular prefix commands and prefix keys, except that the available commands are shown in the popup buffer.

(Another package that does this is Which-Key. It does so automatically for any incomplete key sequence. The advantage of that approach is that no additional work is necessary; the disadvantage is that the available commands are not organized semantically.)

Both Hydra and Transient provide features that go beyond simple command dispatchers:

  • Invoking a command from a hydra does not necessarily exit the hydra. That makes it possible to invoke the same command again, but using a shorter key sequence (i.e., the key that was used to enter the hydra does not have to be pressed again).

    Transient supports that too, but for now this feature is not a focus and the interface is a bit more complicated. A very basic example using the current interface:

    (transient-define-prefix outline-navigate ()
      :transient-suffix     'transient--do-stay
      :transient-non-suffix 'transient--do-warn
      [("p" "previous visible heading" outline-previous-visible-heading)
       ("n" "next visible heading" outline-next-visible-heading)])
        
  • Transient supports infix arguments; values that are set by infix commands and then consumed by the invoked suffix command(s).

    To my knowledge, Hydra does not support that.

Both packages make it possible to specify how exactly the available commands are outlined:

  • With Hydra this is often done using an explicit format string, which gives authors a lot of flexibility and makes it possible to do fancy things.

    The downside of this is that it becomes harder for a user to add additional commands to an existing hydra and to change key bindings.

  • Transient allows the author of a transient to organize the commands into groups and the use of generic functions allows authors of transients to control exactly how a certain command type is displayed.

    However while Transient supports giving sections a heading it does not currently support giving the displayed information more structure by, for example, using box-drawing characters.

    That could be implemented by defining a new group class, which lets the author specify a format string. It should be possible to implement that without modifying any existing code, but it does not currently exist.

Clone this wiki locally