]> granicus.if.org Git - vim/commitdiff
patch 7.4.785 v7.4.785
authorBram Moolenaar <Bram@vim.org>
Fri, 17 Jul 2015 12:18:08 +0000 (14:18 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 17 Jul 2015 12:18:08 +0000 (14:18 +0200)
Problem:    On some systems automatically adding the missing EOL causes
            problems. Setting 'binary' has too many side effects.
Solution:   Add the 'fixeol' option, default on. (Pavel Samarkin)

21 files changed:
runtime/doc/options.txt
runtime/optwin.vim
src/buffer.c
src/fileio.c
src/memline.c
src/netbeans.c
src/ops.c
src/option.c
src/option.h
src/os_unix.c
src/os_win32.c
src/structs.h
src/testdir/Make_amiga.mak
src/testdir/Make_dos.mak
src/testdir/Make_ming.mak
src/testdir/Make_os2.mak
src/testdir/Make_vms.mms
src/testdir/Makefile
src/testdir/test_fixeol.in [new file with mode: 0644]
src/testdir/test_fixeol.ok [new file with mode: 0644]
src/version.c

index 209e1ba87ffc3a84df135e44693a97292870cee2..3b3e10405ff642bdde0236b37d3da51942924f0c 100644 (file)
@@ -1,4 +1,4 @@
-*options.txt*  For Vim version 7.4.  Last change: 2015 Jul 10
+*options.txt*  For Vim version 7.4.  Last change: 2015 Jul 17
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -2671,15 +2671,16 @@ A jump table for the options with a short description can be found at |Q_op|.
                        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.
+       is on, or 'fixeol' option is off, no <EOL> will be written for the
+       last line in the file.  This option is automatically set or reset when
+       starting to edit a new file, depending on whether file has an <EOL>
+       for the last line in the file.  Normally you don't have to set or
+       reset this option.
+       When 'binary' is off and 'fixeol' is on the value is not used when
+       writing the file.  When 'binary' is on or 'fixeol' is off 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.
 
                             *'equalalways'* *'ea'* *'noequalalways'* *'noea'*
 'equalalways' 'ea'     boolean (default on)
@@ -3064,6 +3065,17 @@ A jump table for the options with a short description can be found at |Q_op|.
          fold:c        Folded                  |hl-Folded|
          diff:c        DiffDelete              |hl-DiffDelete|
 
+               *'fixendofline'* *'fixeol'* *'nofixendofline'* *'nofixeol'*
+'fixendofline' 'fixeol'        boolean (default on)
+                       local to buffer
+                       {not in Vi}
+       When writing a file and this option is on, <EOL> at the end of file
+       will be restored if missing. Turn this option off if you want to
+       preserve the situation from the original file.
+       When the 'binary' option is set the value of this option doesn't
+       matter.
+       See the 'endofline' option.
+
                                        *'fkmap'* *'fk'* *'nofkmap'* *'nofk'*
 'fkmap' 'fk'           boolean (default off)                   *E198*
                        global
index 55353ce6699d5d62e53f62be87838f91e5d1d038..921ae36300c08e55da577fba64f586912e228e62 100644 (file)
@@ -954,6 +954,9 @@ call <SID>BinOptionL("bin")
 call append("$", "endofline\tlast line in the file has an end-of-line")
 call append("$", "\t(local to buffer)")
 call <SID>BinOptionL("eol")
+call append("$", "fixeol\tfixes missing end-of-line at end of text file")
+call append("$", "\t(local to buffer)")
+call <SID>BinOptionL("fixeol")
 if has("multi_byte")
   call append("$", "bomb\tprepend a Byte Order Mark to the file")
   call append("$", "\t(local to buffer)")
index 97c65960423bb9c78675c903ca63e86ed90d0237..c4d5e340baacc8d4d697f505faf890061a2bd527 100644 (file)
@@ -547,6 +547,7 @@ buf_clear_file(buf)
     buf->b_shortname = FALSE;
 #endif
     buf->b_p_eol = TRUE;
+    buf->b_p_fixeol = TRUE;
     buf->b_start_eol = TRUE;
 #ifdef FEAT_MBYTE
     buf->b_p_bomb = FALSE;
index 9965920c5c9984e320b34590f8d1f12cd11b6e47..fb14dbf7ee41fb24873b0637f02be3642e2a4aeb 100644 (file)
@@ -2623,10 +2623,10 @@ failed:
 #endif
 
     /*
-     * Trick: We remember if the last line of the read didn't have
-     * an eol even when 'binary' is off, for when writing it again with
-     * 'binary' on.  This is required for
-     * ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
+     * We remember if the last line of the read didn't have
+     * an eol even when 'binary' is off, to support turning 'fixeol' off,
+     * or writing the read again with 'binary' on.  The latter is required
+     * for ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
      */
     curbuf->b_no_eol_lnum = read_no_eol_lnum;
 
@@ -4547,7 +4547,7 @@ restore_backup:
        /* write failed or last line has no EOL: stop here */
        if (end == 0
                || (lnum == end
-                   && write_bin
+                   && (write_bin || !buf->b_p_fixeol)
                    && (lnum == buf->b_no_eol_lnum
                        || (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol))))
        {
index 91ef270bc30f79636ab3d09b42fdf255e133930f..8cd9b80b2ad21b1f8ac96a175dc200da7c107aec 100644 (file)
@@ -5361,8 +5361,10 @@ ml_find_line_or_offset(buf, lnum, offp)
        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 && buf->b_ml.ml_line_count == lnum)
+       /* Don't count the last line break if 'noeol' and ('bin' or
+        * 'nofixeol'). */
+       if ((!buf->b_p_fixeol || buf->b_p_bin) && !buf->b_p_eol
+                                          && buf->b_ml.ml_line_count == lnum)
            size -= ffdos + 1;
     }
 
index 68ca301d0755ef5af4d24afbe3f023061d5ef2b6..ea0c017ad6522d9273ba8df201b8fadd12d45a25 100644 (file)
@@ -3802,7 +3802,7 @@ get_buf_size(buf_T *bufp)
            }
        }
        /* Correction for when last line doesn't have an EOL. */
-       if (!bufp->b_p_eol && bufp->b_p_bin)
+       if (!bufp->b_p_eol && (bufp->b_p_bin || !bufp->b_p_fixeol))
            char_count -= eol_size;
     }
 
index 7ad8222e1c8a186286afabd4e3d4f85651aa12c3..3441f05ddeb258400ccba1b21631499b0903c6b1 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -7052,7 +7052,7 @@ cursor_pos_info()
                                           &char_count_cursor, len, eol_size);
                    if (lnum == curbuf->b_ml.ml_line_count
                            && !curbuf->b_p_eol
-                           && curbuf->b_p_bin
+                           && (curbuf->b_p_bin || !curbuf->b_p_fixeol)
                            && (long)STRLEN(s) < len)
                        byte_count_cursor -= eol_size;
                }
@@ -7076,7 +7076,7 @@ cursor_pos_info()
        }
 
        /* Correction for when last line doesn't have an EOL. */
-       if (!curbuf->b_p_eol && curbuf->b_p_bin)
+       if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol))
            byte_count -= eol_size;
 
        if (VIsual_active)
index 2e805d785ba6d5036c4e212e24632cfb486574eb..40dcc8d7b9f2bea053412cb40a9d35e4ebdb63b2 100644 (file)
@@ -98,6 +98,7 @@
 # define PV_INC                OPT_BOTH(OPT_BUF(BV_INC))
 #endif
 #define PV_EOL         OPT_BUF(BV_EOL)
+#define PV_FIXEOL      OPT_BUF(BV_FIXEOL)
 #define PV_EP          OPT_BOTH(OPT_BUF(BV_EP))
 #define PV_ET          OPT_BUF(BV_ET)
 #ifdef FEAT_MBYTE
@@ -306,6 +307,7 @@ static char_u       *p_cfu;
 static char_u  *p_ofu;
 #endif
 static int     p_eol;
+static int     p_fixeol;
 static int     p_et;
 #ifdef FEAT_MBYTE
 static char_u  *p_fenc;
@@ -1169,6 +1171,9 @@ static struct vimoption
                            {(char_u *)"", (char_u *)0L}
 #endif
                            SCRIPTID_INIT},
