+(defun stgit-edit ()
+ "Edit the patch on the current line"
+ (interactive)
+ (let ((patch (stgit-patch-at-point))
+ (edit-buf (get-buffer-create "*StGit edit*"))
+ (dir default-directory))
+ (log-edit 'stgit-confirm-edit t nil edit-buf)
+ (set (make-local-variable 'stgit-edit-patch) patch)
+ (setq default-directory dir)
+ (let ((standard-output edit-buf))
+ (stgit-run "edit" "--save-template=-" patch))))
+
+(defun stgit-confirm-edit ()
+ (interactive)
+ (let ((file (make-temp-file "stgit-edit-")))
+ (write-region (point-min) (point-max) file)
+ (stgit-capture-output nil
+ (stgit-run "edit" "-f" file stgit-edit-patch))
+ (with-current-buffer log-edit-parent-buffer
+ (stgit-refresh))))
+
+(defun stgit-new ()
+ "Create a new patch"
+ (interactive)
+ (let ((edit-buf (get-buffer-create "*StGit edit*")))
+ (log-edit 'stgit-confirm-new t nil edit-buf)))
+
+(defun stgit-confirm-new ()
+ (interactive)
+ (let ((file (make-temp-file "stgit-edit-")))
+ (write-region (point-min) (point-max) file)
+ (stgit-capture-output nil
+ (stgit-run "new" "-f" file))
+ (with-current-buffer log-edit-parent-buffer
+ (stgit-refresh))))
+
+(defun stgit-create-patch-name (description)
+ "Create a patch name from a long description"
+ (let ((patch ""))
+ (while (> (length description) 0)
+ (cond ((string-match "\\`[a-zA-Z_-]+" description)
+ (setq patch (downcase (concat patch (match-string 0 description))))
+ (setq description (substring description (match-end 0))))
+ ((string-match "\\` +" description)
+ (setq patch (concat patch "-"))
+ (setq description (substring description (match-end 0))))
+ ((string-match "\\`[^a-zA-Z_-]+" description)
+ (setq description (substring description (match-end 0))))))
+ (cond ((= (length patch) 0)
+ "patch")
+ ((> (length patch) 20)
+ (substring patch 0 20))
+ (t patch))))
+
+(defun stgit-delete (patch-names)
+ "Delete the named patches"
+ (interactive (list (stgit-patches-marked-or-at-point)))
+ (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))))
+
+(defun stgit-coalesce (patch-names)
+ "Run stg coalesce on the named patches"
+ (interactive (list (stgit-marked-patches)))
+ (let ((edit-buf (get-buffer-create "*StGit edit*"))
+ (dir default-directory))
+ (log-edit 'stgit-confirm-coalesce t nil edit-buf)
+ (set (make-local-variable 'stgit-patches) patch-names)
+ (setq default-directory dir)
+ (let ((standard-output edit-buf))
+ (apply 'stgit-run "coalesce" "--save-template=-" patch-names))))
+
+(defun stgit-confirm-coalesce ()
+ (interactive)
+ (let ((file (make-temp-file "stgit-edit-")))
+ (write-region (point-min) (point-max) file)
+ (stgit-capture-output nil
+ (apply 'stgit-run "coalesce" "-f" file stgit-patches))
+ (with-current-buffer log-edit-parent-buffer
+ (stgit-refresh))))
+