+ (unless arg (setq arg 1))
+ (cond ((< arg 0)
+ (stgit-next-patch (- arg)))
+ ((zerop arg)
+ (move-to-column (stgit-goal-column)))
+ ((stgit-at-header-p)
+ (goto-char (point-min)))
+ (t
+ (let ((opatch (stgit-patch-at-point)))
+ (ewoc-goto-prev stgit-ewoc arg)
+ (unless (zerop arg)
+ (when (eq opatch (stgit-patch-at-point))
+ (goto-char (point-min)))))
+ (move-to-column (stgit-goal-column)))))
+
+(defun stgit-previous-patch-group (&optional arg)
+ "Move to the previous group of patches.
+
+If ARG is non-nil, do this ARG times. If ARG is negative, move
+-ARG groups forward instead; cf. `stgit-next-patch-group'."
+ (interactive "p")
+ (stgit-assert-mode)
+ (if (< arg 0)
+ (stgit-previous-patch-group (- arg))
+ (while (and (not (bobp))
+ (> arg 0))
+ (stgit-previous-patch 1)
+ (let* ((opoint (point))
+ (patch (stgit-patch-at-point))
+ (status (and patch (stgit-patch->status patch))))
+ (while (and (not (bobp))
+ (let* ((npatch (stgit-patch-at-point))
+ (nstatus (and npatch (stgit-patch->status npatch))))
+ (eq status nstatus)))
+ (setq opoint (point))
+ (stgit-previous-patch 1))
+ (goto-char opoint))
+ (setq arg (1- arg)))))
+
+(defun stgit-next-patch-group (&optional arg)
+ "Move to the next group of patches.
+
+If ARG is non-nil, do this ARG times. If ARG is negative, move
+-ARG groups backwards instead; cf. `stgit-previous-patch-group'."
+ (interactive "p")
+ (stgit-assert-mode)
+ (if (< arg 0)
+ (stgit-previous-patch-group (- arg))
+ (while (and (not (eobp))
+ (> arg 0))
+ (let* ((patch (stgit-patch-at-point))
+ (status (and patch (stgit-patch->status patch))))
+ (while (and (not (eobp))
+ (let* ((npatch (stgit-patch-at-point))
+ (nstatus (and npatch (stgit-patch->status npatch))))
+ (eq status nstatus)))
+ (stgit-next-patch 1)))
+ (setq arg (1- arg)))))