(insert-file-contents): Regard coding-system-magic-cookie if
authortomo <tomo>
Thu, 22 Jul 1999 10:06:45 +0000 (10:06 +0000)
committertomo <tomo>
Thu, 22 Jul 1999 10:06:45 +0000 (10:06 +0000)
`coding-system-for-read' is nil.

lisp/code-files.el

index c07749a..ab5fd15 100644 (file)
@@ -393,7 +393,7 @@ for reading.
 See also `insert-file-contents-access-hook',
 `insert-file-contents-pre-hook', `insert-file-contents-error-hook',
 and `insert-file-contents-post-hook'."
-  (let (return-val coding-system used-codesys)
+  (let (return-val coding-system cs used-codesys)
     ;; OK, first load the file.
     (condition-case err
        (progn
@@ -422,11 +422,24 @@ and `insert-file-contents-post-hook'."
                   "Invalid coding-system (%s), using 'undecided"
                   coding-system)
                  (setq coding-system 'undecided)))
-           (setq return-val
-                 (insert-file-contents-internal filename visit beg end
-                                                replace coding-system
-                                                ;; store here!
-                                                'used-codesys))
+           (save-restriction
+             (narrow-to-region (point)(point))
+             (setq return-val
+                   (insert-file-contents-internal filename visit beg end
+                                                  replace coding-system
+                                                  ;; store here!
+                                                  'used-codesys))
+             (or coding-system-for-read
+                 (null (setq cs (find-coding-system-magic-cookie)))
+                 (eq cs coding-system)
+                 (progn
+                   (delete-region (point-min)(point-max))
+                   (setq return-val
+                         (insert-file-contents-internal
+                          filename visit beg end
+                          replace cs
+                          ;; store here!
+                          'used-codesys)))))
            ))
       (file-error
        (run-hook-with-args 'insert-file-contents-error-hook