* files.el (file-name-non-special): Only change buffer-file-name after
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 24 Jan 2011 20:34:44 +0000 (15:34 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Mon, 24 Jan 2011 20:34:44 +0000 (15:34 -0500)
insert-file-contents if it's `visit'ing the file.

Fixes: debbugs:7854

lisp/ChangeLog
lisp/files.el

index 4a8efcd..820a54f 100644 (file)
@@ -1,3 +1,8 @@
+2011-01-24  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * files.el (file-name-non-special): Only change buffer-file-name after
+       insert-file-contents if it's `visit'ing the file (bug#7854).
+
 2011-01-23  Chong Yidong  <cyd@stupidchicken.com>
 
        * dired.el (dired-revert): Doc fix (Bug#7758).
index 92029b4..ee77975 100644 (file)
@@ -6041,8 +6041,7 @@ only these files will be asked to be saved."
                          (substitute-in-file-name identity)
                          ;; `add' means add "/:" to the result.
                          (file-truename add 0)
-                         ;; `quote' means add "/:" to buffer-file-name.
-                         (insert-file-contents quote 0)
+                         (insert-file-contents insert-file-contents 0)
                          ;; `unquote-then-quote' means set buffer-file-name
                          ;; temporarily to unquoted filename.
                          (verify-visited-file-modtime unquote-then-quote)
@@ -6073,20 +6072,18 @@ only these files will be asked to be saved."
                           "/"
                         (substring (car pair) 2)))))
        (setq file-arg-indices (cdr file-arg-indices))))
-    (cond ((eq method 'identity)
-          (car arguments))
-         ((eq method 'add)
-          (concat "/:" (apply operation arguments)))
-         ((eq method 'quote)
-          (unwind-protect
+    (case method
+      (identity (car arguments))
+      (add (concat "/:" (apply operation arguments)))
+      (insert-file-contents
+       (let ((visit (nth 1 arguments)))
+         (prog1
               (apply operation arguments)
-            (setq buffer-file-name (concat "/:" buffer-file-name))))
-         ((eq method 'unquote-then-quote)
-          (let (res)
-            (setq buffer-file-name (substring buffer-file-name 2))
-            (setq res (apply operation arguments))
-            (setq buffer-file-name (concat "/:" buffer-file-name))
-            res))
+           (when (and visit buffer-file-name)
+             (setq buffer-file-name (concat "/:" buffer-file-name))))))
+      (unquote-then-quote
+       (let ((buffer-file-name (substring buffer-file-name 2)))
+         (apply operation arguments)))
          (t
           (apply operation arguments)))))
 \f