Skip to content

Commit 5c16937

Browse files
committed
Convert delete popup
1 parent 9a8dfdc commit 5c16937

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

magit-stgit.el

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ one from the minibuffer, and move to the next line."
271271
("RET" "Show" magit-stgit-show)]
272272
[("e" "Edit" magit-stgit-edit)
273273
("n" "Rename" magit-stgit-rename)
274-
("k" "Delete" magit-stgit-delete-popup)]
274+
("k" "Delete" magit-stgit-delete)]
275275
[("m" "Mail patches" magit-stgit-mail-popup)]])
276276

277277
;;;###autoload
@@ -502,37 +502,40 @@ and ask whether to update the remote first."
502502
(message "Updating remote...done"))
503503
(magit-run-stgit "rebase" args (format "remotes/%s/%s" remote branch)))
504504

505-
(magit-define-popup magit-stgit-delete-popup
506-
"Popup console for StGit delete."
507-
'magit-stgit-commands
508-
:switches '((?s "Spill patch contents to worktree and index" "--spill"))
509-
:actions '((?k "Delete" magit-stgit-delete))
510-
:default-action #'magit-stgit-delete)
505+
(transient-define-prefix magit-stgit-delete ()
506+
"Delete a set of patches."
507+
:man-page "stg-delete"
508+
["Arguments"
509+
("-s" "Spill patch contents to worktree and index" "--spill")]
510+
["Actions"
511+
("k" "Delete" magit-stgit--delete)])
511512

512513
;;;###autoload
513-
(defun magit-stgit-delete (patches &rest args)
514-
"Delete StGit patches.
515-
Argument PATCHES is a list of patchnames.
516-
Use ARGS to pass additional arguments."
517-
(interactive (list (magit-stgit-read-patches t t t t "Delete patch")
518-
(magit-stgit-delete-arguments)))
519-
(let ((affected-files
520-
(-mapcat (lambda (patch)
521-
(magit-stgit-lines "files" "--bare" patch))
522-
patches)))
523-
(when (and (called-interactively-p 'any)
524-
(not magit-current-popup)
525-
(and affected-files (y-or-n-p "Spill contents? ")))
526-
(setq args (append args (list "--spill")))))
527-
(let ((spill (member "--spill" args)))
528-
(when spill
529-
(setq spill (list "--spill")))
514+
(defun magit-stgit--delete (patches &rest args)
515+
"Invoke `stg delete ARGS... PATCHES...'.
516+
517+
If called interactively, delete the patches around point or read
518+
one from the minibuffer. Ask whether to spill the contents and
519+
ask for confirmation before deleting."
520+
(interactive (cons (magit-stgit-read-patches t t t t "Delete patch")
521+
(transient-args 'magit-stgit-delete)))
522+
(let* ((non-empty-p (-some (-cut magit-stgit-lines "files" "--bare" <>)
523+
patches))
524+
(args (if (and (called-interactively-p 'any)
525+
(not transient-current-prefix)
526+
non-empty-p
527+
(y-or-n-p "Spill contents? "))
528+
(cons "--spill" args)
529+
args))
530+
(spillp (member "--spill" args)))
530531
(when (or (not (called-interactively-p 'any))
531-
(yes-or-no-p (format "Delete%s patch%s %s? "
532-
(if spill " and spill" "")
533-
(if (> (length patches) 1) "es" "")
534-
(mapconcat (lambda (patch) (format "`%s'" patch)) patches ", "))))
535-
(magit-run-stgit-and-mark-remove patches "delete" args "--" patches))))
532+
(yes-or-no-p
533+
(format "Delete%s patch%s %s? "
534+
(if spillp " and spill" "")
535+
(if (> (length patches) 1) "es" "")
536+
(mapconcat (lambda (patch) (format "`%s'" patch))
537+
patches ", "))))
538+
(magit-run-stgit-and-mark-remove patches "delete" args patches))))
536539

537540
(magit-define-popup magit-stgit-goto-popup
538541
"Popup console for StGit goto."
@@ -694,7 +697,7 @@ the To, Cc, and Bcc fields for all patches."
694697
:help "Permanently store the base patch into the stack base"]
695698
["Uncommit patch" magit-stgit-uncommit
696699
:help "Turn a regular commit into an StGit patch"]
697-
["Delete patch" magit-stgit-delete-popup
700+
["Delete patch" magit-stgit-delete
698701
:help "Delete an StGit patch"]
699702
"---"
700703
["Float patch" magit-stgit-float
@@ -723,7 +726,7 @@ the To, Cc, and Bcc fields for all patches."
723726

724727
(defvar magit-stgit-patch-section-map
725728
(let ((map (make-sparse-keymap)))
726-
(define-key map "k" 'magit-stgit-delete)
729+
(define-key map "k" #'magit-stgit--delete)
727730
(define-key map "a" 'magit-stgit-goto)
728731
(define-key map (kbd "RET") #'magit-stgit-show)
729732
(define-key map "#" #'magit-stgit-mark-toggle)

0 commit comments

Comments
 (0)