diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 22:40:31 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 22:40:31 +0000 |
commit | 339e2d15cc26fe86988ea06468d912a46c8d6f29 (patch) | |
tree | a6167fc8fcfc6ae2dc102f57b2473858eac34063 /src/nvim/arglist.c | |
parent | 067dc73729267c0262438a6fdd66e586f8496946 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.gz rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.bz2 rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.zip |
Merge remote-tracking branch 'upstream/master' into fix_repeatcmdline
Diffstat (limited to 'src/nvim/arglist.c')
-rw-r--r-- | src/nvim/arglist.c | 79 |
1 files changed, 45 insertions, 34 deletions
diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index c6a4be7e13..d2734e6c5a 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // arglist.c: functions for dealing with the argument list #include <assert.h> @@ -10,9 +7,11 @@ #include "auto/config.h" #include "nvim/arglist.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" +#include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/charset.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/eval/typval.h" #include "nvim/eval/typval_defs.h" #include "nvim/eval/window.h" @@ -21,23 +20,25 @@ #include "nvim/ex_cmds_defs.h" #include "nvim/ex_getln.h" #include "nvim/fileio.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mark.h" #include "nvim/memline_defs.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/input.h" #include "nvim/path.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/regexp.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/undo.h" #include "nvim/version.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #include "nvim/window.h" /// State used by the :all command to open all the files in the argument list in @@ -63,7 +64,9 @@ typedef struct { # include "arglist.c.generated.h" #endif -static char e_cannot_change_arglist_recursively[] +static const char e_window_layout_changed_unexpectedly[] + = N_("E249: Window layout changed unexpectedly"); +static const char e_cannot_change_arglist_recursively[] = N_("E1156: Cannot change the argument list recursively"); enum { @@ -135,7 +138,7 @@ void alist_expand(int *fnum_list, int fnum_len) // Don't use 'suffixes' here. This should work like the shell did the // expansion. Also, the vimrc file isn't read yet, thus the user // can't set the options. - p_su = empty_option; + p_su = empty_string_option; for (int i = 0; i < GARGCOUNT; i++) { old_arg_files[i] = xstrdup(GARGLIST[i].ae_fname); } @@ -252,9 +255,8 @@ void alist_slash_adjust(void) static char *do_one_arg(char *str) { char *p; - bool inbacktick; - inbacktick = false; + bool inbacktick = false; for (p = str; *str; str++) { // When the backslash is used for escaping the special meaning of a // character we need to keep it until wildcard expansion. @@ -388,7 +390,7 @@ static void arglist_del_files(garray_T *alist_ga) bool didone = false; for (int match = 0; match < ARGCOUNT; match++) { - if (vim_regexec(®match, alist_name(&ARGLIST[match]), (colnr_T)0)) { + if (vim_regexec(®match, alist_name(&ARGLIST[match]), 0)) { didone = true; xfree(ARGLIST[match].ae_fname); memmove(ARGLIST + match, ARGLIST + match + 1, @@ -619,8 +621,6 @@ void ex_argument(exarg_T *eap) /// Edit file "argn" of the argument lists. void do_argfile(exarg_T *eap, int argn) { - int other; - char *p; int old_arg_idx = curwin->w_arg_idx; if (argn < 0 || argn >= ARGCOUNT) { @@ -646,9 +646,9 @@ void do_argfile(exarg_T *eap, int argn) } else { // if 'hidden' set, only check for changed file when re-editing // the same buffer - other = true; + int other = true; if (buf_hide(curbuf)) { - p = fix_fname(alist_name(&ARGLIST[argn])); + char *p = fix_fname(alist_name(&ARGLIST[argn])); other = otherfile(p); xfree(p); } @@ -683,8 +683,6 @@ void do_argfile(exarg_T *eap, int argn) /// ":next", and commands that behave like it. void ex_next(exarg_T *eap) { - int i; - // check for changed buffer now, if this fails the argument list is not // redefined. if (buf_hide(curbuf) @@ -692,6 +690,7 @@ void ex_next(exarg_T *eap) || !check_changed(curbuf, CCGD_AW | (eap->forceit ? CCGD_FORCEIT : 0) | CCGD_EXCMD)) { + int i; if (*eap->arg != NUL) { // redefine file list if (do_arglist(eap->arg, AL_SET, 0, true) == FAIL) { return; @@ -835,10 +834,8 @@ char *get_arglist_name(expand_T *xp FUNC_ATTR_UNUSED, int idx) /// Get the file name for an argument list entry. char *alist_name(aentry_T *aep) { - buf_T *bp; - // Use the name from the associated buffer if it exists. - bp = buflist_findnr(aep->ae_fnum); + buf_T *bp = buflist_findnr(aep->ae_fnum); if (bp == NULL || bp->b_fname == NULL) { return aep->ae_fname; } @@ -855,15 +852,20 @@ static void arg_all_close_unused_windows(arg_all_state_T *aall) if (aall->had_tab > 0) { goto_tabpage_tp(first_tabpage, true, true); } - for (;;) { + while (true) { win_T *wpnext = NULL; tabpage_T *tpnext = curtab->tp_next; - for (win_T *wp = firstwin; wp != NULL; wp = wpnext) { + // Try to close floating windows first + for (win_T *wp = lastwin->w_floating ? lastwin : firstwin; wp != NULL; wp = wpnext) { int i; - wpnext = wp->w_next; + wpnext = wp->w_floating + ? wp->w_prev->w_floating ? wp->w_prev : firstwin + : (wp->w_next == NULL || wp->w_next->w_floating) ? NULL : wp->w_next; buf_T *buf = wp->w_buffer; if (buf->b_ffname == NULL - || (!aall->keep_tabs && (buf->b_nwindows > 1 || wp->w_width != Columns))) { + || (!aall->keep_tabs + && (buf->b_nwindows > 1 || wp->w_width != Columns + || (wp->w_floating && !is_aucmd_win(wp))))) { i = aall->opened_len; } else { // check if the buffer in this window is in the arglist @@ -918,7 +920,7 @@ static void arg_all_close_unused_windows(arg_all_state_T *aall) (void)autowrite(buf, false); // Check if autocommands removed the window. if (!win_valid(wp) || !bufref_valid(&bufref)) { - wpnext = firstwin; // Start all over... + wpnext = lastwin->w_floating ? lastwin : firstwin; // Start all over... continue; } } @@ -931,7 +933,7 @@ static void arg_all_close_unused_windows(arg_all_state_T *aall) // check if autocommands removed the next window if (!win_valid(wpnext)) { // start all over... - wpnext = firstwin; + wpnext = lastwin->w_floating ? lastwin : firstwin; } } } @@ -978,8 +980,10 @@ static void arg_all_open_windows(arg_all_state_T *aall, int count) if (aall->keep_tabs) { aall->new_curwin = wp; aall->new_curtab = curtab; + } else if (wp->w_floating) { + break; } else if (wp->w_frame->fr_parent != curwin->w_frame->fr_parent) { - emsg(_("E249: window layout changed unexpectedly")); + emsg(_(e_window_layout_changed_unexpectedly)); i = count; break; } else { @@ -1074,6 +1078,8 @@ static void do_arg_all(int count, int forceit, int keep_tabs) aall.alist->al_refcount++; arglist_locked = true; + tabpage_T *const new_lu_tp = curtab; + // Try closing all windows that are not in the argument list. // Also close windows that are not full width; // When 'hidden' or "forceit" set the buffer becomes hidden. @@ -1081,6 +1087,11 @@ static void do_arg_all(int count, int forceit, int keep_tabs) // When the ":tab" modifier was used do this for all tab pages. arg_all_close_unused_windows(&aall); + // Now set the last used tabpage to where we started. + if (valid_tabpage(new_lu_tp)) { + lastused_tabpage = new_lu_tp; + } + // Open a window for files in the argument list that don't have one. // ARGCOUNT may change while doing this, because of autocommands. if (count > aall.opened_len || count <= 0) { @@ -1092,7 +1103,8 @@ static void do_arg_all(int count, int forceit, int keep_tabs) autocmd_no_leave++; last_curwin = curwin; last_curtab = curtab; - win_enter(lastwin, false); + // lastwin may be aucmd_win + win_enter(lastwin_nofloating(), false); // Open up to "count" windows. arg_all_open_windows(&aall, count); @@ -1144,7 +1156,7 @@ char *arg_all(void) // Do this loop two times: // first time: compute the total length // second time: concatenate the names - for (;;) { + while (true) { int len = 0; for (int idx = 0; idx < ARGCOUNT; idx++) { char *p = alist_name(&ARGLIST[idx]); @@ -1233,8 +1245,7 @@ static void get_arglist_as_rettv(aentry_T *arglist, int argcount, typval_T *rett tv_list_alloc_ret(rettv, argcount); if (arglist != NULL) { for (int idx = 0; idx < argcount; idx++) { - tv_list_append_string(rettv->vval.v_list, - (const char *)alist_name(&arglist[idx]), -1); + tv_list_append_string(rettv->vval.v_list, alist_name(&arglist[idx]), -1); } } } @@ -1270,7 +1281,7 @@ void f_argv(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) rettv->vval.v_string = NULL; int idx = (int)tv_get_number_chk(&argvars[0], NULL); if (arglist != NULL && idx >= 0 && idx < argcount) { - rettv->vval.v_string = xstrdup((const char *)alist_name(&arglist[idx])); + rettv->vval.v_string = xstrdup(alist_name(&arglist[idx])); } else if (idx == -1) { get_arglist_as_rettv(arglist, argcount, rettv); } |