(insert-file-contents): fixed.
authortomo <tomo>
Thu, 29 Jul 1999 07:33:46 +0000 (07:33 +0000)
committertomo <tomo>
Thu, 29 Jul 1999 07:33:46 +0000 (07:33 +0000)
lisp/code-files.el

index ab5fd15..3a014ad 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 cs used-codesys)
+  (let (return-val coding-system cs used-codesys p)
     ;; OK, first load the file.
     (condition-case err
        (progn
@@ -422,24 +422,30 @@ and `insert-file-contents-post-hook'."
                   "Invalid coding-system (%s), using 'undecided"
                   coding-system)
                  (setq coding-system 'undecided)))
-           (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)))))
+           (setq p (point))
+           (setq return-val
+                 (insert-file-contents-internal filename visit beg end
+                                                (and coding-system-for-read
+                                                     replace)
+                                                coding-system
+                                                ;; store here!
+                                                'used-codesys))
+           (unless coding-system-for-read
+             (if (or (null (setq cs (find-coding-system-magic-cookie)))
+                     (eq cs used-codesys)
+                     (eq cs (coding-system-name
+                             (coding-system-base used-codesys))))
+                 (if replace
+                     (let* ((len (nth 1 return-val))
+                            (end (+ p len)))
+                       (delete-region end (+ end len))))
+               (delete-region p (+ p (nth 1 return-val)))
+               (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