Subject: CRLF on DOS_NT

From: Eli Zaretskii <[email-masked]>
Date: Sun, 13 Jul 1997 21:02:01 +0300 (IDT)

The following changes are required to make CRLF <-> LF conversion work
in most common cases.  I have deliberately not tried to get them into
final shape, since I need to learn more about the coding systems, and
because Geoff said he will work on that.  I didn't install these
changes, for these reasons (and also because I didn't have enough time
to do that today).

See also my other mail about the file format translation.

(Geoff, the `callproc.c' patch is DOS-specific, since that fragment is
for DOS only; you might consider looking up the relevant code for the
NT subprocess support.)

1997-07-10  Eli Zaretskii  <[email-masked]>

	* fileio.c (Fwrite_region) [DOS_NT]: Always use binary mode since
	coding conversion now takes care of NL -> CRLF.

*** src/fileio.c~0	Tue Jul  8 11:36:00 1997
--- src/fileio.c	Thu Jul 10 23:16:14 1997
*************** to the file, instead of any buffer conte
*** 3799,3806 ****
    struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
    struct buffer *given_buffer;
  #ifdef DOS_NT
!   int buffer_file_type
!     = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY;
  #endif /* DOS_NT */
    struct coding_system coding;
  
--- 3799,3805 ----
    struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
    struct buffer *given_buffer;
  #ifdef DOS_NT
!   int buffer_file_type = O_BINARY;
  #endif /* DOS_NT */
    struct coding_system coding;

1997-07-11  Eli Zaretskii  <[email-masked]>

	* callproc.c (Fcall_process) [MSDOS]: Request EOL conversion of
	the process output, unless we were promised it is binary.

*** src/callproc.c~0	Mon Jul  7 00:56:00 1997
--- src/callproc.c	Fri Jul 11 21:48:30 1997
*************** If you quit, the process is killed with 
*** 295,300 ****
--- 295,311 ----
  	      val = Qnil;
  	  }
  	setup_coding_system (Fcheck_coding_system (val), &process_coding);
+ #ifdef MSDOS
+ 	/* FIXME: this probably should be moved into the guts of
+ 	   `Ffind_operation_coding_system' for the case of `call-process'.  */
+ 	if (NILP (Vbinary_process_output))
+ 	  {
+ 	    process_coding.eol_type = CODING_EOL_CRLF;
+ 	    if (process_coding.type == coding_type_no_conversion)
+ 	      /* FIXME: should we set type to undecided?  */
+ 	      process_coding.type = coding_type_emacs_mule;
+ 	  }
+ #endif
        }
    }

---

From: Richard Stallman <[email-masked]>
Date: Fri, 18 Jul 1997 23:13:02 -0400

I've always interpreted the semantics of specifying 'nil' (text) in
    file-name-buffer-file-type-alist as being that you explicitly want
    CRLF separating lines.  For example, no matter what, you want
    config.sys to have CRLFs between the lines.

That is a good point.  So here's the change I've made.

But I wonder whether emacs-mule-dos is the right coding system
in other respects.  You've argued that -dos is right, but is
emacs-mule right?

*** dos-w32.el	1997/07/18 22:54:23	1.6
--- dos-w32.el	1997/07/19 03:10:17
***************
*** 102,128 ****
      If the match is nil (for text):			'emacs-mule-dos'
    Otherwise:
      If the file exists:					'undecided'
!     If the file does not exist:				'emacs-mule-dos'
  
  If COMMAND is 'write-region', the coding system is chosen based
  upon the value of 'buffer-file-type': If t, the coding system is
  'no-conversion', otherwise it is 'emacs-mule-dos'."
    (let ((op (nth 0 command))
  	(target)
! 	(binary)
  	(undecided nil))
      (cond ((eq op 'insert-file-contents) 
  	   (setq target (nth 1 command))
  	   (setq binary (find-buffer-file-type target))
! 	   (if (not binary)
! 	       (setq undecided 
! 		     (and (file-exists-p target)
! 			  (not (find-buffer-file-type-match target))))))
  	  ((eq op 'write-region) 
  	   (setq binary buffer-file-type)))
      (cond (binary '(no-conversion . no-conversion))
  	  (undecided '(undecided . undecided))
! 	  (t '(emacs-mule-dos . emacs-mule-dos)))))
  
  (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system)
  
--- 102,129 ----
      If the match is nil (for text):			'emacs-mule-dos'
    Otherwise:
      If the file exists:					'undecided'
!     If the file does not exist:				'undecided-dos'
  
  If COMMAND is 'write-region', the coding system is chosen based
  upon the value of 'buffer-file-type': If t, the coding system is
  'no-conversion', otherwise it is 'emacs-mule-dos'."
    (let ((op (nth 0 command))
  	(target)
! 	(binary nil) (text nil)
  	(undecided nil))
      (cond ((eq op 'insert-file-contents) 
  	   (setq target (nth 1 command))
  	   (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)))))
  	  ((eq op 'write-region) 
  	   (setq binary buffer-file-type)))
      (cond (binary '(no-conversion . no-conversion))
+ 	  (text '(emacs-mule-dos . emacs-mule-dos))
  	  (undecided '(undecided . undecided))
! 	  (t '(undecided-dos . undecided-dos)))))
  
  (modify-coding-system-alist 'file "" 'find-buffer-file-type-coding-system)