To: vim_dev@googlegroups.com Subject: Patch 8.2.4343 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4343 Problem: When reloading not all properties are detected. Solution: Add the "edit" value to v:fcs_choice. (Rob Pilling, closes #9579) Files: runtime/doc/editing.txt, runtime/doc/eval.txt, src/fileio.c, src/proto/fileio.pro, src/message.c, src/spellfile.c, src/testdir/test_filechanged.vim *** ../vim-8.2.4342/runtime/doc/editing.txt 2021-12-24 20:27:58.029861532 +0000 --- runtime/doc/editing.txt 2022-02-11 14:55:41.867372046 +0000 *************** *** 1641,1646 **** --- 1650,1660 ---- if it exists now. Once a file has been checked the timestamp is reset, you will not be warned again. + Syntax highlighting, marks, diff status, + 'fileencoding', 'fileformat' and 'binary' options + are not changed. See |v:fcs_choice| to reload these + too (for example, if a code formatting tools has + changed the file). :[N]checkt[ime] {filename} :[N]checkt[ime] [N] *** ../vim-8.2.4342/runtime/doc/eval.txt 2022-01-01 14:59:39.539684488 +0000 --- runtime/doc/eval.txt 2022-02-11 14:58:33.583117954 +0000 *************** *** 2054,2059 **** --- 2070,2080 ---- do with the affected buffer: reload Reload the buffer (does not work if the file was deleted). + edit Reload the buffer and detect the + values for options such as + 'fileformat', 'fileencoding', 'binary' + (does not work if the file was + deleted). ask Ask the user what to do, as if there was no autocommand. Except that when only the timestamp changed nothing *** ../vim-8.2.4342/src/fileio.c 2022-01-19 11:24:35.874972747 +0000 --- src/fileio.c 2022-02-11 15:05:26.254512398 +0000 *************** *** 2697,2703 **** } /* ! * Fill "*eap" to force the 'fileencoding', 'fileformat' and 'binary to be * equal to the buffer "buf". Used for calling readfile(). * Returns OK or FAIL. */ --- 2697,2703 ---- } /* ! * Fill "*eap" to force the 'fileencoding', 'fileformat' and 'binary' to be * equal to the buffer "buf". Used for calling readfile(). * Returns OK or FAIL. */ *************** *** 4041,4047 **** char *mesg = NULL; char *mesg2 = ""; int helpmesg = FALSE; ! int reload = FALSE; char *reason; #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) int can_reload = FALSE; --- 4041,4051 ---- char *mesg = NULL; char *mesg2 = ""; int helpmesg = FALSE; ! enum { ! RELOAD_NONE, ! RELOAD_NORMAL, ! RELOAD_DETECT ! } reload = RELOAD_NONE; char *reason; #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) int can_reload = FALSE; *************** *** 4117,4123 **** */ else if ((buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar) && !bufIsChanged(buf) && stat_res >= 0) ! reload = TRUE; else { if (stat_res < 0) --- 4121,4127 ---- */ else if ((buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar) && !bufIsChanged(buf) && stat_res >= 0) ! reload = RELOAD_NORMAL; else { if (stat_res < 0) *************** *** 4158,4164 **** #ifdef FEAT_EVAL 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 --- 4162,4170 ---- #ifdef FEAT_EVAL s = get_vim_var_str(VV_FCS_CHOICE); if (STRCMP(s, "reload") == 0 && *reason != 'd') ! reload = RELOAD_NORMAL; ! else if (STRCMP(s, "edit") == 0) ! reload = RELOAD_DETECT; else if (STRCMP(s, "ask") == 0) n = FALSE; else *************** *** 4239,4248 **** STRCAT(tbuf, "\n"); STRCAT(tbuf, mesg2); } ! if (do_dialog(VIM_WARNING, (char_u *)_("Warning"), ! (char_u *)tbuf, ! (char_u *)_("&OK\n&Load File"), 1, NULL, TRUE) == 2) ! reload = TRUE; } else #endif --- 4245,4262 ---- 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)) ! { ! case 2: ! reload = RELOAD_NORMAL; ! break; ! case 3: ! reload = RELOAD_DETECT; ! break; ! } } else #endif *************** *** 4287,4296 **** } } ! if (reload) { // Reload the buffer. ! buf_reload(buf, orig_mode); #ifdef FEAT_PERSISTENT_UNDO if (buf->b_p_udf && buf->b_ffname != NULL) { --- 4301,4310 ---- } } ! if (reload != RELOAD_NONE) { // Reload the buffer. ! buf_reload(buf, orig_mode, reload == RELOAD_DETECT); #ifdef FEAT_PERSISTENT_UNDO if (buf->b_p_udf && buf->b_ffname != NULL) { *************** *** 4326,4332 **** * buf->b_orig_mode may have been reset already. */ void ! buf_reload(buf_T *buf, int orig_mode) { exarg_T ea; pos_T old_cursor; --- 4340,4346 ---- * buf->b_orig_mode may have been reset already. */ void ! buf_reload(buf_T *buf, int orig_mode, int reload_options) { exarg_T ea; pos_T old_cursor; *************** *** 4337,4350 **** int saved = OK; aco_save_T aco; int flags = READ_NEW; // set curwin/curbuf for "buf" and save some things aucmd_prepbuf(&aco, buf); ! // We only want to read the text from the file, not reset the syntax ! // highlighting, clear marks, diff status, etc. Force the fileformat ! // and encoding to be the same. ! if (prep_exarg(&ea, buf) == OK) { old_cursor = curwin->w_cursor; old_topline = curwin->w_topline; --- 4351,4370 ---- int saved = OK; aco_save_T aco; int flags = READ_NEW; + int prepped = OK; // set curwin/curbuf for "buf" and save some things aucmd_prepbuf(&aco, buf); ! // Unless reload_options is set, we only want to read the text from the ! // file, not reset the syntax highlighting, clear marks, diff status, etc. ! // Force the fileformat and encoding to be the same. ! if (reload_options) ! memset(&ea, 0, sizeof(ea)); ! else ! prepped = prep_exarg(&ea, buf); ! ! if (prepped == OK) { old_cursor = curwin->w_cursor; old_topline = curwin->w_topline; *** ../vim-8.2.4342/src/proto/fileio.pro 2021-10-14 21:27:50.646253845 +0100 --- src/proto/fileio.pro 2022-02-11 14:50:37.047828679 +0000 *************** *** 28,34 **** int vim_rename(char_u *from, char_u *to); int check_timestamps(int focus); int buf_check_timestamp(buf_T *buf, int focus); ! void buf_reload(buf_T *buf, int orig_mode); void buf_store_time(buf_T *buf, stat_T *st, char_u *fname); void write_lnum_adjust(linenr_T offset); int readdir_core(garray_T *gap, char_u *path, int withattr, void *context, int (*checkitem)(void *context, void *item), int sort); --- 28,34 ---- int vim_rename(char_u *from, char_u *to); int check_timestamps(int focus); int buf_check_timestamp(buf_T *buf, int focus); ! 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); int readdir_core(garray_T *gap, char_u *path, int withattr, void *context, int (*checkitem)(void *context, void *item), int sort); *** ../vim-8.2.4342/src/message.c 2022-01-28 15:28:00.208927722 +0000 --- src/message.c 2022-02-11 14:50:37.047828679 +0000 *************** *** 3752,3757 **** --- 3752,3759 ---- * Other buttons- use your imagination! * A '&' in a button name becomes a shortcut, so each '&' should be before a * different letter. + * + * Returns 0 if cancelled, otherwise the nth button (1-indexed). */ int do_dialog( *** ../vim-8.2.4342/src/spellfile.c 2022-01-28 15:28:00.212927659 +0000 --- src/spellfile.c 2022-02-11 14:50:37.047828679 +0000 *************** *** 6336,6342 **** // If the .add file is edited somewhere, reload it. if (buf != NULL) ! buf_reload(buf, buf->b_orig_mode); redraw_all_later(SOME_VALID); } --- 6336,6342 ---- // If the .add file is edited somewhere, reload it. if (buf != NULL) ! buf_reload(buf, buf->b_orig_mode, FALSE); redraw_all_later(SOME_VALID); } *** ../vim-8.2.4342/src/testdir/test_filechanged.vim 2020-06-15 18:51:52.637404472 +0100 --- src/testdir/test_filechanged.vim 2022-02-11 14:50:37.047828679 +0000 *************** *** 91,96 **** --- 91,190 ---- call delete('Xchanged_r') endfunc + func Test_FileChangedShell_edit() + CheckUnix + + new Xchanged_r + call setline(1, 'reload this') + set fileformat=unix + write + + " File format changed, reload (content only, no 'ff' etc) + augroup testreload + au! + au FileChangedShell Xchanged_r let g:reason = v:fcs_reason | let v:fcs_choice = 'reload' + augroup END + call assert_equal(&fileformat, 'unix') + call writefile(["line1\r", "line2\r"], 'Xchanged_r') + let g:reason = '' + checktime + call assert_equal('changed', g:reason) + call assert_equal(&fileformat, 'unix') + call assert_equal("line1\r", getline(1)) + call assert_equal("line2\r", getline(2)) + %s/\r + write + + " File format changed, reload with 'ff', etc + augroup testreload + au! + au FileChangedShell Xchanged_r let g:reason = v:fcs_reason | let v:fcs_choice = 'edit' + augroup END + call assert_equal(&fileformat, 'unix') + call writefile(["line1\r", "line2\r"], 'Xchanged_r') + let g:reason = '' + checktime + call assert_equal('changed', g:reason) + call assert_equal(&fileformat, 'dos') + call assert_equal('line1', getline(1)) + call assert_equal('line2', getline(2)) + set fileformat=unix + write + + au! testreload + bwipe! + call delete(undofile('Xchanged_r')) + call delete('Xchanged_r') + endfunc + + func Test_FileChangedShell_edit_dialog() + CheckNotGui + + new Xchanged_r + call setline(1, 'reload this') + set fileformat=unix + write + + " File format changed, reload (content only) via prompt + augroup testreload + au! + au FileChangedShell Xchanged_r let g:reason = v:fcs_reason | let v:fcs_choice = 'ask' + augroup END + call assert_equal(&fileformat, 'unix') + call writefile(["line1\r", "line2\r"], 'Xchanged_r') + let g:reason = '' + call feedkeys('L', 'L') " load file content only + checktime + call assert_equal('changed', g:reason) + call assert_equal(&fileformat, 'unix') + call assert_equal("line1\r", getline(1)) + call assert_equal("line2\r", getline(2)) + %s/\r + write + + " File format changed, reload (file and options) via prompt + augroup testreload + au! + au FileChangedShell Xchanged_r let g:reason = v:fcs_reason | let v:fcs_choice = 'ask' + augroup END + 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 + checktime + call assert_equal('changed', g:reason) + call assert_equal(&fileformat, 'dos') + call assert_equal("line1", getline(1)) + call assert_equal("line2", getline(2)) + set fileformat=unix + write + + au! testreload + bwipe! + call delete(undofile('Xchanged_r')) + call delete('Xchanged_r') + endfunc + func Test_file_changed_dialog() CheckUnix CheckNotGui *** ../vim-8.2.4342/src/version.c 2022-02-11 11:09:36.592868324 +0000 --- src/version.c 2022-02-11 14:52:50.799627228 +0000 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4343, /**/ -- I am also told that there is a logical proof out there somewhere that demonstrates that there is no task which duct tape cannot handle. -- Paul Brannan /// 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 ///