]> code.delx.au - gnu-emacs/blobdiff - lisp/format.el
Sync with Tramp 2.1.19.
[gnu-emacs] / lisp / format.el
index 37dd95bd1c43b225c58cbe2a828063d268f7fa22..d4262e2d0e694dd2d9cf7f6adfb0dc6e36ee83db 100644 (file)
@@ -1,7 +1,7 @@
 ;;; format.el --- read and save files in multiple formats
 
 ;; Copyright (C) 1994, 1995, 1997, 1999, 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007, 2008, 2009  Free Software Foundation, Inc.
+;;   2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
 
 ;; Author: Boris Goldowsky <boris@gnu.org>
 
@@ -222,9 +222,6 @@ For most purposes, consider using `format-encode-region' instead."
                  (multibyte enable-multibyte-characters)
                  (coding-system buffer-file-coding-system))
              (with-current-buffer copy-buf
-               (set (make-local-variable
-                     'write-region-post-annotation-function)
-                    'kill-buffer)
                (setq selective-display sel-disp)
                (set-buffer-multibyte multibyte)
                (setq buffer-file-coding-system coding-system))
@@ -232,6 +229,15 @@ For most purposes, consider using `format-encode-region' instead."
              (set-buffer copy-buf)
              (format-insert-annotations write-region-annotations-so-far from)
              (format-encode-run-method to-fn (point-min) (point-max) orig-buf)
+              (when (buffer-live-p copy-buf)
+                (with-current-buffer copy-buf
+                  ;; Set write-region-post-annotation-function to
+                  ;; delete the buffer once the write is done, but do
+                  ;; it after running to-fn so it doesn't affect
+                  ;; write-region calls in to-fn.
+                  (set (make-local-variable
+                        'write-region-post-annotation-function)
+                       'kill-buffer)))
              nil)
          ;; Otherwise just call function, it will return annotations.
          (funcall to-fn from to orig-buf)))))