1

In response to a question about adding an action to magit's push menu, I've written an Emacs Lisp command to implement the extension, and I've learned that I can extend the push menu by calling magit-define-popup-action. However, not every repository supports the new action. I've defined another Emacs Lisp function that will tell me, in a particular repository, whether the action is supported. I want to define a new popup action only when the action is supported.

Is there a hook or other trick I can use to define the new popup action only on those repositories where the action is supported? Or some other conditional code I can arrange for so that the menu knows, in a way sensitive to a particular repository, whether the action is enabled? I know for example that P p and P u change their descriptions depending on settings in the git configuration, but I don't see how that is done.

Ideally if the action is not supported, there is no change of setting that can make it supported, and I'd prefer not to have the item on the menu. But I'd settle for a way to give a description saying the action is unavailable. And bonus points if I can "gray it out."

1

You can do this simply by using a function instead of a string as "description":

(magit-define-popup-action 'magit-push-popup ?!
  (lambda ()
    (and PREDICATE
         "Make remotely\n"))
  'aec/ssh-make-and-fetch)

This function has to return nil to indicate that the action should not be available or else it has to return the string to be inserted into the popup buffer to describe what the action does.

0

This has changed recently with newer versions of Magit which use "Transient" to accomplish this:

(transient-append-suffix 'magit-push "m" '("!" "Make remotely" 'aec/ssh-make-and-fetch))

Reference: https://github.com/magit/magit/wiki/Converting-popup-modifications-to-transient-modifications

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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