diff --git a/src/buffer.c b/src/buffer.c index f6c161081dd9ac..a4e97bdb511eb8 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1934,7 +1934,7 @@ enter_buffer(buf_T *buf) need_fileinfo = TRUE; // display file info after redraw // check if file changed - (void)buf_check_timestamp(curbuf, FALSE); + (void)buf_check_timestamp(curbuf, FALSE, FALSE); curwin->w_topline = 1; #ifdef FEAT_DIFF diff --git a/src/diff.c b/src/diff.c index a46f0bf81e7fb6..7e575854b63187 100644 --- a/src/diff.c +++ b/src/diff.c @@ -878,12 +878,16 @@ diff_try_update( // :diffupdate! if (eap != NULL && eap->forceit) + { + reset_buf_default_reload_choice(); for (idx_new = idx_orig; idx_new < DB_COUNT; ++idx_new) { buf = curtab->tp_diffbuf[idx_new]; if (buf_valid(buf)) - buf_check_timestamp(buf, FALSE); + buf_check_timestamp(buf, FALSE, TRUE); } + reset_buf_default_reload_choice(); + } // Write the first buffer to a tempfile or mmfile_t. buf = curtab->tp_diffbuf[idx_orig]; diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 3ccb29ab371f0b..13871035a94e43 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -2742,7 +2742,7 @@ do_ecmd( { oldbuf = TRUE; set_bufref(&bufref, buf); - (void)buf_check_timestamp(buf, FALSE); + (void)buf_check_timestamp(buf, FALSE, FALSE); // Check if autocommands made the buffer invalid or changed the // current buffer. if (!bufref_valid(&bufref) || curbuf != old_curbuf.br_buf) @@ -5435,7 +5435,7 @@ ex_drop(exarg_T *eap) // reload the file if it is newer curbuf->b_p_ar = TRUE; - buf_check_timestamp(curbuf, FALSE); + buf_check_timestamp(curbuf, FALSE, FALSE); curbuf->b_p_ar = save_ar; } return; diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index 567b839cdb43be..a150ed95cb955a 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -992,7 +992,7 @@ ex_checktime(exarg_T *eap) { buf = buflist_findnr((int)eap->line2); if (buf != NULL) // cannot happen? - (void)buf_check_timestamp(buf, FALSE); + (void)buf_check_timestamp(buf, FALSE, FALSE); } no_check_timestamps = save_no_check_timestamps; } diff --git a/src/fileio.c b/src/fileio.c index 19664201e9f75c..aa76dcf6f26a10 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3959,6 +3959,7 @@ check_timestamps( ++no_wait_return; did_check_timestamps = TRUE; already_warned = FALSE; + reset_buf_default_reload_choice(); FOR_ALL_BUFFERS(buf) { // Only check buffers in a window. @@ -3967,7 +3968,7 @@ check_timestamps( bufref_T bufref; set_bufref(&bufref, buf); - n = buf_check_timestamp(buf, focus); + n = buf_check_timestamp(buf, focus, TRUE); if (didit < n) didit = n; if (n > 0 && !bufref_valid(&bufref)) @@ -3979,6 +3980,7 @@ check_timestamps( } } } + reset_buf_default_reload_choice(); --no_wait_return; need_check_timestamps = FALSE; if (need_wait_return && didit == 2) @@ -4036,9 +4038,27 @@ move_lines(buf_T *frombuf, buf_T *tobuf) return retval; } +static int default_reload_choice = -1; + +/* + * Reset the reload choice that will apply to all buffer reloads. This should + * be called before and after calling a sequence of buf_check_timestamp() when + * setting "multiple" = 1. + */ + void +reset_buf_default_reload_choice() +{ + default_reload_choice = -1; +} + /* * Check if buffer "buf" has been changed. * Also check if the file for a new buffer unexpectedly appeared. + * + * "multiple" means this is called when multiple buffers are checked together. + * "reset_buf_default_reload_choice" needs to be called before/after calling + * this function. + * * return 1 if a changed buffer was found. * return 2 if a message has been displayed. * return 0 otherwise. @@ -4046,7 +4066,8 @@ move_lines(buf_T *frombuf, buf_T *tobuf) int buf_check_timestamp( buf_T *buf, - int focus UNUSED) // called for GUI focus event + int focus UNUSED, // called for GUI focus event + int multiple) { stat_T st; int stat_res; @@ -4260,17 +4281,35 @@ buf_check_timestamp( STRCAT(tbuf, "\n"); STRCAT(tbuf, mesg2); } - switch (do_dialog(VIM_WARNING, (char_u *)_("Warning"), - (char_u *)tbuf, - (char_u *)_("&OK\n&Load File\nLoad File &and Options"), - 1, NULL, TRUE)) + if (multiple && default_reload_choice >= 0) { - case 2: - reload = RELOAD_NORMAL; - break; - case 3: - reload = RELOAD_DETECT; - break; + reload = default_reload_choice; + } + else + { + char *msg = multiple ? + "&OK\n&Load File\nLoad File and O&ptions\nLoad &All\n&Ignore All" : + "&OK\n&Load File\nLoad File and O&ptions\n"; + + switch (do_dialog(VIM_WARNING, (char_u *)_("Warning"), + (char_u *)tbuf, + (char_u *)_(msg), + 1, NULL, TRUE)) + { + case 2: + reload = RELOAD_NORMAL; + break; + case 3: + reload = RELOAD_DETECT; + break; + case 4: + reload = RELOAD_NORMAL; + default_reload_choice = RELOAD_NORMAL; + break; + case 5: + default_reload_choice = RELOAD_NONE; + break; + } } } else diff --git a/src/proto/fileio.pro b/src/proto/fileio.pro index 3f7b30d44865a0..729aa4513533d6 100644 --- a/src/proto/fileio.pro +++ b/src/proto/fileio.pro @@ -27,7 +27,8 @@ char_u *buf_modname(int shortname, char_u *fname, char_u *ext, int prepend_dot); int vim_fgets(char_u *buf, int size, FILE *fp); int vim_rename(char_u *from, char_u *to); int check_timestamps(int focus); -int buf_check_timestamp(buf_T *buf, int focus); +void reset_buf_default_reload_choice(); +int buf_check_timestamp(buf_T *buf, int focus, int multiple); void buf_reload(buf_T *buf, int orig_mode, int reload_options); void buf_store_time(buf_T *buf, stat_T *st, char_u *fname); void write_lnum_adjust(linenr_T offset); diff --git a/src/testdir/test_filechanged.vim b/src/testdir/test_filechanged.vim index c3a5664aedfec1..9ddd42226a5992 100644 --- a/src/testdir/test_filechanged.vim +++ b/src/testdir/test_filechanged.vim @@ -156,7 +156,7 @@ func Test_FileChangedShell_edit_dialog() call feedkeys('L', 'L') " load file content only checktime call assert_equal('changed', g:reason) - call assert_equal(&fileformat, 'unix') + call assert_equal('unix', &fileformat) call assert_equal("line1\r", getline(1)) call assert_equal("line2\r", getline(2)) %s/\r @@ -170,10 +170,10 @@ func Test_FileChangedShell_edit_dialog() call assert_equal(&fileformat, 'unix') call writefile(["line1\r", "line2\r"], 'Xchanged_r') let g:reason = '' - call feedkeys('a', 'L') " load file content and options + call feedkeys('p', 'L') " load file content and options checktime call assert_equal('changed', g:reason) - call assert_equal(&fileformat, 'dos') + call assert_equal('dos', &fileformat) call assert_equal("line1", getline(1)) call assert_equal("line2", getline(2)) set fileformat=unix