Subject: bug#1183: 23.0.60; ediff-buffers is broken

From: Eli Zaretskii <[email-masked]>
Date: Sun, 19 Oct 2008 10:32:53 +0200

Drew, please see if the patch below fixes the problem for you.

If you are not using a very recent CVS code, you will probably need to
use utf-8-emacs-unix instead of emacs-internal in the ediff-init.el
change, because emacs-internal was only introduced yesterday.

Michael, could you please add a warning message in buffer jobs about
differences in the values of buffer-file-coding-system between the
buffers being compared?  In particular, if there are no differences in
a region, but the above values are different, it would be good if
Ediff would say something like "only character-encoding differences"
instead of "only white-space differences".

Thanks.

2008-10-19  Eli Zaretskii  <[email-masked]>

	Fix Bug #1183:

	* ediff-diff.el (ediff-exec-process): For buffer jobs, bind
	coding-system-for-read to ediff-coding-system-for-write.

	* ediff-util.el (ediff-make-temp-file): Unconditionally bind
	coding-system-for-write to ediff-coding-system-for-write.

	* ediff-init.el (ediff-coding-system-for-read): Doc fix.
	(ediff-coding-system-for-write): Set to emacs-internal.

Index: lisp/ediff-init.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/ediff-init.el,v
retrieving revision 1.93
diff -u -r1.93 ediff-init.el
--- lisp/ediff-init.el	31 Jul 2008 05:33:43 -0000	1.93
+++ lisp/ediff-init.el	19 Oct 2008 08:20:30 -0000
@@ -719,17 +719,17 @@
 
 (defcustom ediff-coding-system-for-read 'raw-text
   "*The coding system for read to use when running the diff program as a subprocess.
-In most cases, the default will do. However, under certain circumstances in
-Windows NT/98/95 you might need to use something like 'raw-text-dos here.
+In most cases, the default will do.  However, under certain circumstances in
+MS-Windows you might need to use something like 'raw-text-dos here.
 So, if the output that your diff program sends to Emacs contains extra ^M's,
 you might need to experiment here, if the default or 'raw-text-dos doesn't
 work."
   :type 'symbol
   :group 'ediff)
 
-(defcustom ediff-coding-system-for-write 'no-conversion
+(defcustom ediff-coding-system-for-write 'emacs-internal
   "*The coding system for write to use when writing out difference regions
-to temp files when Ediff needs to find fine differences."
+to temp files in buffer jobs and when Ediff needs to find fine differences."
   :type 'symbol
   :group 'ediff)
 
Index: lisp/ediff-util.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/ediff-util.el,v
retrieving revision 1.93
diff -u -r1.93 ediff-util.el
--- lisp/ediff-util.el	31 Jul 2008 05:33:43 -0000	1.93
+++ lisp/ediff-util.el	19 Oct 2008 08:20:55 -0000
@@ -3146,11 +3146,7 @@
 (defun ediff-make-temp-file (buff &optional prefix given-file start end)
   (let* ((p (ediff-convert-standard-filename (or prefix "ediff")))
 	 (short-p p)
-	 (coding-system-for-write
-	  (ediff-with-current-buffer buff
-	    (if (boundp 'buffer-file-coding-system)
-		buffer-file-coding-system
-	      ediff-coding-system-for-write)))
+	 (coding-system-for-write ediff-coding-system-for-write)
 	 f short-f)
     (if (and (fboundp 'msdos-long-file-names)
 	     (not (msdos-long-file-names))
Index: lisp/ediff-diff.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/ediff-diff.el,v
retrieving revision 1.72
diff -u -r1.72 ediff-diff.el
--- lisp/ediff-diff.el	31 Jul 2008 05:33:42 -0000	1.72
+++ lisp/ediff-diff.el	19 Oct 2008 08:21:10 -0000
@@ -1207,7 +1207,13 @@
 ;; args.
 (defun ediff-exec-process (program buffer synch options &rest files)
   (let ((data (match-data))
-	(coding-system-for-read ediff-coding-system-for-read)
+	;; If this is a buffer job, we are diffing temporary files
+	;; produced by Emacs with ediff-coding-system-for-write, so
+	;; use the same encoding to read the results.
+	(coding-system-for-read
+	 (if (string-match "buffer" (symbol-name ediff-job-name))
+	     ediff-coding-system-for-write
+	   ediff-coding-system-for-read))
 	args)
     (setq args (append (split-string options) files))
     (setq args (delete "" (delq nil args))) ; delete nil and "" from arguments