Previous: , Up: Top   [Contents]


3 Defining Prefix and Suffix Commands

If you write an extension for Magit then you should use this library now and later when transient is released port to that.

If you are considering using this library to define popups for packages not related to Magit, then keep in mind that it will be superseded eventually. Once transient has been released I will only fix bugs in magit-popup but not implement any new features.

Also consider using hydra instead. To some extend magit-popup and hydra are similar but have a different focus. The main purpose of magit-popup is to pass infix arguments to suffix commands. If all you need is a command dispatcher then you are better of using hydra. Of course hydra may also be a better fit not only because of the features it lacks, but also because of the features it provides, which are in turn missing from magit-popup.

Here is an example of how one defines a prefix command along with its infix arguments, and then also one of its suffix commands.

;;;###autoload (autoload 'magit-tag-popup "magit" nil t)
(magit-define-popup magit-tag-popup
  "Show popup buffer featuring tagging commands."
  'magit-commands
  :man-page "git-tag"
  :switches '((?a "Annotate" "--annotate")
              (?s "Sign"     "--sign")
              (?f "Force"    "--force"))
  :actions  '((?t "Create"   magit-tag)
              (?k "Delete"   magit-tag-delete)
              (?p "Prune"    magit-tag-prune))
  :default-action 'magit-tag)

;;;###autoload
(defun magit-tag (name rev &optional args)
  "Create a new tag with the given NAME at REV."
  (interactive (list (magit-read-tag "Tag name")
                     (magit-read-branch-or-commit "Place tag on")
                     (magit-tag-arguments)))
  (magit-run-git-with-editor "tag" args name rev))

Previous: , Up: Top   [Contents]