# 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)))
