Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging menu and do-it commands into just one command #20

Open
tarsius opened this issue Feb 11, 2025 · 0 comments
Open

Merging menu and do-it commands into just one command #20

tarsius opened this issue Feb 11, 2025 · 0 comments

Comments

@tarsius
Copy link
Collaborator

tarsius commented Feb 11, 2025

You could merge do-it commands into the respective menu commands.

This, for example:

(transient-define-prefix magit-stgit-undo ()
  "Undo a previous stack operation."
  :man-page "stg-undo"
  ["Arguments"
   ("-n" "Undo the last N operations" "--number="
    :reader (lambda (prompt _initial-input history)
              (number-to-string (read-number prompt nil history))))
   ("-h" "Discard changes in index/worktree" "--hard")]
  ["Actions"
   ("z"  "Undo" magit-stgit--undo)])

;;;###autoload
(defun magit-stgit--undo (&rest args)
  "Invoke `stg undo ARGS...'."
  (interactive (transient-args 'magit-stgit-undo))
  (magit-run-stgit "undo" args))

would become

(transient-define-prefix magit-stgit-undo (&optional menu)
  "Undo a previous stack operation."
  :man-page "stg-undo"
  ["Arguments"
   ("-n" "Undo the last N operations" "--number="
    :reader (lambda (prompt _initial-input history)
              (number-to-string (read-number prompt nil history))))
   ("-h" "Discard changes in index/worktree" "--hard")]
  ["Actions"
   ("z"  "Undo" magit-stgit-undo)]
  (interactive (list (not (eq transient-current-command 'magit-stgit-undo))))
  (if menu
      (transient-setup 'magit-stgit-undo)
    (apply #'magit-run-stgit "undo" (transient-args 'magit-stgit-undo))))

That's what I consider the canonical way to implement such commands. It would also have the benefit benefit that there no longer would be any commands that use the magit-stgit-- prefix, which is intended only for internal functions, and certainly not commands. (Of course the latter could also be addressed using magit-stgit-do-ACTION.)

You would lose the ability to call the magit-stgit--ACTION functions from code, but I assume that might not actually be something you wanted to make possible and just fell out of the implementation.

For a few commands this would be a bit more complicated. It appears that you do want to enable delete and goto without going through the menu. You could do that using interactive forms looking like:

  (interactive (list (not (or (eq transient-current-command 'magit-stgit-goto)
                              (magit-section-match 'stgit-patch)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant