To: vim_dev@googlegroups.com Subject: Patch 9.0.0816 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0816 Problem: CTRL-Z at end of file is always dropped. Solution: Add the 'endoffile' option, like the 'endofline' option. (closes #11408, closes #11397) Files: runtime/doc/options.txt, src/optiondefs.h, src/option.h, src/structs.h, src/fileio.c, src/bufwrite.c, src/testdir/test_fixeol.vim *** ../vim-9.0.0815/runtime/doc/options.txt 2022-10-15 16:04:43.994187227 +0100 --- runtime/doc/options.txt 2022-10-22 08:05:51.595164161 +0100 *** ../vim-9.0.0815/src/optiondefs.h 2022-10-15 16:04:43.994187227 +0100 --- src/optiondefs.h 2022-10-22 08:35:21.235445848 +0100 *************** *** 61,66 **** --- 61,67 ---- # 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,852 **** {"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, (char_u *)&p_emoji, PV_NONE, {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, --- 847,853 ---- {"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, (char_u *)&p_emoji, PV_NONE, {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, *************** *** 854,859 **** --- 855,863 ---- (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}, *** ../vim-9.0.0815/src/option.h 2022-10-15 16:04:43.998187220 +0100 --- src/option.h 2022-10-22 08:06:35.771137201 +0100 *************** *** 555,560 **** --- 555,561 ---- 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,1128 **** --- 1124,1130 ---- , BV_DEF , BV_INC #endif + , BV_EOF , BV_EOL , BV_FIXEOL , BV_EP *** ../vim-9.0.0815/src/structs.h 2022-10-15 16:25:23.982973900 +0100 --- src/structs.h 2022-10-22 08:29:32.087180705 +0100 *************** *** 2999,3004 **** --- 2999,3005 ---- 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' *** ../vim-9.0.0815/src/fileio.c 2022-08-26 16:41:10.037072416 +0100 --- src/fileio.c 2022-10-22 08:30:02.755208344 +0100 *************** *** 590,595 **** --- 590,596 ---- if (!read_buffer) { curbuf->b_p_eol = TRUE; + curbuf->b_p_eof = FALSE; curbuf->b_start_eol = TRUE; } curbuf->b_p_bomb = FALSE; *************** *** 2278,2290 **** && !got_int && linerest != 0 && !(!curbuf->b_p_bin ! && fileformat == EOL_DOS ! && *line_start == Ctrl_Z ! && ptr == line_start + 1)) { // remember for when writing if (set_options) curbuf->b_p_eol = FALSE; *ptr = NUL; len = (colnr_T)(ptr - line_start + 1); if (ml_append(lnum, line_start, len, newfile) == FAIL) --- 2279,2293 ---- && !got_int && linerest != 0 && !(!curbuf->b_p_bin ! && 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) *** ../vim-9.0.0815/src/bufwrite.c 2022-09-20 11:49:06.007787298 +0100 --- src/bufwrite.c 2022-10-22 08:37:55.487537322 +0100 *************** *** 2050,2055 **** --- 2050,2059 ---- len = 0; write_info.bw_start_lnum = lnum; } + if (!buf->b_p_fixeol && buf->b_p_eof) + // write trailing CTRL-Z + (void)write_eintr(ip->bw_fd, "\x1a", 1); + // write failed or last line has no EOL: stop here if (end == 0 || (lnum == end *** ../vim-9.0.0815/src/testdir/test_fixeol.vim 2020-08-12 17:43:41.000000000 +0100 --- src/testdir/test_fixeol.vim 2022-10-22 08:42:14.091775840 +0100 *************** *** 1,17 **** ! " Tests for 'fixeol' 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') w! XXEol enew! ! set noeol nofixeol ! call setline('.', 'without eol') w! XXNoEol ! set eol fixeol bwipe XXEol XXNoEol " try editing files with 'fixeol' disabled --- 1,17 ---- ! " 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 or eof') w! XXEol enew! ! set noeof noeol nofixeol ! call setline('.', 'without eol or eof') w! XXNoEol ! set eol eof fixeol bwipe XXEol XXNoEol " try editing files with 'fixeol' disabled *************** *** 44,50 **** call delete('XXNoEol') call delete('XXTestEol') call delete('XXTestNoEol') ! set ff& fixeol& eol& enew! endfunc --- 44,50 ---- call delete('XXNoEol') call delete('XXTestEol') call delete('XXTestNoEol') ! set ff& fixeol& eof& eol& enew! endfunc *** ../vim-9.0.0815/src/version.c 2022-10-22 07:54:22.951580569 +0100 --- src/version.c 2022-10-22 08:07:15.295113057 +0100 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 816, /**/ -- CART DRIVER: Bring out your dead! We follow the cart through a wretched, impoverished plague-ridden village. A few starved mongrels run about in the mud scavenging. In the open doorway of one house perhaps we jug glimpse a pair of legs dangling from the ceiling. In another doorway an OLD WOMAN is beating a cat against a wall rather like one does with a mat. The cart passes round a dead donkey or cow in the mud. And a MAN tied to a cart is being hammered to death by four NUNS with huge mallets. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///