diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-10-22 11:25:19 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-10-22 11:25:19 +0100 |
commit | fb0cf2357e0c85bbfd9f9178705ad8d77b6b3b4e (patch) | |
tree | 25307998711d15645e29dac9ba83815a31f1fb4d /src | |
parent | 9c50eeb40117413bf59a9da904c8d0921ed0a6e6 (diff) |
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/bufwrite.c | 4 | ||||
-rw-r--r-- | src/ex_cmds.c | 2 | ||||
-rw-r--r-- | src/fileio.c | 9 | ||||
-rw-r--r-- | src/option.h | 2 | ||||
-rw-r--r-- | src/optiondefs.h | 6 | ||||
-rw-r--r-- | src/structs.h | 1 | ||||
-rw-r--r-- | src/testdir/test_fixeol.vim | 12 | ||||
-rw-r--r-- | src/version.c | 4 |
9 files changed, 29 insertions, 13 deletions
diff --git a/src/Makefile b/src/Makefile index bd6c187554..4b342da6b5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -355,7 +355,7 @@ CClink = $(CC) #CONF_OPT_GUI = --enable-gui=gnome2 --disable-gtktest #CONF_OPT_GUI = --enable-gui=gtk3 #CONF_OPT_GUI = --enable-gui=gtk3 --disable-gtktest -#CONF_OPT_GUI = --enable-gui=motif +CONF_OPT_GUI = --enable-gui=motif #CONF_OPT_GUI = --enable-gui=motif --with-motif-lib="-static -lXm -shared" # Uncomment this line to run an individual test with gvim. diff --git a/src/bufwrite.c b/src/bufwrite.c index 3ff7fb3390..713dac561f 100644 --- a/src/bufwrite.c +++ b/src/bufwrite.c @@ -2050,6 +2050,10 @@ restore_backup: len = 0; write_info.bw_start_lnum = lnum; } + if (!buf->b_p_fixeol && buf->b_p_eof) + // write trailing CTRL-Z + (void)write_eintr(write_info->bw_fd, "\x1a", 1); + // write failed or last line has no EOL: stop here if (end == 0 || (lnum == end diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 676ab704b3..44333d514c 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -929,8 +929,6 @@ do_bang( STRCAT(t, newcmd); if (ins_prevcmd) STRCAT(t, prevcmd); - else - vim_free(t); p = t + STRLEN(t); STRCAT(t, trailarg); vim_free(newcmd); diff --git a/src/fileio.c b/src/fileio.c index 701521a419..ab867b7c8f 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -590,6 +590,7 @@ readfile( if (!read_buffer) { curbuf->b_p_eol = TRUE; + curbuf->b_p_eof = FALSE; curbuf->b_start_eol = TRUE; } curbuf->b_p_bomb = FALSE; @@ -2278,13 +2279,15 @@ failed: && !got_int && linerest != 0 && !(!curbuf->b_p_bin - && fileformat == EOL_DOS - && *line_start == Ctrl_Z - && ptr == line_start + 1)) + && fileformat == EOL_DOS)) { // remember for when writing if (set_options) + { curbuf->b_p_eol = FALSE; + if (*line_start == Ctrl_Z && ptr == line_start + 1) + curbuf->b_p_eof = FALSE; + } *ptr = NUL; len = (colnr_T)(ptr - line_start + 1); if (ml_append(lnum, line_start, len, newfile) == FAIL) diff --git a/src/option.h b/src/option.h index e266d387ea..eed12e8378 100644 --- a/src/option.h +++ b/src/option.h @@ -555,6 +555,7 @@ EXTERN char_u *p_efm; // 'errorformat' EXTERN char_u *p_gefm; // 'grepformat' EXTERN char_u *p_gp; // 'grepprg' #endif +EXTERN int p_eof; // 'endoffile' EXTERN int p_eol; // 'endofline' EXTERN int p_ek; // 'esckeys' EXTERN char_u *p_ei; // 'eventignore' @@ -1123,6 +1124,7 @@ enum , BV_DEF , BV_INC #endif + , BV_EOF , BV_EOL , BV_FIXEOL , BV_EP diff --git a/src/optiondefs.h b/src/optiondefs.h index 9ea8602905..43a334fc07 100644 --- a/src/optiondefs.h +++ b/src/optiondefs.h @@ -61,6 +61,7 @@ # define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF)) # define PV_INC OPT_BOTH(OPT_BUF(BV_INC)) #endif +#define PV_EOF OPT_BUF(BV_EOF) #define PV_EOL OPT_BUF(BV_EOL) #define PV_FIXEOL OPT_BUF(BV_FIXEOL) #define PV_EP OPT_BOTH(OPT_BUF(BV_EP)) @@ -846,7 +847,7 @@ static struct vimoption options[] = {"edcompatible","ed", P_BOOL|P_VI_DEF, (char_u *)&p_ed, PV_NONE, {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, - {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR, + {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR, (char_u *)&p_emoji, PV_NONE, {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, @@ -854,6 +855,9 @@ static struct vimoption options[] = (char_u *)&p_enc, PV_NONE, {(char_u *)ENC_DFLT, (char_u *)0L} SCTX_INIT}, + {"endoffile", "eof", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT, + (char_u *)&p_eof, PV_EOF, + {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT, (char_u *)&p_eol, PV_EOL, {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, diff --git a/src/structs.h b/src/structs.h index bc3d8cb07f..02c9c2adad 100644 --- a/src/structs.h +++ b/src/structs.h @@ -2999,6 +2999,7 @@ struct file_buffer char_u *b_p_tfu; // 'tagfunc' option value callback_T b_tfu_cb; // 'tagfunc' callback #endif + int b_p_eof; // 'endoffile' int b_p_eol; // 'endofline' int b_p_fixeol; // 'fixendofline' int b_p_et; // 'expandtab' diff --git a/src/testdir/test_fixeol.vim b/src/testdir/test_fixeol.vim index e97bf004f1..3ede84f49e 100644 --- a/src/testdir/test_fixeol.vim +++ b/src/testdir/test_fixeol.vim @@ -1,17 +1,17 @@ -" Tests for 'fixeol' and 'eol' +" Tests for 'fixeol', 'eof' and 'eol' func Test_fixeol() " first write two test files – with and without trailing EOL " use Unix fileformat for consistency set ff=unix enew! - call setline('.', 'with eol') + call setline('.', 'with eol or eof') w! XXEol enew! - set noeol nofixeol - call setline('.', 'without eol') + set noeof noeol nofixeol + call setline('.', 'without eol or eof') w! XXNoEol - set eol fixeol + set eol eof fixeol bwipe XXEol XXNoEol " try editing files with 'fixeol' disabled @@ -44,7 +44,7 @@ func Test_fixeol() call delete('XXNoEol') call delete('XXTestEol') call delete('XXTestNoEol') - set ff& fixeol& eol& + set ff& fixeol& eof& eol& enew! endfunc diff --git a/src/version.c b/src/version.c index 237cd7c40a..e9f9f12608 100644 --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,10 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 817, +/**/ + 816, +/**/ 815, /**/ 814, |