On 23/01/11 3:31 AM, Marc Weber wrote:
This patch allows using ff=dos and noendofline and binary:

Is anyone interested in this patch - should I try feeding it upstream?

I think the attached old patch of mine is a better solution, allowing
noendofline to be used without binary. It doesn't break the losslessness
of 'binary' like your patch I think does.

I've attached the old version, that applies to Vim 7.2.something, and an
updated one that applies to the current Vim sources (it started clashing
due to the ff fix for empty buffers that just came through a day or so
ago).

It hasn't been very thoroughly tested, particularly with later Vim
versions. But I know it used to work fine for me.

I personally think its important that my beloved editor can write files
the way they are - because very often its best to keep things the way
they are. Changing eol behaviour is causing trouble in distributed dev
environments because diffs show that all lines have changed.

I agree.

But I'm pretty sure Bram doesn't.

And since this change does to some degree break backward compatibility,
I doubt he'll accept it.

I would be keen to find some kind of solution to this problem, though.
It is crazy that Vim can't write files unchanged with a simple option or
two. Not all of us want the last lines of our files 'fixed'.

Ben.



-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
# HG changeset patch
# Parent b6737bdf59bd624d46978dbc1999da3846db9d07
diff -r 64e8e5eacab2 runtime/doc/options.txt
--- a/runtime/doc/options.txt	Sun Jan 23 09:36:52 2011 +1100
+++ b/runtime/doc/options.txt	Sun Jan 23 09:39:29 2011 +1100
@@ -2557,16 +2557,16 @@
 'endofline' 'eol'	boolean	(default on)
 			local to buffer
 			{not in Vi}
-	When writing a file and this option is off and the 'binary' option
-	is on, no <EOL> will be written for the last line in the file.  This
-	option is automatically set when starting to edit a new file, unless
-	the file does not have an <EOL> for the last line in the file, in
-	which case it is reset.  Normally you don't have to set or reset this
-	option.  When 'binary' is off the value is not used when writing the
-	file.  When 'binary' is on it is used to remember the presence of a
-	<EOL> for the last line in the file, so that when you write the file
-	the situation from the original file can be kept.  But you can change
-	it if you want to.
+	When writing a file and this option is off, no <EOL> will be written
+	for the last line in the file.  This option is automatically set when
+	starting to edit a new file, unless the file does not have an <EOL>
+	for the last line in the file, in which case it is reset.  Normally
+	you don't have to set or reset this option, the situation from the
+	original file will be kept.  But you can change it if you want to.
+	If you prefer Vim to automatically add the <EOL> to text files that
+	don't have it, add the following to your .vimrc: >
+	    au BufWritePre * if !&bin | set eol | endif
+<
 
 			     *'equalalways'* *'ea'* *'noequalalways'* *'noea'*
 'equalalways' 'ea'	boolean	(default on)
diff -r 64e8e5eacab2 src/fileio.c
--- a/src/fileio.c	Sun Jan 23 09:36:52 2011 +1100
+++ b/src/fileio.c	Sun Jan 23 09:39:29 2011 +1100
@@ -4563,8 +4563,7 @@
 	/* write failed or last line has no EOL: stop here */
 	if (end == 0
 		|| (lnum == end
-		    && write_bin
-		    && (lnum == write_no_eol_lnum
+		    && ((write_bin && lnum == write_no_eol_lnum)
 			|| (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol))))
 	{
 	    ++lnum;			/* written the line, count it */
diff -r 64e8e5eacab2 src/memline.c
--- a/src/memline.c	Sun Jan 23 09:36:52 2011 +1100
+++ b/src/memline.c	Sun Jan 23 09:39:29 2011 +1100
@@ -5280,8 +5280,8 @@
 	if (ffdos)
 	    size += lnum - 1;
 
-	/* Don't count the last line break if 'bin' and 'noeol'. */
-	if (buf->b_p_bin && !buf->b_p_eol)
+	/* Don't count the last line break if 'noeol'. */
+	if (!buf->b_p_eol)
 	    size -= ffdos + 1;
     }
 
diff -r 64e8e5eacab2 src/netbeans.c
--- a/src/netbeans.c	Sun Jan 23 09:36:52 2011 +1100
+++ b/src/netbeans.c	Sun Jan 23 09:39:29 2011 +1100
@@ -3751,7 +3751,7 @@
 	    }
 	}
 	/* Correction for when last line doesn't have an EOL. */
-	if (!bufp->b_p_eol && bufp->b_p_bin)
+	if (!bufp->b_p_eol)
 	    char_count -= eol_size;
     }
 
diff -r 64e8e5eacab2 src/ops.c
--- a/src/ops.c	Sun Jan 23 09:36:52 2011 +1100
+++ b/src/ops.c	Sun Jan 23 09:39:29 2011 +1100
@@ -6451,7 +6451,6 @@
 					   &char_count_cursor, len, eol_size);
 		    if (lnum == curbuf->b_ml.ml_line_count
 			    && !curbuf->b_p_eol
-			    && curbuf->b_p_bin
 			    && (long)STRLEN(s) < len)
 			byte_count_cursor -= eol_size;
 		}
@@ -6476,7 +6475,7 @@
 	}
 
 	/* Correction for when last line doesn't have an EOL. */
-	if (!curbuf->b_p_eol && curbuf->b_p_bin)
+	if (!curbuf->b_p_eol)
 	    byte_count -= eol_size;
 
 #ifdef FEAT_VISUAL
diff -r 64e8e5eacab2 src/option.c
--- a/src/option.c	Sun Jan 23 09:36:52 2011 +1100
+++ b/src/option.c	Sun Jan 23 09:39:29 2011 +1100
@@ -8788,7 +8788,7 @@
     else
     {
 	/* Special case: 'modified' is b_changed, but we also want to consider
-	 * it set when 'ff' or 'fenc' changed. */
+	 * it set when 'ff', 'fenc' or 'eol' changed. */
 	if ((int *)varp == &curbuf->b_changed)
 	    *numval = curbufIsChanged();
 	else
@@ -9090,7 +9090,7 @@
 
     varp = get_varp_scope(p, opt_flags);
 
-    /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
+    /* for 'modified' we also need to check if 'ff', 'fenc' or 'eol' changed. */
     if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
 					? !curbufIsChanged() : !*(int *)varp))
 	MSG_PUTS("no");
@@ -11454,8 +11454,9 @@
 }
 
 /*
- * Save the current values of 'fileformat' and 'fileencoding', so that we know
- * the file must be considered changed when the value is different.
+ * Save the current values of 'fileformat', 'fileencoding' and 'endofline', so
+ * that we know the file must be considered changed when the value is
+ * different.
  */
     void
 save_file_ff(buf)
@@ -11477,10 +11478,9 @@
 }
 
 /*
- * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
- * from when editing started (save_file_ff() called).
- * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
- * changed and 'binary' is not set.
+ * Return TRUE if 'fileformat', 'fileencoding' and/or 'endofline' has a
+ * different value from when editing started (save_file_ff() called).
+ * Also when 'bomb' was changed and 'binary' is not set.
  * When "ignore_empty" is true don't consider a new, empty buffer to be
  * changed.
  */
@@ -11499,7 +11499,7 @@
 	return FALSE;
     if (buf->b_start_ffc != *buf->b_p_ff)
 	return TRUE;
-    if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
+    if (buf->b_start_eol != buf->b_p_eol)
 	return TRUE;
 #ifdef FEAT_MBYTE
     if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
diff -r 64e8e5eacab2 src/os_unix.c
--- a/src/os_unix.c	Sun Jan 23 09:36:52 2011 +1100
+++ b/src/os_unix.c	Sun Jan 23 09:39:29 2011 +1100
@@ -4244,8 +4244,8 @@
 				/* Finished a line, add a NL, unless this line
 				 * should not have one. */
 				if (lnum != curbuf->b_op_end.lnum
-					|| !curbuf->b_p_bin
-					|| (lnum != write_no_eol_lnum
+					|| ((!curbuf->b_p_bin
+					    || lnum != write_no_eol_lnum)
 					    && (lnum !=
 						    curbuf->b_ml.ml_line_count
 						    || curbuf->b_p_eol)))
Index: runtime/doc/options.txt
===================================================================
--- runtime/doc/options.txt	(revision 984)
+++ runtime/doc/options.txt	(working copy)
@@ -2391,16 +2391,16 @@
 'endofline' 'eol'	boolean	(default on)
 			local to buffer
 			{not in Vi}
-	When writing a file and this option is off and the 'binary' option
-	is on, no <EOL> will be written for the last line in the file.  This
-	option is automatically set when starting to edit a new file, unless
-	the file does not have an <EOL> for the last line in the file, in
-	which case it is reset.  Normally you don't have to set or reset this
-	option.  When 'binary' is off the value is not used when writing the
-	file.  When 'binary' is on it is used to remember the presence of a
-	<EOL> for the last line in the file, so that when you write the file
-	the situation from the original file can be kept.  But you can change
-	it if you want to.
+	When writing a file and this option is off, no <EOL> will be written
+	for the last line in the file.  This option is automatically set when
+	starting to edit a new file, unless the file does not have an <EOL>
+	for the last line in the file, in which case it is reset.  Normally
+	you don't have to set or reset this option, the situation from the
+	original file will be kept.  But you can change it if you want to.
+	If you prefer Vim to automatically add the <EOL> to text files that
+	don't have it, add the following to your .vimrc: >
+	    au BufWritePre * if !&bin | set eol | endif
+<
 
 			     *'equalalways'* *'ea'* *'noequalalways'* *'noea'*
 'equalalways' 'ea'	boolean	(default on)
Index: src/netbeans.c
===================================================================
--- src/netbeans.c	(revision 984)
+++ src/netbeans.c	(working copy)
@@ -3455,7 +3455,7 @@
 	    }
 	}
 	/* Correction for when last line doesn't have an EOL. */
-	if (!bufp->b_p_eol && bufp->b_p_bin)
+	if (!bufp->b_p_eol)
 	    char_count -= eol_size;
     }
 
Index: src/option.c
===================================================================
--- src/option.c	(revision 984)
+++ src/option.c	(working copy)
@@ -8192,7 +8192,7 @@
     else
     {
 	/* Special case: 'modified' is b_changed, but we also want to consider
-	 * it set when 'ff' or 'fenc' changed. */
+	 * it set when 'ff', 'fenc' or 'eol' changed. */
 	if ((int *)varp == &curbuf->b_changed)
 	    *numval = curbufIsChanged();
 	else
@@ -8494,7 +8494,7 @@
 
     varp = get_varp_scope(p, opt_flags);
 
-    /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
+    /* for 'modified' we also need to check if 'ff', 'fenc' or 'eol' changed. */
     if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
 					? !curbufIsChanged() : !*(int *)varp))
 	MSG_PUTS("no");
@@ -10623,8 +10623,9 @@
 }
 
 /*
- * Save the current values of 'fileformat' and 'fileencoding', so that we know
- * the file must be considered changed when the value is different.
+ * Save the current values of 'fileformat', 'fileencoding' and 'endofline', so
+ * that we know the file must be considered changed when the value is
+ * different.
  */
     void
 save_file_ff(buf)
@@ -10646,10 +10647,9 @@
 }
 
 /*
- * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
- * from when editing started (save_file_ff() called).
- * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
- * changed and 'binary' is not set.
+ * Return TRUE if 'fileformat', 'fileencoding' and/or 'endofline' has a
+ * different value from when editing started (save_file_ff() called).
+ * Also when 'bomb' was changed and 'binary' is not set.
  * Don't consider a new, empty buffer to be changed.
  */
     int
@@ -10665,7 +10665,7 @@
 	return FALSE;
     if (buf->b_start_ffc != *buf->b_p_ff)
 	return TRUE;
-    if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
+    if (buf->b_start_eol != buf->b_p_eol)
 	return TRUE;
 #ifdef FEAT_MBYTE
     if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
Index: src/os_unix.c
===================================================================
--- src/os_unix.c	(revision 984)
+++ src/os_unix.c	(working copy)
@@ -4022,8 +4022,8 @@
 				/* Finished a line, add a NL, unless this line
 				 * should not have one. */
 				if (lnum != curbuf->b_op_end.lnum
-					|| !curbuf->b_p_bin
-					|| (lnum != write_no_eol_lnum
+					|| ((!curbuf->b_p_bin
+					    || lnum != write_no_eol_lnum)
 					    && (lnum !=
 						    curbuf->b_ml.ml_line_count
 						    || curbuf->b_p_eol)))
Index: src/memline.c
===================================================================
--- src/memline.c	(revision 984)
+++ src/memline.c	(working copy)
@@ -4812,8 +4812,8 @@
 	if (ffdos)
 	    size += lnum - 1;
 
-	/* Don't count the last line break if 'bin' and 'noeol'. */
-	if (buf->b_p_bin && !buf->b_p_eol)
+	/* Don't count the last line break if 'noeol'. */
+	if (!buf->b_p_eol)
 	    size -= ffdos + 1;
     }
 
Index: src/ops.c
===================================================================
--- src/ops.c	(revision 984)
+++ src/ops.c	(working copy)
@@ -6332,7 +6332,6 @@
 					   &char_count_cursor, len, eol_size);
 		    if (lnum == curbuf->b_ml.ml_line_count
 			    && !curbuf->b_p_eol
-			    && curbuf->b_p_bin
 			    && (long)STRLEN(s) < len)
 			byte_count_cursor -= eol_size;
 		}
@@ -6357,7 +6356,7 @@
 	}
 
 	/* Correction for when last line doesn't have an EOL. */
-	if (!curbuf->b_p_eol && curbuf->b_p_bin)
+	if (!curbuf->b_p_eol)
 	    byte_count -= eol_size;
 
 #ifdef FEAT_VISUAL
Index: src/fileio.c
===================================================================
--- src/fileio.c	(revision 984)
+++ src/fileio.c	(working copy)
@@ -4201,8 +4205,7 @@
 	/* write failed or last line has no EOL: stop here */
 	if (end == 0
 		|| (lnum == end
-		    && write_bin
-		    && (lnum == write_no_eol_lnum
+		    && ((write_bin && lnum == write_no_eol_lnum)
 			|| (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol))))
 	{
 	    ++lnum;			/* written the line, count it */

Reply via email to