Subject: 23.1; vc-revert modifies window configuration
From: Nathaniel Flath <[email-masked]>
To: [email-masked]
Date: Mon, 4 Jan 2010 00:14:50 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

To: [email-masked]
Subject: 23.1; vc-revert modifies window configuration
--text follows this line--

Please write in English if possible, because the Emacs maintainers
usually do not have translators to read other languages for them.

Your bug report will be posted to the [email-masked] mailing list,
and to the gnu.emacs.bug news group.

Please describe exactly what actions triggered the bug
and the precise symptoms of the bug:

When calling vc-revert on a window configuration other than the default, it
is likely to change as a result.

To reproduce:
emacs -q
C-x 3
In one window, open a file under version control and modify it
M-x vc-revert
confirm the reversion

At this point, the second window will be closed.

The attached patch fixes this problem.

If Emacs crashed, and you have the Emacs process in the gdb debugger,
please include the output from the following gdb commands:
    `bt full' and `xbacktrace'.
If you would like to further debug the crash, please read the file
/usr/share/emacs/23.1/etc/DEBUG for instructions.

In GNU Emacs 23.1.1 (i486-pc-linux-gnu, GTK+ Version 2.18.3)
 of 2009-11-10 on vernadsky, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.10604000
configured using `configure  '--build=i486-linux-gnu'
'--host=i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib'
'--libexecdir=/usr/lib' '--localstatedir=/var/lib'
'--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes'
'--enable-locallisppath=/etc/emacs23:/etc/emacs:/usr/local/share/emacs/23.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.1/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/23.1/leim'
'--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars'
'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g
-O2' 'LDFLAGS=-g' 'CPPFLAGS=''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default-enable-multibyte-characters: t

Major mode: Shell

Minor modes in effect:
  diff-auto-refine-mode: t
  save-visited-files-mode: t
  savehist-mode: t
  dirtrack-mode: t
  global-pabbrev-mode: t
  icomplete-mode: t
  display-battery-mode: t
  display-time-mode: t
  show-paren-mode: t
  cua-mode: t
  command-frequency-autosave-mode: t
  command-frequency-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  global-auto-composition-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n
C-n C-n C-n C-n C-n C-p M-< C-x o M-> M-p C-a M-f C-f
v c . e l SPC C-a M-f SPC - j <backspace> u <return>
C-x C-f <backspace> <backspace> v c <return> M-< C-n
C-n C-k C-k C-k C-k C-k C-/ C-/ C-k C-k C-k C-d C-d
C-d C-d C-d C-d C-d C-d C-p C-p C-k C-k C-k C-k C-d
C-d C-d C-d C-d C-d C-d C-d C-n C-x C-s C-x b <return>
M-p <return> M-p M-p M-p M-p M-p M-m M-n C-a M-f M-f
M-f <tab> b <home> <backspace> <backspace> <right>
<right> <right> <right> <right> <right> <right> <right>
<right> <right> <right> <right> <backspace> <backspace>
N a u f <backspace> r <return> C-x p o C-x <tab> t
t C-g C-g C-c C-c M-p C-w C-w <backspace> <backspace>
<backspace> <backspace> <backspace> <backspace> <return>
C-x o C-x C-f v c . e l <return> y C-p C-n C-M-b C-n
C-n C-n C-n C-n C-x C-s C-a C-f C-f C-f C-f C-f C-f
C-f C-f C-f C-f C-f C-f C-f C-f C-f C-f C-f C-f C-f
C-f C-f C-f C-f C-f C-f C-f C-f C-f C-a C-p C-p C-p
C-p C-x v = C-x k <return> C-x o M-x v c SPC r e v
e r t SPC f <backspace> <backspace> <return> <return>
y C-n C-n C-n C-n C-n C-p C-x v = C-x k <return> C-x
o C-x o C-x b <return> C-c C-c M-p M-p M-p M-p M-n
<return> C-x o d r C-x o r r <backspace> C-x C-s C-x
o M-x r e p o r t SPC e m a c s SPC b u g <return>

Recent messages:
vc.el changed on disk; really edit the buffer? (y, n, r or C-h)
Please type y, n or r; or ? for help
vc.el changed on disk; really edit the buffer? (y, n, r or C-h)
byte-code: File reverted: /home/nflath/emacs/lisp/vc.el
Saving file /home/nflath/emacs/lisp/vc.el...
Wrote /home/nflath/emacs/lisp/vc.el

Saving file /home/nflath/.emacs.d/emacs-visited-files...
Wrote /home/nflath/.emacs.d/emacs-visited-files
defun: (NAME ARGLIST [DOCSTRING] BODY...)
--- vc.el	7 Dec 2009 09:02:16 -0000	1.746
+++ vc.el	4 Jan 2010 04:10:54 -0000
@@ -1975,37 +1975,38 @@
 This asks for confirmation if the buffer contents are not identical
 to the working revision (except for keyword expansion)."
   (interactive)
-  (let* ((vc-fileset (vc-deduce-fileset))
-	 (files (cadr vc-fileset)))
-    ;; If any of the files is visited by the current buffer, make
-    ;; sure buffer is saved.  If the user says `no', abort since
-    ;; we cannot show the changes and ask for confirmation to
-    ;; discard them.
-    (when (or (not files) (memq (buffer-file-name) files))
-      (vc-buffer-sync nil))
-    (dolist (file files)
-      (let ((buf (get-file-buffer file)))
-	(when (and buf (buffer-modified-p buf))
-	  (error "Please kill or save all modified buffers before reverting")))
-      (when (vc-up-to-date-p file)
-	(unless (yes-or-no-p (format "%s seems up-to-date.  Revert anyway? " file))
-	  (error "Revert canceled"))))
-    (when (vc-diff-internal vc-allow-async-revert vc-fileset nil nil)
-      (unless (yes-or-no-p
-	       (format "Discard changes in %s? "
-		       (let ((str (vc-delistify files))
-			     (nfiles (length files)))
-			 (if (< (length str) 50)
-			     str
-			   (format "%d file%s" nfiles
-				   (if (= nfiles 1) "" "s"))))))
-	(error "Revert canceled"))
-      (delete-windows-on "*vc-diff*")
-      (kill-buffer "*vc-diff*"))
-    (dolist (file files)
-      (message "Reverting %s..." (vc-delistify files))
-      (vc-revert-file file)
-      (message "Reverting %s...done" (vc-delistify files)))))
+  (save-window-excursion
+   (let* ((vc-fileset (vc-deduce-fileset))
+          (files (cadr vc-fileset)))
+     ;; If any of the files is visited by the current buffer, make
+     ;; sure buffer is saved.  If the user says `no', abort since
+     ;; we cannot show the changes and ask for confirmation to
+     ;; discard them.
+     (when (or (not files) (memq (buffer-file-name) files))
+       (vc-buffer-sync nil))
+     (dolist (file files)
+       (let ((buf (get-file-buffer file)))
+         (when (and buf (buffer-modified-p buf))
+           (error "Please kill or save all modified buffers before reverting")))
+       (when (vc-up-to-date-p file)
+         (unless (yes-or-no-p (format "%s seems up-to-date.  Revert anyway? " file))
+           (error "Revert canceled"))))
+     (when (vc-diff-internal vc-allow-async-revert vc-fileset nil nil)
+       (unless (yes-or-no-p
+                (format "Discard changes in %s? "
+                        (let ((str (vc-delistify files))
+                              (nfiles (length files)))
+                          (if (< (length str) 50)
+                              str
+                            (format "%d file%s" nfiles
+                                    (if (= nfiles 1) "" "s"))))))
+         (error "Revert canceled"))
+       (delete-windows-on "*vc-diff*")
+       (kill-buffer "*vc-diff*"))
+     (dolist (file files)
+       (message "Reverting %s..." (vc-delistify files))
+       (vc-revert-file file)
+       (message "Reverting %s...done" (vc-delistify files))))))

 ;;;###autoload
 (defun vc-rollback ()