diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-19 10:06:34 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-04-19 11:29:35 +0800 |
commit | 85c61d67160133ba53762bc1e5e7bbd7a0c582c0 (patch) | |
tree | 5931d3222fcac7d05fc53481e63dae5422b8fdd4 /src | |
parent | d82a6ca72aca57d89cfb8954abf2ae3980f85c04 (diff) | |
download | rneovim-85c61d67160133ba53762bc1e5e7bbd7a0c582c0.tar.gz rneovim-85c61d67160133ba53762bc1e5e7bbd7a0c582c0.tar.bz2 rneovim-85c61d67160133ba53762bc1e5e7bbd7a0c582c0.zip |
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.
https://github.com/vim/vim/commit/c216a7a21a25a701b84b79abc1ba6ab0baa3a311
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.
https://github.com/vim/vim/commit/d0f8d39d20f8d42f7451f781f7be0bcd20e06741
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.lua | 1 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 11 | ||||
-rw-r--r-- | src/nvim/main.c | 2 | ||||
-rw-r--r-- | src/nvim/memline.c | 30 |
4 files changed, 32 insertions, 12 deletions
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 7dbfac80f3..5babfa4809 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -400,6 +400,7 @@ return { strwidth={args=1, base=1, fast=true}, submatch={args={1, 2}, base=1}, substitute={args=4, base=1}, + swapfilelist={}, swapinfo={args=1, base=1}, swapname={args=1, base=1}, synID={args=3}, diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 28901d6e55..d9226214c6 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -44,6 +44,7 @@ #include "nvim/eval/executor.h" #include "nvim/eval/funcs.h" #include "nvim/eval/typval.h" +#include "nvim/eval/typval_defs.h" #include "nvim/eval/userfunc.h" #include "nvim/eval/vars.h" #include "nvim/eval/window.h" @@ -3850,8 +3851,7 @@ static void f_insert(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } /// "interrupt()" function -static void f_interrupt(typval_T *argvars FUNC_ATTR_UNUSED, typval_T *rettv FUNC_ATTR_UNUSED, - EvalFuncData fptr FUNC_ATTR_UNUSED) +static void f_interrupt(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { got_int = true; } @@ -8523,6 +8523,13 @@ static void f_substitute(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } +/// "swapfilelist()" function +static void f_swapfilelist(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) +{ + tv_list_alloc_ret(rettv, kListLenUnknown); + recover_names(NULL, false, rettv->vval.v_list, 0, NULL); +} + /// "swapinfo(swap_filename)" function static void f_swapinfo(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { diff --git a/src/nvim/main.c b/src/nvim/main.c index 698c2dcc4f..6ff26b6e96 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -466,7 +466,7 @@ int main(int argc, char **argv) // Recovery mode without a file name: List swap files. // Uses the 'dir' option, therefore it must be after the initializations. if (recoverymode && fname == NULL) { - recover_names(NULL, true, 0, NULL); + recover_names(NULL, true, NULL, 0, NULL); os_exit(0); } diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 0c38f18739..498b4b5960 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -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; } |