Skip to content

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

@tarsius

Description

@tarsius

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)))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions