changeset 2718:5427b625d5cc

[xemacs-hg @ 2005-04-08 14:06:58 by aidan] Make find-file with prefix-arg on a nonexistent file behave properly.
author aidan
date Fri, 08 Apr 2005 14:07:00 +0000
parents 834cce9b2360
children 5f6ef2b26d9f
files lisp/ChangeLog lisp/files.el
diffstat 2 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Thu Apr 07 21:51:47 2005 +0000
+++ b/lisp/ChangeLog	Fri Apr 08 14:07:00 2005 +0000
@@ -1,3 +1,8 @@
+2005-04-08  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* files.el (find-file): Honour the coding system argument even in
+	the case where we're creating a new file. 
+
 2005-04-04  Steve Youngs  <steve@sxemacs.org>
 
 	* files.el (backup-buffer): Write "%backup%~" in
--- a/lisp/files.el	Thu Apr 07 21:51:47 2005 +0000
+++ b/lisp/files.el	Fri Apr 08 14:07:00 2005 +0000
@@ -864,12 +864,20 @@
 			  (read-coding-system "Coding system: "))
 		     t))
   (if codesys
-      (let ((coding-system-for-read
-	     (get-coding-system codesys)))
-	(let ((value (find-file-noselect filename nil nil wildcards)))
-	  (if (listp value)
-	      (mapcar 'switch-to-buffer (nreverse value))
-	    (switch-to-buffer value))))
+      (let* ((coding-system-for-read (get-coding-system codesys))
+	     (value (find-file-noselect filename nil nil wildcards))
+	     (bufname (if (listp value) (car (nreverse value)) value)))
+	;; If a user explicitly specified the coding system with a prefix
+	;; argument when opening a nonexistent file, insert-file-contents
+	;; hasn't preserved that coding system as the local
+	;; buffer-file-coding-system. Do that ourselves.
+	(unless (and bufname
+		     (file-exists-p (buffer-file-name bufname)) 
+		     (local-variable-p 'buffer-file-coding-system bufname))
+	  (save-excursion
+	    (set-buffer bufname)
+	    (setq buffer-file-coding-system coding-system-for-read)))
+	(switch-to-buffer bufname))
     (let ((value (find-file-noselect filename nil nil wildcards)))
       (if (listp value)
 	  (mapcar 'switch-to-buffer (nreverse value))