* epa-file.el (epa-file-decode-and-insert): New function which
authorueno <ueno>
Mon, 11 Sep 2006 04:08:07 +0000 (04:08 +0000)
committerueno <ueno>
Mon, 11 Sep 2006 04:08:07 +0000 (04:08 +0000)
utilizes decode-coding-inserted-region if available.
(epa-file-insert-file-contents): Use it.

ChangeLog
epa-file.el

index 48e1111..7edd188 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2006-09-11  Daiki Ueno  <ueno@unixuser.org>
 
+       * epa-file.el (epa-file-decode-and-insert): New function which
+       utilizes decode-coding-inserted-region if available.
+       (epa-file-insert-file-contents): Use it.
+
        * epg.el (epg--start): Specify --enable-progress-filter in
        imitation of GPGME.
        (epg-progress-callback-function): Remove a couple of %%'s.
index 4a59d8d..2b47373 100644 (file)
        (inhibit-file-name-operation operation))
     (apply operation args)))
 
+(defun epa-file-decode-and-insert (string file visit beg end replace)
+  (if (fboundp 'decode-coding-inserted-region)
+      (save-restriction
+       (narrow-to-region (point) (point))
+       (let ((multibyte enable-multibyte-characters))
+         (set-buffer-multibyte nil)
+         (insert string)
+         (set-buffer-multibyte multibyte)
+         (decode-coding-inserted-region
+          (point-min) (point-max)
+          (substring file 0 (string-match epa-file-name-regexp file))
+          visit beg end replace)))
+    (insert (decode-coding-string string (or coding-system-for-read
+                                            'undecided)))))
+
 (defvar last-coding-system-used)
 (defun epa-file-insert-file-contents (file &optional visit beg end replace)
   (barf-if-buffer-read-only)
                     (cons "Opening input file" (cdr error)))))
          (if (or beg end)
              (setq string (substring string (or beg 0) end)))
-         (setq string
-               (decode-coding-string string
-                                     (or coding-system-for-read 'undecided)))
-         (if (boundp 'last-coding-system-used)
-             (set-buffer-file-coding-system last-coding-system-used)
-           (set-buffer-file-coding-system default-buffer-file-coding-system))
          (save-excursion
-           (insert string)
-           (setq length (length string))
+           (save-restriction
+             (narrow-to-region (point) (point))
+             (epa-file-decode-and-insert string file visit beg end replace)
+             (setq length (- (point-max) (point-min))))
            (if replace
                (delete-region (point) (point-max)))))
       (if (and local-copy