Subject: "Binary" I/O and subprocesses on DOS_NT

From: Eli Zaretskii <[email-masked]>
Date: Thu, 28 Aug 1997 17:19:31 +0300 (IDT)

Here are my thoughts about this.

First, the word ``binary'' is loaded, and it got in the way when I worked 
on this.  binary-process-XXXput being non-nil doesn't really mean that 
data should be read or written with no conversions; it just means that 
EOLs should not be converted.  I can imagine cases where the rest of the 
text should be encoded or decoded even though the EOLs should be left 
alone.

Therefore, it is IMHO incorrect to set coding system to nil when binary 
I/O is specified.  We should only set the eol-type property.

The patch that I sent to you also avoids setting the EOL conversion of the
coding system was specified explicitly, to let the callers override the
value of binary-process-XXXput, if they need to do so. 

Geoff, I think that the code which sets the coding system on dos-w32.el 
should also be revised, so that it doesn't fall into this trap of 
``binary'' files.  The patterns for names of binary files in 
file-name-buffer-file-type-alist designate true binary files which should 
be read with no conversions at all, but the untranslated filesystems only 
specify the EOL conversion.  As far as I can see, the current code 
doesn't make that distinction.  In particular, when buffer-file-type is 
non-nil, it does NOT mean the coding system for write should be 
no-conversion, as dos-w32 sets it now.

And btw, why is the coding system for ASCII buffers (such as C source) 
set to undecided?  Shouldn't it be emacs-mule?

---

From: "Richard M. Stallman" <[email-masked]>
Date: Fri, 29 Aug 1997 14:19:59 -0400

I agree.

I agree in principle.  Implementing this in a fully satisfactory
way may be hard.

---

From: "Richard M. Stallman" <[email-masked]>
Date: Fri, 29 Aug 1997 14:21:43 -0400

doesn't make that distinction.

I've made changes (below) that I think solve these problems.
Can you please test them?  (These are in the .97 pretest too.)

  In particular, when buffer-file-type is 
    non-nil, it does NOT mean the coding system for write should be 
    no-conversion, as dos-w32 sets it now.

Please note that that code is used only when buffer-file-coding-system
is nil, which means, in a buffer that is not file-visiting.
As far as I can see, no-conversion is the right choice for that case.

*** dos-w32.el	1997/08/17 01:49:50	1.10
--- dos-w32.el	1997/08/29 18:17:38
***************
*** 72,89 ****
  	(setq alist (cdr alist)))
        found)))
  
  (defun find-buffer-file-type (filename)
!   ;; First check if file is on an untranslated filesystem, then on the alist.
!   (if (untranslated-file-p filename)
!       t ; for binary
!     (let ((match (find-buffer-file-type-match filename))
! 	  (code))
!       (if (not match)
! 	  default-buffer-file-type
! 	(setq code (cdr match))
! 	(cond ((memq code '(nil t)) code)
! 	      ((and (symbolp code) (fboundp code))
! 	       (funcall code filename)))))))
  
  (setq-default buffer-file-coding-system 'undecided-dos)
  
--- 72,87 ----
  	(setq alist (cdr alist)))
        found)))
  
+ ;; Don't check for untranslated file systems here.
  (defun find-buffer-file-type (filename)
!   (let ((match (find-buffer-file-type-match filename))
! 	(code))
!     (if (not match)
! 	default-buffer-file-type
!       (setq code (cdr match))
!       (cond ((memq code '(nil t)) code)
! 	    ((and (symbolp code) (fboundp code))
! 	     (funcall code filename))))))
  
  (setq-default buffer-file-coding-system 'undecided-dos)
  
***************
*** 123,142 ****
    (let ((op (nth 0 command))
  	(target)
  	(binary nil) (text nil)
! 	(undecided nil))
      (cond ((eq op 'insert-file-contents) 
  	   (setq target (nth 1 command))
! 	   (if (untranslated-file-p target)
! 	       (if (file-exists-p target)
! 		   (setq undecided t)
! 		 (setq binary t))
! 	     (setq binary (find-buffer-file-type target))
! 	     (unless binary
! 		     (if (find-buffer-file-type-match target)
! 			 (setq text t)
! 		       (setq undecided (file-exists-p target)))))
  	   (cond (binary '(no-conversion . no-conversion))
  		 (text '(undecided-dos . undecided-dos))
  		 (undecided '(undecided . undecided))
  		 (t '(undecided-dos . undecided-dos))))
  	  ((eq op 'write-region)
--- 121,145 ----
    (let ((op (nth 0 command))
  	(target)
  	(binary nil) (text nil)
! 	(undecided nil) (undecided-unix nil))
      (cond ((eq op 'insert-file-contents) 
  	   (setq target (nth 1 command))
! 	   ;; First check for a file name that indicates
! 	   ;; it is truly binary.
! 	   (setq binary (find-buffer-file-type target))
! 	   (cond (binary)
! 		 ;; Next check for files that MUST use DOS eol conversion.
! 		 ((find-buffer-file-type-match target)
! 		  (setq text t))
! 		 ;; For any other existing file, decide based on contents.
! 		 ((file-exists-p target)
! 		  (setq undecided t))
! 		 ;; Next check for a non-DOS file system.
! 		 ((untranslated-file-p target)
! 		  (setq undecided-unix t)))
  	   (cond (binary '(no-conversion . no-conversion))
  		 (text '(undecided-dos . undecided-dos))
+ 		 (undecided-unix '(undecided-unix . undecided-unix))
  		 (undecided '(undecided . undecided))
  		 (t '(undecided-dos . undecided-dos))))
  	  ((eq op 'write-region)