aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/fileio.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-10-29 09:03:15 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-10-30 08:07:50 +0800
commitfeabc1c98cb077f60fde1a14e8540f2cf99eb8d2 (patch)
tree7cf648efe976fbac85e36f62964f1146b046aa54 /src/nvim/fileio.c
parent8d38e1ad34552293de9e562b73c727ec119fd847 (diff)
downloadrneovim-feabc1c98cb077f60fde1a14e8540f2cf99eb8d2.tar.gz
rneovim-feabc1c98cb077f60fde1a14e8540f2cf99eb8d2.tar.bz2
rneovim-feabc1c98cb077f60fde1a14e8540f2cf99eb8d2.zip
vim-patch:9.0.0816: CTRL-Z at end of file is always dropped
Problem: CTRL-Z at end of file is always dropped. Solution: Add the 'endoffile' option, like the 'endofline' option. (closes vim/vim#11408, closes vim/vim#11397) Cherry-pick test_fixeol.vim changes from patch 8.2.1432. Cherry-pick 'endoffile' changes from latest Vim runtime update. https://github.com/vim/vim/commit/fb0cf2357e0c85bbfd9f9178705ad8d77b6b3b4e vim-patch:f0b567e32a46 Revert unintended Makefile change https://github.com/vim/vim/commit/f0b567e32a462fe838170a202919d18b53eff987 vim-patch:72c8e3c070b3 Fix wrong struct access for member. https://github.com/vim/vim/commit/72c8e3c070b30f82bc0d203a62c168e43a13e99b vim-patch:3f68a4136eb9 Add missing entry for the 'endoffile' option. https://github.com/vim/vim/commit/3f68a4136eb99840d739af5133ab31948f273f63 Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/fileio.c')
-rw-r--r--src/nvim/fileio.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index cfdd6fe697..ae0340cdc6 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -525,6 +525,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip,
// correctly set when reading stdin.
if (!read_buffer) {
curbuf->b_p_eol = true;
+ curbuf->b_p_eof = false;
curbuf->b_start_eol = true;
}
curbuf->b_p_bomb = false;
@@ -1629,12 +1630,13 @@ 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);
@@ -3191,6 +3193,11 @@ 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