+    {"fixendofline",  "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
+                           (char_u *)&p_fixeol, PV_FIXEOL,
+                           {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
     {"fkmap",      "fk",   P_BOOL|P_VI_DEF,
 #ifdef FEAT_FKMAP
                            (char_u *)&p_fkmap, PV_NONE,
@@ -7781,6 +7786,11 @@ set_bool_option(opt_idx, varp, value, opt_flags)
     {
        redraw_titles();
     }
+    /* when 'fixeol' is changed, redraw the window title */
+    else if ((int *)varp == &curbuf->b_p_fixeol)
+    {
+       redraw_titles();
+    }
 # ifdef FEAT_MBYTE
     /* when 'bomb' is changed, redraw the window title and tab page text */
     else if ((int *)varp == &curbuf->b_p_bomb)
@@ -10176,6 +10186,7 @@ get_varp(p)
        case PV_OFU:    return (char_u *)&(curbuf->b_p_ofu);
 #endif
        case PV_EOL:    return (char_u *)&(curbuf->b_p_eol);
+       case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
        case PV_ET:     return (char_u *)&(curbuf->b_p_et);
 #ifdef FEAT_MBYTE
        case PV_FENC:   return (char_u *)&(curbuf->b_p_fenc);
@@ -11894,6 +11905,7 @@ save_file_ff(buf)
  * 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.
+ * Also when 'endofline' was changed and 'fixeol' is not set.
  * When "ignore_empty" is true don't consider a new, empty buffer to be
  * changed.
  */
@@ -11912,7 +11924,7 @@ file_ff_differs(buf, ignore_empty)
        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_p_bin || !buf->b_p_fixeol) && 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 7c7d35abfe8521217bc430dd895ea3be5c8efd02..819473befa1082e877f37eb28faf703277cb06bc 100644 (file)
@@ -962,6 +962,7 @@ enum
     , BV_INC
 #endif
     , BV_EOL
+    , BV_FIXEOL
     , BV_EP
     , BV_ET
     , BV_FENC
index 57c013f509908ae7258bb5e3fbd9e3f81a27200f..f53faa35a01a777ff2bb8ff6c243fa2b29c05db5 100644 (file)
@@ -4624,7 +4624,8 @@ mch_call_shell(cmd, options)
                                /* Finished a line, add a NL, unless this line
                                 * should not have one. */
                                if (lnum != curbuf->b_op_end.lnum
-                                       || !curbuf->b_p_bin
+                                       || (!curbuf->b_p_bin
+                                           && curbuf->b_p_fixeol)
                                        || (lnum != curbuf->b_no_eol_lnum
                                            && (lnum !=
                                                    curbuf->b_ml.ml_line_count
index b50ab95eb080bee73ae47fbcf3baee3fd011c259..1e1214b652c9893142736c4e9438a993308bb20f 100644 (file)
@@ -4173,7 +4173,8 @@ sub_process_writer(LPVOID param)
            /* Finished a line, add a NL, unless this line should not have
             * one. */
            if (lnum != curbuf->b_op_end.lnum
-               || !curbuf->b_p_bin
+               || (!curbuf->b_p_bin
+                   && curbuf->b_p_fixeol)
                || (lnum != curbuf->b_no_eol_lnum
                    && (lnum != curbuf->b_ml.ml_line_count
                        || curbuf->b_p_eol)))
index fedd3b96cda6001fa785acd90bba05713114e707..2c7f7108d483f6da3d91414f9fe1b2453c51b03e 100644 (file)
@@ -635,7 +635,7 @@ typedef struct memline
     int                ml_flags;
 
     infoptr_T  *ml_stack;      /* stack of pointer blocks (array of IPTRs) */
-    int                ml_stack_top;   /* current top if ml_stack */
+    int                ml_stack_top;   /* current top of ml_stack */
     int                ml_stack_size;  /* total number of entries in ml_stack */
 
     linenr_T   ml_line_lnum;   /* line number of cached line, 0 if not valid */
@@ -1586,6 +1586,7 @@ struct file_buffer
     char_u     *b_p_ofu;       /* 'omnifunc' */
 #endif
     int                b_p_eol;        /* 'endofline' */
+    int                b_p_fixeol;     /* 'fixendofline' */
     int                b_p_et;         /* 'expandtab' */
     int                b_p_et_nobin;   /* b_p_et saved for binary mode */
 #ifdef FEAT_MBYTE
index eba28f83e8be39968b0556d7aaef86fcb0745add..da4798980a1a04f70debdbcf55aa10e44698210c 100644 (file)
@@ -45,6 +45,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
                test_command_count.out \
                test_erasebackword.out \
                test_eval.out \
+               test_fixeol.out \
                test_increment.out \
                test_insertcount.out \
                test_listchars.out \
@@ -195,6 +196,7 @@ test_command_count.out: test_command_count.in
 test_erasebackword.out: test_erasebackword.in
 test_eval.out: test_eval.in
 test_increment.out: test_increment.in
+test_fixeol.out: test_fixeol.in
 test_insertcount.out: test_insertcount.in
 test_listchars.out: test_listchars.in
 test_listlbr.out: test_listlbr.in
index eecb7354d9a28019a71432cdb30db67d72ddeaf6..6bb0577692dc0815af7e5da850ffad542afb0c31 100644 (file)
@@ -44,6 +44,7 @@ SCRIPTS =     test3.out test4.out test5.out test6.out test7.out \
                test_command_count.out \
                test_erasebackword.out \
                test_eval.out \
+               test_fixeol.out \
                test_increment.out \
                test_insertcount.out \
                test_listchars.out \
index 29d931d1e41e7ae8a72bda0e721981df2d1d9e4c..faa2294c39d8499066863d22d104466bfd9cd1de 100644 (file)
@@ -66,6 +66,7 @@ SCRIPTS =     test3.out test4.out test5.out test6.out test7.out \
                test_command_count.out \
                test_erasebackword.out \
                test_eval.out \
+               test_fixeol.out \
                test_increment.out \
                test_insertcount.out \
                test_listchars.out \
index f473d8983c1a1a9019f73180c13a893c0f177fce..b93408c82f1520ea7324c0c40e0c154a0052e3ed 100644 (file)
@@ -46,6 +46,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
                test_command_count.out \
                test_erasebackword.out \
                test_eval.out \
+               test_fixeol.out \
                test_increment.out \
                test_insertcount.out \
                test_listchars.out \
index 437f9b1a210e1633579a135a077273e40c734626..1c6a56dc360ff7e73b0a2a4063f19abfe3443ba2 100644 (file)
@@ -4,7 +4,7 @@
 # Authors:     Zoltan Arpadffy, <arpadffy@polarhome.com>
 #              Sandor Kopanyi,  <sandor.kopanyi@mailbox.hu>
 #
-# Last change:  2015 Jul 10
+# Last change:  2015 Jul 17
 #
 # This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
 # Edit the lines in the Configuration section below to select.
@@ -105,6 +105,7 @@ SCRIPT = test1.out  test2.out  test3.out  test4.out  test5.out  \
         test_command_count.out \
         test_erasebackword.out \
         test_eval.out \
+        test_fixeol.out \
         test_increment.out \
         test_insertcount.out \
         test_listchars.out \
index 656a744519875c00ecbcf61e218020440676775f..1a3ff8509d6eca75f8c46ebfdd07407800aadf9d 100644 (file)
@@ -42,6 +42,7 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
                test_command_count.out \
                test_erasebackword.out \
                test_eval.out \
+               test_fixeol.out \
                test_increment.out \
                test_insertcount.out \
                test_listchars.out \
diff --git a/src/testdir/test_fixeol.in b/src/testdir/test_fixeol.in
new file mode 100644 (file)
index 0000000..a881fb1
--- /dev/null
@@ -0,0 +1,40 @@
+Tests for 'fixeol'                         vim: set ft=vim :
+STARTTEST
+:" first write two test files – with and without trailing EOL
+:" use Unix fileformat for consistency
+:set ff=unix
+:enew!
+awith eol\e:w! XXEol
+:enew!
+:set noeol nofixeol
+awithout eol\e:w! XXNoEol
+:set eol fixeol
+:bwipe XXEol XXNoEol
+:"
+:" try editing files with 'fixeol' disabled
+:e! XXEol
+ostays eol\e:set nofixeol
+:w! XXTestEol
+:e! XXNoEol
+ostays without\e:set nofixeol
+:w! XXTestNoEol
+:bwipe XXEol XXNoEol XXTestEol XXTestNoEol
+:set fixeol
+:"
+:" Append "END" to each file so that we can see what the last written char was.
+ggdGaEND\e:w >>XXEol
+:w >>XXNoEol
+:w >>XXTestEol
+:w >>XXTestNoEol
+:"
+:" Concatenate the results
+:e! test.out
+a0\e:$r XXEol
+:$r XXNoEol
+Go1\e:$r XXTestEol
+:$r XXTestNoEol
+:w
+:qa!
+ENDTEST
+
diff --git a/src/testdir/test_fixeol.ok b/src/testdir/test_fixeol.ok
new file mode 100644 (file)
index 0000000..68ac9be
--- /dev/null
@@ -0,0 +1,10 @@
+0
+with eol
+END
+without eolEND
+1
+with eol
+stays eol
+END
+without eol
+stays withoutEND
index 4907d68f5de3b027b5c514bb71b10c968ef12868..27a19ad53233e144a84c5e87f0af0f813b10c2a3 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    785,
 /**/
     784,
 /**/