changeset 81049:e41bb5f56da5

(tar-file-name-handler): New function. (tar-extract): Bind file-name-handler-alist to it to force find-buffer-file-type-coding-system behave as if the file being extracted existed. Use last-coding-system-used to force buffer-file-coding-system to what decode-coding-region actually used to decode the file.
author Eli Zaretskii <eliz@gnu.org>
date Wed, 23 May 2007 12:38:35 +0000
parents 3b0453fee5b3
children f71cf00a1150
files lisp/tar-mode.el
diffstat 1 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/tar-mode.el	Wed May 23 08:12:59 2007 +0000
+++ b/lisp/tar-mode.el	Wed May 23 12:38:35 2007 +0000
@@ -681,6 +681,12 @@
   (goto-char (posn-point (event-end event)))
   (tar-extract))
 
+(defun tar-file-name-handler (op &rest args)
+  "Helper function for `tar-extract'."
+  (or (eq op 'file-exists-p)
+      (let ((file-name-handler-alist nil))
+	(apply op args))))
+
 (defun tar-extract (&optional other-window-p)
   "In Tar mode, extract this entry of the tar file into its own buffer."
   (interactive)
@@ -735,9 +741,17 @@
 				  (save-excursion
 				    (funcall set-auto-coding-function
 					     name (- (point-max) (point)))))
-			     (car (find-operation-coding-system
-				   'insert-file-contents
-				   (cons name (current-buffer)) t))))
+			     ;; The following binding causes
+			     ;; find-buffer-file-type-coding-system
+			     ;; (defined on dos-w32.el) to act as if
+			     ;; the file being extracted existed, so
+			     ;; that the file's contents' encoding is
+			     ;; auto-detected.
+			     (let ((file-name-handler-alist
+				    '(("" . tar-file-name-handler))))
+			       (car (find-operation-coding-system
+				     'insert-file-contents
+				     (cons name (current-buffer)) t)))))
 			(multibyte enable-multibyte-characters)
 			(detected (detect-coding-region
 				   (point-min)
@@ -758,7 +772,9 @@
 			      (coding-system-change-text-conversion
 			       coding 'raw-text)))
 		    (decode-coding-region (point-min) (point-max) coding)
-		    (set-buffer-file-coding-system coding))
+		    ;; Force buffer-file-coding-system to what
+		    ;; decode-coding-region actually used.
+		    (set-buffer-file-coding-system last-coding-system-used t))
 		  ;; Set the default-directory to the dir of the
 		  ;; superior buffer.
 		  (setq default-directory