mirror of
https://github.com/neovim/neovim.git
synced 2025-10-07 02:16:31 +00:00
vim-patch:9.0.1007: there is no way to get a list of swap file names
Problem: There is no way to get a list of swap file names. Solution: Add the swapfilelist() function. Use it in the test script to clean up. Remove deleting individual swap files.c216a7a21a
vim-patch:9.0.1005: a failed test may leave a swap file behind Problem: A failed test may leave a swap file behind. Solution: Delete the swap file to avoid another test to fail. Use another file name.d0f8d39d20
Cherry-pick test_window_cmd.vim changes from patch 8.2.1593. Remove FUNC_ATTR_UNUSED from eval functions as fptr is always unused. Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -762,7 +762,7 @@ void ml_recover(bool checkext)
|
||||
directly = false;
|
||||
|
||||
// count the number of matching swap files
|
||||
len = recover_names(fname, false, 0, NULL);
|
||||
len = recover_names(fname, false, NULL, 0, NULL);
|
||||
if (len == 0) { // no swap files found
|
||||
semsg(_("E305: No swap file found for %s"), fname);
|
||||
goto theend;
|
||||
@@ -772,7 +772,7 @@ void ml_recover(bool checkext)
|
||||
i = 1;
|
||||
} else { // several swap files found, choose
|
||||
// list the names of the swap files
|
||||
(void)recover_names(fname, true, 0, NULL);
|
||||
(void)recover_names(fname, true, NULL, 0, NULL);
|
||||
msg_putchar('\n');
|
||||
msg_puts(_("Enter number of swap file to use (0 to quit): "));
|
||||
i = get_number(false, NULL);
|
||||
@@ -781,7 +781,7 @@ void ml_recover(bool checkext)
|
||||
}
|
||||
}
|
||||
// get the swap file name that will be used
|
||||
(void)recover_names(fname, false, i, &fname_used);
|
||||
(void)recover_names(fname, false, NULL, i, &fname_used);
|
||||
}
|
||||
if (fname_used == NULL) {
|
||||
goto theend; // user chose invalid number.
|
||||
@@ -1200,13 +1200,15 @@ theend:
|
||||
/// - list the swap files for "vim -r"
|
||||
/// - count the number of swap files when recovering
|
||||
/// - list the swap files when recovering
|
||||
/// - list the swap files for swapfilelist()
|
||||
/// - find the name of the n'th swap file when recovering
|
||||
///
|
||||
/// @param fname base for swap file name
|
||||
/// @param list when true, list the swap file names
|
||||
/// @param do_list when true, list the swap file names
|
||||
/// @param ret_list when not NULL add file names to it
|
||||
/// @param nr when non-zero, return nr'th swap file name
|
||||
/// @param fname_out result when "nr" > 0
|
||||
int recover_names(char *fname, int list, int nr, char **fname_out)
|
||||
int recover_names(char *fname, bool do_list, list_T *ret_list, int nr, char **fname_out)
|
||||
{
|
||||
int num_names;
|
||||
char *(names[6]);
|
||||
@@ -1230,7 +1232,7 @@ int recover_names(char *fname, int list, int nr, char **fname_out)
|
||||
fname_res = fname;
|
||||
}
|
||||
|
||||
if (list) {
|
||||
if (do_list) {
|
||||
// use msg() to start the scrolling properly
|
||||
msg(_("Swap files found:"));
|
||||
msg_putchar('\n');
|
||||
@@ -1306,9 +1308,11 @@ int recover_names(char *fname, int list, int nr, char **fname_out)
|
||||
}
|
||||
}
|
||||
|
||||
// remove swapfile name of the current buffer, it must be ignored
|
||||
// Remove swapfile name of the current buffer, it must be ignored.
|
||||
// But keep it for swapfilelist().
|
||||
if (curbuf->b_ml.ml_mfp != NULL
|
||||
&& (p = curbuf->b_ml.ml_mfp->mf_fname) != NULL) {
|
||||
&& (p = curbuf->b_ml.ml_mfp->mf_fname) != NULL
|
||||
&& ret_list == NULL) {
|
||||
for (int i = 0; i < num_files; i++) {
|
||||
// Do not expand wildcards, on Windows would try to expand
|
||||
// "%tmp%" in "%tmp%file"
|
||||
@@ -1333,7 +1337,7 @@ int recover_names(char *fname, int list, int nr, char **fname_out)
|
||||
*fname_out = xstrdup(files[nr - 1 + num_files - file_count]);
|
||||
dirp = ""; // stop searching
|
||||
}
|
||||
} else if (list) {
|
||||
} else if (do_list) {
|
||||
if (dir_name[0] == '.' && dir_name[1] == NUL) {
|
||||
if (fname == NULL) {
|
||||
msg_puts(_(" In current directory:\n"));
|
||||
@@ -1359,6 +1363,14 @@ int recover_names(char *fname, int list, int nr, char **fname_out)
|
||||
msg_puts(_(" -- none --\n"));
|
||||
}
|
||||
ui_flush();
|
||||
} else if (ret_list != NULL) {
|
||||
for (int i = 0; i < num_files; i++) {
|
||||
char *name = concat_fnames(dir_name, files[i], true);
|
||||
if (name != NULL) {
|
||||
tv_list_append_string(ret_list, name, -1);
|
||||
xfree(name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
file_count += num_files;
|
||||
}
|
||||
|
Reference in New Issue
Block a user