From 309296545cf0c8556d82f81703eef4cdc7e539d3 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 31 Jul 2019 21:42:47 -0400 Subject: [PATCH 1/4] vim-patch:8.1.1780: warning for file no longer available is repeated Problem: Warning for file no longer available is repeated every time Vim is focused. (Brian Armstrong) Solution: Only give the message once. (closes vim/vim#4748) https://github.com/vim/vim/commit/674e2bde6e7b0c468f304713aa8f97a45e1fcc89 --- src/nvim/fileio.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 907e6c978a..82cf79722e 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4840,6 +4840,8 @@ buf_check_timestamp( || time_differs(file_info.stat.st_mtim.tv_sec, buf->b_mtime) || (int)file_info.stat.st_mode != buf->b_orig_mode )) { + const long prev_b_mtime = buf->b_mtime; + retval = 1; // set b_mtime to stop further warnings (e.g., when executing @@ -4903,9 +4905,12 @@ buf_check_timestamp( return 2; } if (!n) { - if (*reason == 'd') - mesg = _("E211: File \"%s\" no longer available"); - else { + if (*reason == 'd') { + // Only give the message once. + if (prev_b_mtime != -1) { + mesg = _("E211: File \"%s\" no longer available"); + } + } else { helpmesg = TRUE; can_reload = TRUE; /* From 28946c285b41f199ae1d2ddd214e57b7f442fbb1 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 1 Aug 2019 04:20:35 -0400 Subject: [PATCH 2/4] lint --- src/nvim/fileio.c | 75 ++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 82cf79722e..56c74fbfd6 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4807,13 +4807,12 @@ buf_check_timestamp( char_u *path; char *mesg = NULL; char *mesg2 = ""; - int helpmesg = FALSE; - int reload = FALSE; - int can_reload = FALSE; + bool helpmesg = false; + bool reload = false; + bool can_reload = false; uint64_t orig_size = buf->b_orig_size; int orig_mode = buf->b_orig_mode; - static int busy = FALSE; - int n; + static bool busy = false; char_u *s; char *reason; @@ -4838,8 +4837,7 @@ buf_check_timestamp( && buf->b_mtime != 0 && (!(file_info_ok = os_fileinfo((char *)buf->b_ffname, &file_info)) || time_differs(file_info.stat.st_mtim.tv_sec, buf->b_mtime) - || (int)file_info.stat.st_mode != buf->b_orig_mode - )) { + || (int)file_info.stat.st_mode != buf->b_orig_mode)) { const long prev_b_mtime = buf->b_mtime; retval = 1; @@ -4858,28 +4856,25 @@ buf_check_timestamp( /* Don't do anything for a directory. Might contain the file * explorer. */ - if (os_isdir(buf->b_fname)) - ; - - /* - * If 'autoread' is set, the buffer has no changes and the file still - * exists, reload the buffer. Use the buffer-local option value if it - * was set, the global option value otherwise. - */ - else if ((buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar) - && !bufIsChanged(buf) && file_info_ok) - reload = TRUE; - else { - if (!file_info_ok) + if (os_isdir(buf->b_fname)) { + } else if ((buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar) + && !bufIsChanged(buf) && file_info_ok) { + // If 'autoread' is set, the buffer has no changes and the file still + // exists, reload the buffer. Use the buffer-local option value if it + // was set, the global option value otherwise. + reload = true; + } else { + if (!file_info_ok) { reason = "deleted"; - else if (bufIsChanged(buf)) + } else if (bufIsChanged(buf)) { reason = "conflict"; - else if (orig_size != buf->b_orig_size || buf_contents_changed(buf)) + } else if (orig_size != buf->b_orig_size || buf_contents_changed(buf)) { reason = "changed"; - else if (orig_mode != buf->b_orig_mode) + } else if (orig_mode != buf->b_orig_mode) { reason = "mode"; - else + } else { reason = "time"; + } // Only give the warning if there are no FileChangedShell // autocommands. @@ -4888,8 +4883,8 @@ buf_check_timestamp( set_vim_var_string(VV_FCS_REASON, reason, -1); set_vim_var_string(VV_FCS_CHOICE, "", -1); allbuf_lock++; - n = apply_autocmds(EVENT_FILECHANGEDSHELL, - buf->b_fname, buf->b_fname, false, buf); + bool n = apply_autocmds(EVENT_FILECHANGEDSHELL, + buf->b_fname, buf->b_fname, false, buf); allbuf_lock--; busy = false; if (n) { @@ -4897,12 +4892,13 @@ buf_check_timestamp( EMSG(_("E246: FileChangedShell autocommand deleted buffer")); } s = get_vim_var_str(VV_FCS_CHOICE); - if (STRCMP(s, "reload") == 0 && *reason != 'd') - reload = TRUE; - else if (STRCMP(s, "ask") == 0) - n = FALSE; - else + if (STRCMP(s, "reload") == 0 && *reason != 'd') { + reload = true; + } else if (STRCMP(s, "ask") == 0) { + n = false; + } else { return 2; + } } if (!n) { if (*reason == 'd') { @@ -4911,14 +4907,13 @@ buf_check_timestamp( mesg = _("E211: File \"%s\" no longer available"); } } else { - helpmesg = TRUE; - can_reload = TRUE; - /* - * Check if the file contents really changed to avoid - * giving a warning when only the timestamp was set (e.g., - * checked out of CVS). Always warn when the buffer was - * changed. - */ + helpmesg = true; + can_reload = true; + + // Check if the file contents really changed to avoid + // giving a warning when only the timestamp was set (e.g., + // checked out of CVS). Always warn when the buffer was + // changed. if (reason[2] == 'n') { mesg = _( "W12: Warning: File \"%s\" has changed and the buffer was changed in Vim as well"); @@ -4944,7 +4939,7 @@ buf_check_timestamp( retval = 1; mesg = _("W13: Warning: File \"%s\" has been created after editing started"); buf->b_flags |= BF_NEW_W; - can_reload = TRUE; + can_reload = true; } if (mesg != NULL) { From 7995a5e96420c3cc2e6caff80b94264631f9dbd9 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 1 Aug 2019 04:24:16 -0400 Subject: [PATCH 3/4] vim-patch:8.1.1374: check for file changed triggers too often Problem: Check for file changed triggers too often. Solution: Don't use "b_p_ar" when it is negative. https://github.com/vim/vim/commit/c97582b0296cb6f63f3c2e5a0eb954f5920a8e42 --- src/nvim/fileio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 56c74fbfd6..d5b61a802a 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4847,7 +4847,7 @@ buf_check_timestamp( if (!file_info_ok) { // When 'autoread' is set we'll check the file again to see if it // re-appears. - buf->b_mtime = buf->b_p_ar; + buf->b_mtime = (buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar); buf->b_orig_size = 0; buf->b_orig_mode = 0; } else { From c708567262c14f13cef3e939d23e013e46d71c3c Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 1 Aug 2019 04:35:21 -0400 Subject: [PATCH 4/4] fileio: port hotfix from patch 8.1.1379 Patch 8.1.1379 includes a change to a test, added in Patch 8.1.0815. Patch 8.1.0815 includes runtime doc changes to Blob. Neovim does not support Blobs yet. --- src/nvim/fileio.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index d5b61a802a..a164cf47d5 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4845,9 +4845,8 @@ buf_check_timestamp( // set b_mtime to stop further warnings (e.g., when executing // FileChangedShell autocmd) if (!file_info_ok) { - // When 'autoread' is set we'll check the file again to see if it - // re-appears. - buf->b_mtime = (buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar); + // Check the file again later to see if it re-appears. + buf->b_mtime = -1; buf->b_orig_size = 0; buf->b_orig_mode = 0; } else {