chiark / gitweb /
stgit.el: Move point correctly after stgit-revert-file
authorGustav Hållberg <gustav@virtutech.com>
Wed, 5 Aug 2009 13:18:43 +0000 (15:18 +0200)
committerGustav Hållberg <gustav@virtutech.com>
Thu, 6 Aug 2009 20:49:08 +0000 (22:49 +0200)
Signed-off-by: Gustav Hållberg <gustav@virtutech.com>
contrib/stgit.el

index e8995b34ba658be70297c68b41f2d045655d88f6..083b25b1f7ef836ff8d239026bfe57ff5fdf8b19 100644 (file)
@@ -980,6 +980,22 @@ (defun stgit-uncommit (count)
     (stgit-capture-output nil (stgit-run "uncommit" "-n" count))
     (stgit-reload)))
 
+(defun stgit-neighbour-file ()
+  "Return the file name of the next file after point, or the
+previous file if point is at the last file within a patch."
+  (let ((old-point (point))
+        neighbour-file)
+    (and (zerop (forward-line 1))
+         (let ((f (stgit-patched-file-at-point)))
+           (and f (setq neighbour-file (stgit-file-file f)))))
+    (goto-char old-point)
+    (unless neighbour-file
+      (and (zerop (forward-line -1))
+           (let ((f (stgit-patched-file-at-point)))
+             (and f (setq neighbour-file (stgit-file-file f)))))
+      (goto-char old-point))
+    neighbour-file))
+
 (defun stgit-revert-file ()
   "Revert the file at point, which must be in the index or the
 working tree."
@@ -995,7 +1011,8 @@ (defun stgit-revert-file ()
          (co-file      (cond ((eq file-status 'rename)
                               (stgit-file-cr-from patched-file))
                              ((not (memq file-status '(copy add)))
-                              (stgit-file-file patched-file)))))
+                              (stgit-file-file patched-file))))
+         (next-file    (stgit-neighbour-file)))
 
     (unless (memq patch-name '(:work :index))
       (error "No index or working tree file on this line"))
@@ -1015,7 +1032,8 @@ (defun stgit-revert-file ()
             (stgit-run-git "rm" "-f" "-q" "--" rm-file))
           (when co-file
             (stgit-run-git "checkout" "HEAD" co-file)))
-        (stgit-reload)))))
+        (stgit-reload)
+        (stgit-goto-patch patch-name next-file)))))
 
 (defun stgit-resolve-file ()
   "Resolve conflict in the file at point."
@@ -1198,20 +1216,7 @@ (defun stgit-file-toggle-index ()
       (error "You cannot add ignored files to the index"))
     (let* ((patch      (stgit-patch-at-point))
            (patch-name (stgit-patch-name patch))
-           (old-point  (point))
-           next-file)
-
-      ;; find the next file in the patch, or the previous one if this
-      ;; was the last file
-      (and (zerop (forward-line 1))
-           (let ((f (stgit-patched-file-at-point)))
-             (and f (setq next-file (stgit-file-file f)))))
-      (goto-char old-point)
-      (unless next-file
-        (and (zerop (forward-line -1))
-             (let ((f (stgit-patched-file-at-point)))
-               (and f (setq next-file (stgit-file-file f)))))
-        (goto-char old-point))
+           (next-file  (stgit-neighbour-file)))
 
       (cond ((eq patch-name :work)
              (stgit-move-change-to-index (stgit-file-file patched-file)))