12

Magit displays the progression of multi-step commands with popup windows. For example, pressing c brings up the commit menu, whence pressing a will invoke magit-commit-amend.

I would like to include my own command magit-commit-snapshot, and invoke it with cn.
n: Snapshot should be displayed in the commit menu, after s: Squash.

How can I do this? I can see that the bindings exist in magit-key-mode.el, but I don't see an easy way to add to them from my .emacs.

1 Answer 1

17

Starting with v2.1.0 you can do so using this:

(magit-define-popup-action 'magit-commit-popup ?n "Snapshot" 'magit-commit-snapshot) 

The next release of Magit will replace magit-popup with transient. (As of writing the current Magit release is v2.90.1.) Using transient, you can add a custom command with transient-append-suffix:

(transient-append-suffix 'magit-commit "c" '("n" "Snapshot" magit-commit-snapshot)) 

For more information, see the section on modifying existing transients in the manual.

3
  • 1
    @tarsius, I appreciate how you keep your answer up to date as Magit changes. Commented Jul 3, 2015 at 20:45
  • @tarsius I think this no longer works with transient.el? Is there a more up-to-date answer? Commented Oct 30, 2019 at 21:07
  • For anyone wondering how to figure out what prefix command goes with a key (e.g. 'magit-commit in this case): enter the magit transient (C-x M-g), then hit C-x l, then type the leader key: it will show the prefix command in the minibuffer. E.g. to find the prefix command for "l" (log): C-x M-g C-x l l, and you will see: magit-log. Commented Apr 19, 2021 at 9:53

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.