Subject: Re: [StGit PATCH 2/2] Emacs mode: delete patches

From: David Kågedal <[email-masked]>
Date: Mon, 11 Feb 2008 10:42:22 +0100

Karl Hasselström <[email-masked]> writes:

> Teach the emacs mode to delete patches.
>
> Signed-off-by: Karl Hasselström <[email-masked]>
>
> ---
>
> David, could you have a look at this as well? In addition to me being
> elisp challenged, there are the following issues:
>
>   * Is "d" a reasonable binding? Any better suggestion?

We could reserve "d" for moving a patch "down", maybe.  The more
destructive commands could be on less accessible keys. Maybe "D" or
"C-d".

>   * Currently, this command requires you to mark one or more patches
>     before deleting. This is convenient when deleting more than one
>     patch, but one could argue that it should be possible to delete
>     the patch at point without having to select it.

You need something like this:

--- a/contrib/stgit.el
+++ b/contrib/stgit.el
@@ -187,6 +187,15 @@ Commands:
         (match-string-no-properties 1)
       nil)))
 
+(defun stgit-selected-patches ()
+  "Return the names of the marked patches, or the patch on the current line."
+  (if stgit-marked-patches
+      (stgit-marked-patches)
+    (let ((patch (stgit-patch-at-point)))
+      (if patch
+          (list patch)
+        '()))))
+
 (defun stgit-goto-patch (patch)
   "Move point to the line containing PATCH"
   (let ((p (point)))

>   * We should probably ask for confirmation before deleting.

Absolutely. Something like this (untested):

(defun stgit-delete (patch-names)
  "Delete the named patches"
  (interactive (list (stgit-selected-patches)))
  (if (zerop (length patch-names))
      (error "No patches to delete")
    (when (yes-or-no-p (format "Really delete %d patches? "
                               (length patch-names)))
      (stgit-capture-output nil
        (apply 'stgit-run "delete" patch-names))
      (stgit-refresh))

-- 
David Kågedal