[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EOL conversion of files in .tar archives

From: Eli Zaretskii
Subject: Re: EOL conversion of files in .tar archives
Date: Tue, 22 May 2007 14:19:14 +0300

> From: Kenichi Handa <address@hidden>
> CC: address@hidden
> Date: Mon, 21 May 2007 13:48:20 +0900
> In article <address@hidden>, Eli Zaretskii <address@hidden> writes:
> > Lately I noticed that, in the Windows port of Emacs, visiting files in
> > .tar archives shows them as if they had DOS EOLs, even though the
> > files have Unix EOLs.  (This is not due to some recent change: it
> > looks like Emacs behaved like that since before the pretest.)
> > Is this intentional, or should I debug it?  If the former, can someone
> > explain the rationale?
> I think it is a bug of find-buffer-file-type-coding-system
> (dos-w32.el).  If TARGET is (FILENAME . BUFFER), it should
> assume that the file contents is available.  Could you
> verify that the attached patch is correct?

I'm uneasy about patching find-buffer-file-type-coding-system at this
stage, since it is so widely used.  For example,
decode-coding-inserted-region also invokes
find-operation-coding-system with second argument a cons cell, and it
is not clear to me that your change will DTRT in that case.

I'd like to suggest an alternative change that is local to
tar-mode.el, see below.  It mimics what arc-mode.el does.

This solves the problem with the EOL decoding, but reveals a very
strange phenomenon: dos-w32.el and dos-w32.elc behave differently.
The latter is preloaded into Emacs on Windows, and if I visit a file
inside a tarball (after applying the patch below), plain text files
with Unix EOLs get latin-1-unix buffer-file-coding-system, instead of
the expected undecided-unix.  But if I manually load dos-w32.el and
visit the same file again, its buffer-file-coding-system is now
undecided-unix, as expected!  Is this some problem with the byte

Index: lisp/tar-mode.el
RCS file: /cvsroot/emacs/emacs/lisp/tar-mode.el,v
retrieving revision 1.108
diff -u -r1.108 tar-mode.el
--- lisp/tar-mode.el    21 Jan 2007 03:53:10 -0000      1.108
+++ lisp/tar-mode.el    22 May 2007 11:18:19 -0000
@@ -681,6 +681,12 @@
   (goto-char (posn-point (event-end event)))
+(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."
@@ -735,9 +741,17 @@
                                    (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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]