changeset 104858:53d8d2c49942

* lisp/files.el (find-alternate-file): Run `kill-buffer-hook' manually before killing the old buffer, since by the time `kill-buffer' is run so many buffer variables have been set to nil that it may not behave as expected. (Bug#4061)
author Karl Fogel <kfogel@red-bean.com>
date Sat, 05 Sep 2009 16:25:27 +0000
parents ea5c49fab49a
children 04c1c903e532
files lisp/ChangeLog lisp/files.el
diffstat 2 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Sep 05 15:16:49 2009 +0000
+++ b/lisp/ChangeLog	Sat Sep 05 16:25:27 2009 +0000
@@ -1,3 +1,10 @@
+2009-09-05  Karl Fogel  <kfogel@red-bean.com>
+
+	* files.el (find-alternate-file): Run `kill-buffer-hook' manually
+	before killing the old buffer, since by the time `kill-buffer' is
+	run so many buffer variables have been set to nil that it may not
+	behave as expected.  (Bug#4061)
+
 2009-09-05  Karl Fogel  <kfogel@red-bean.com>
 
 	* files.el (find-alternate-file): If the old buffer is modified
--- a/lisp/files.el	Sat Sep 05 15:16:49 2009 +0000
+++ b/lisp/files.el	Sat Sep 05 16:25:27 2009 +0000
@@ -1493,6 +1493,17 @@
 	(odir dired-directory)
 	(otrue buffer-file-truename)
 	(oname (buffer-name)))
+    ;; Run `kill-buffer-hook' here.  It needs to happen before
+    ;; variables like `buffer-file-name' etc are set to nil below,
+    ;; because some of the hooks that could be invoked
+    ;; (e.g., `save-place-to-alist') depend on those variables.
+    ;;
+    ;; Note that `kill-buffer-hook' is not what queries whether to
+    ;; save a modified buffer visiting a file.  Rather, `kill-buffer'
+    ;; asks that itself.  Thus, there's no need to temporarily do
+    ;; `(set-buffer-modified-p nil)' before running this hook.
+    (run-hooks 'kill-buffer-hook)
+    ;; Okay, now we can end-of-life the old buffer.
     (if (get-buffer " **lose**")
 	(kill-buffer " **lose**"))
     (rename-buffer " **lose**")
@@ -1520,8 +1531,8 @@
 	(rename-buffer oname)))
     (unless (eq (current-buffer) obuf)
       (with-current-buffer obuf
-	;; We already asked; don't ask again.
-	(let ((kill-buffer-query-functions))
+	;; We already ran these; don't run them again.
+	(let (kill-buffer-query-functions kill-buffer-hook)
 	  (kill-buffer obuf))))))
 
 (defun create-file-buffer (filename)