0

In magit status of a Git repository, you usually press f u to fetch from upstream (these keybindings in Magit will call magit-fetch-from-upstream).

With Magit keybindings I have noticed the letters hkjl after prefix f were not used yet. So I added the following:

(map! :map magit-mode-map
 :n "fh" #'evil-window-left
 :n "fl" #'evil-window-right)

This works well in Magit. Later it turns out this also disabled the prefix-related keybinding u after prefix f. So I'm wondering how I could add another keybinding after prefix f while retaining the other Magit prefix-related keybindings?

1
  • 1
    Please always mention if you are using the doom Emacs distribution. Others have no idea what the map! syntax means. Nov 24, 2023 at 13:33

1 Answer 1

1
+50

Transients activate their own keymaps. The Modifying Existing Transients section of the transient manual describes how to extend existing transients. Unfortunately, it generally takes quite some investment to understand the transient manual.

Anyway, you could extend the 'magit-fetch prefix as follows:

(with-eval-after-load 'magit-fetch
  (transient-append-suffix
  'magit-fetch
  '(3)
  ["Navigate"
   ("h" "forward char" evil-backward-char :transient t)
   ("l" "backward char" evil-forward-char :transient t)]))

The second argument (3) defines where to add the extra commands.

The :transient t sets the transient to stay transient.

I am not sure how to 'point' Emacs to use the 'original' keymap if some key is not included in the prefix (I vaguely remember this was possible, but I can not find it again now... however, maybe I have dreamed it :).

3
  • Your message is appreciated, it took time to wrap my head around what transients are and how it works. Unfortunately, as you provided didn't worked. I copied it and got this error: Error caused by user's config or system: [path to keybinding], (error magit-fetch is not a transient command). When I do <kbd>C-h k</h> <kbd>f</kbd> in Magit status window, he is waiting for second input so I can't find it. Based on docs about transients, I found this section: magit.vc/manual/0.1.0/transient/… but it didn't solved my question yet.
    – ReneFroger
    Nov 25, 2023 at 16:30
  • 1
    The magit-fetch command is not known before magit-fetch.el has been loaded. I have updated the answer with a solution. Nov 25, 2023 at 19:56
  • 1
    Whoa, it worked straight now! Now it makes much more sense. I really deeply appreciate your response. Learning about transient, I'm going to apply in my other magit workflows as well. Thank you for your help ☺️!
    – ReneFroger
    Nov 25, 2023 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.