diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2022-06-14 21:57:08 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-14 21:57:08 +0800 |
| commit | 8ba64dd3ad1822efd6f986349e99f5f85afd7be7 (patch) | |
| tree | 66b2987707cf6616614fb251d7e342ccdfd96c28 /src | |
| parent | 2a2fb8be74f9147773416be63334ea6a74c66869 (diff) | |
| parent | 0a0cda95286bf62fbce2776a0c0081cea39a88a8 (diff) | |
| download | rneovim-8ba64dd3ad1822efd6f986349e99f5f85afd7be7.tar.gz rneovim-8ba64dd3ad1822efd6f986349e99f5f85afd7be7.tar.bz2 rneovim-8ba64dd3ad1822efd6f986349e99f5f85afd7be7.zip | |
Merge pull request #18947 from zeertzjq/vim-8.2.1897
vim-patch:8.2.{1897,1898,5088}
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/api/command.c | 140 | ||||
| -rw-r--r-- | src/nvim/buffer.c | 22 | ||||
| -rw-r--r-- | src/nvim/change.c | 2 | ||||
| -rw-r--r-- | src/nvim/diff.c | 10 | ||||
| -rw-r--r-- | src/nvim/edit.c | 2 | ||||
| -rw-r--r-- | src/nvim/ex_cmds.c | 56 | ||||
| -rw-r--r-- | src/nvim/ex_cmds2.c | 8 | ||||
| -rw-r--r-- | src/nvim/ex_cmds_defs.h | 56 | ||||
| -rw-r--r-- | src/nvim/ex_docmd.c | 325 | ||||
| -rw-r--r-- | src/nvim/ex_getln.c | 17 | ||||
| -rw-r--r-- | src/nvim/fileio.c | 6 | ||||
| -rw-r--r-- | src/nvim/globals.h | 2 | ||||
| -rw-r--r-- | src/nvim/if_cscope.c | 4 | ||||
| -rw-r--r-- | src/nvim/lua/executor.c | 44 | ||||
| -rw-r--r-- | src/nvim/mark.c | 10 | ||||
| -rw-r--r-- | src/nvim/memline.c | 7 | ||||
| -rw-r--r-- | src/nvim/message.c | 6 | ||||
| -rw-r--r-- | src/nvim/ops.c | 28 | ||||
| -rw-r--r-- | src/nvim/option.c | 2 | ||||
| -rw-r--r-- | src/nvim/quickfix.c | 16 | ||||
| -rw-r--r-- | src/nvim/search.c | 4 | ||||
| -rw-r--r-- | src/nvim/tag.c | 2 | ||||
| -rw-r--r-- | src/nvim/window.c | 10 |
23 files changed, 382 insertions, 397 deletions
diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index a7115c09a3..0d2e013aac 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -218,31 +218,31 @@ Dictionary nvim_parse_cmd(String str, Dictionary opts, Error *err) PUT(result, "nextcmd", CSTR_TO_OBJ((char *)ea.nextcmd)); Dictionary mods = ARRAY_DICT_INIT; - PUT(mods, "silent", BOOLEAN_OBJ(cmdinfo.silent)); - PUT(mods, "emsg_silent", BOOLEAN_OBJ(cmdinfo.emsg_silent)); - PUT(mods, "sandbox", BOOLEAN_OBJ(cmdinfo.sandbox)); - PUT(mods, "noautocmd", BOOLEAN_OBJ(cmdinfo.noautocmd)); - PUT(mods, "tab", INTEGER_OBJ(cmdinfo.cmdmod.tab)); - PUT(mods, "verbose", INTEGER_OBJ(cmdinfo.verbose)); - PUT(mods, "browse", BOOLEAN_OBJ(cmdinfo.cmdmod.browse)); - PUT(mods, "confirm", BOOLEAN_OBJ(cmdinfo.cmdmod.confirm)); - PUT(mods, "hide", BOOLEAN_OBJ(cmdinfo.cmdmod.hide)); - PUT(mods, "keepalt", BOOLEAN_OBJ(cmdinfo.cmdmod.keepalt)); - PUT(mods, "keepjumps", BOOLEAN_OBJ(cmdinfo.cmdmod.keepjumps)); - PUT(mods, "keepmarks", BOOLEAN_OBJ(cmdinfo.cmdmod.keepmarks)); - PUT(mods, "keeppatterns", BOOLEAN_OBJ(cmdinfo.cmdmod.keeppatterns)); - PUT(mods, "lockmarks", BOOLEAN_OBJ(cmdinfo.cmdmod.lockmarks)); - PUT(mods, "noswapfile", BOOLEAN_OBJ(cmdinfo.cmdmod.noswapfile)); - PUT(mods, "vertical", BOOLEAN_OBJ(cmdinfo.cmdmod.split & WSP_VERT)); + PUT(mods, "silent", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_SILENT)); + PUT(mods, "emsg_silent", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_ERRSILENT)); + PUT(mods, "sandbox", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_SANDBOX)); + PUT(mods, "noautocmd", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_NOAUTOCMD)); + PUT(mods, "tab", INTEGER_OBJ(cmdinfo.cmdmod.cmod_tab)); + PUT(mods, "verbose", INTEGER_OBJ(cmdinfo.cmdmod.cmod_verbose - 1)); + PUT(mods, "browse", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_BROWSE)); + PUT(mods, "confirm", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_CONFIRM)); + PUT(mods, "hide", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_HIDE)); + PUT(mods, "keepalt", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_KEEPALT)); + PUT(mods, "keepjumps", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_KEEPJUMPS)); + PUT(mods, "keepmarks", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_KEEPMARKS)); + PUT(mods, "keeppatterns", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_KEEPPATTERNS)); + PUT(mods, "lockmarks", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_LOCKMARKS)); + PUT(mods, "noswapfile", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_flags & CMOD_NOSWAPFILE)); + PUT(mods, "vertical", BOOLEAN_OBJ(cmdinfo.cmdmod.cmod_split & WSP_VERT)); const char *split; - if (cmdinfo.cmdmod.split & WSP_BOT) { + if (cmdinfo.cmdmod.cmod_split & WSP_BOT) { split = "botright"; - } else if (cmdinfo.cmdmod.split & WSP_TOP) { + } else if (cmdinfo.cmdmod.cmod_split & WSP_TOP) { split = "topleft"; - } else if (cmdinfo.cmdmod.split & WSP_BELOW) { + } else if (cmdinfo.cmdmod.cmod_split & WSP_BELOW) { split = "belowright"; - } else if (cmdinfo.cmdmod.split & WSP_ABOVE) { + } else if (cmdinfo.cmdmod.cmod_split & WSP_ABOVE) { split = "aboveleft"; } else { split = ""; @@ -284,12 +284,9 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error { exarg_T ea; memset(&ea, 0, sizeof(ea)); - ea.verbose_save = -1; - ea.save_msg_silent = -1; CmdParseInfo cmdinfo; memset(&cmdinfo, 0, sizeof(cmdinfo)); - cmdinfo.verbose = -1; char *cmdline = NULL; char *cmdname = NULL; @@ -300,7 +297,17 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error #define OBJ_TO_BOOL(var, value, default, varname) \ do { \ - var = api_object_to_bool(value, varname, default, err); \ + (var) = api_object_to_bool(value, varname, default, err); \ + if (ERROR_SET(err)) { \ + goto end; \ + } \ + } while (0) + +#define OBJ_TO_CMOD_FLAG(flag, value, default, varname) \ + do { \ + if (api_object_to_bool(value, varname, default, err)) { \ + cmdinfo.cmdmod.cmod_flags |= (flag); \ + } \ if (ERROR_SET(err)) { \ goto end; \ } \ @@ -508,21 +515,21 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error if (mods.tab.type != kObjectTypeInteger || mods.tab.data.integer < 0) { VALIDATION_ERROR("'mods.tab' must be a non-negative Integer"); } - cmdinfo.cmdmod.tab = (int)mods.tab.data.integer + 1; + cmdinfo.cmdmod.cmod_tab = (int)mods.tab.data.integer + 1; } if (HAS_KEY(mods.verbose)) { if (mods.verbose.type != kObjectTypeInteger) { VALIDATION_ERROR("'mods.verbose' must be a Integer"); - } else if (mods.verbose.data.integer >= 0) { + } else if ((int)mods.verbose.data.integer >= 0) { // Silently ignore negative integers to allow mods.verbose to be set to -1. - cmdinfo.verbose = mods.verbose.data.integer; + cmdinfo.cmdmod.cmod_verbose = (int)mods.verbose.data.integer + 1; } } bool vertical; OBJ_TO_BOOL(vertical, mods.vertical, false, "'mods.vertical'"); - cmdinfo.cmdmod.split |= (vertical ? WSP_VERT : 0); + cmdinfo.cmdmod.cmod_split |= (vertical ? WSP_VERT : 0); if (HAS_KEY(mods.split)) { if (mods.split.type != kObjectTypeString) { @@ -533,34 +540,34 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error // Empty string, do nothing. } else if (STRCMP(mods.split.data.string.data, "aboveleft") == 0 || STRCMP(mods.split.data.string.data, "leftabove") == 0) { - cmdinfo.cmdmod.split |= WSP_ABOVE; + cmdinfo.cmdmod.cmod_split |= WSP_ABOVE; } else if (STRCMP(mods.split.data.string.data, "belowright") == 0 || STRCMP(mods.split.data.string.data, "rightbelow") == 0) { - cmdinfo.cmdmod.split |= WSP_BELOW; + cmdinfo.cmdmod.cmod_split |= WSP_BELOW; } else if (STRCMP(mods.split.data.string.data, "topleft") == 0) { - cmdinfo.cmdmod.split |= WSP_TOP; + cmdinfo.cmdmod.cmod_split |= WSP_TOP; } else if (STRCMP(mods.split.data.string.data, "botright") == 0) { - cmdinfo.cmdmod.split |= WSP_BOT; + cmdinfo.cmdmod.cmod_split |= WSP_BOT; } else { VALIDATION_ERROR("Invalid value for 'mods.split'"); } } - OBJ_TO_BOOL(cmdinfo.silent, mods.silent, false, "'mods.silent'"); - OBJ_TO_BOOL(cmdinfo.emsg_silent, mods.emsg_silent, false, "'mods.emsg_silent'"); - OBJ_TO_BOOL(cmdinfo.sandbox, mods.sandbox, false, "'mods.sandbox'"); - OBJ_TO_BOOL(cmdinfo.noautocmd, mods.noautocmd, false, "'mods.noautocmd'"); - OBJ_TO_BOOL(cmdinfo.cmdmod.browse, mods.browse, false, "'mods.browse'"); - OBJ_TO_BOOL(cmdinfo.cmdmod.confirm, mods.confirm, false, "'mods.confirm'"); - OBJ_TO_BOOL(cmdinfo.cmdmod.hide, mods.hide, false, "'mods.hide'"); - OBJ_TO_BOOL(cmdinfo.cmdmod.keepalt, mods.keepalt, false, "'mods.keepalt'"); - OBJ_TO_BOOL(cmdinfo.cmdmod.keepjumps, mods.keepjumps, false, "'mods.keepjumps'"); - OBJ_TO_BOOL(cmdinfo.cmdmod.keepmarks, mods.keepmarks, false, "'mods.keepmarks'"); - OBJ_TO_BOOL(cmdinfo.cmdmod.keeppatterns, mods.keeppatterns, false, "'mods.keeppatterns'"); - OBJ_TO_BOOL(cmdinfo.cmdmod.lockmarks, mods.lockmarks, false, "'mods.lockmarks'"); - OBJ_TO_BOOL(cmdinfo.cmdmod.noswapfile, mods.noswapfile, false, "'mods.noswapfile'"); - - if (cmdinfo.sandbox && !(ea.argt & EX_SBOXOK)) { + OBJ_TO_CMOD_FLAG(CMOD_SILENT, mods.silent, false, "'mods.silent'"); + OBJ_TO_CMOD_FLAG(CMOD_ERRSILENT, mods.emsg_silent, false, "'mods.emsg_silent'"); + OBJ_TO_CMOD_FLAG(CMOD_SANDBOX, mods.sandbox, false, "'mods.sandbox'"); + OBJ_TO_CMOD_FLAG(CMOD_NOAUTOCMD, mods.noautocmd, false, "'mods.noautocmd'"); + OBJ_TO_CMOD_FLAG(CMOD_BROWSE, mods.browse, false, "'mods.browse'"); + OBJ_TO_CMOD_FLAG(CMOD_CONFIRM, mods.confirm, false, "'mods.confirm'"); + OBJ_TO_CMOD_FLAG(CMOD_HIDE, mods.hide, false, "'mods.hide'"); + OBJ_TO_CMOD_FLAG(CMOD_KEEPALT, mods.keepalt, false, "'mods.keepalt'"); + OBJ_TO_CMOD_FLAG(CMOD_KEEPJUMPS, mods.keepjumps, false, "'mods.keepjumps'"); + OBJ_TO_CMOD_FLAG(CMOD_KEEPMARKS, mods.keepmarks, false, "'mods.keepmarks'"); + OBJ_TO_CMOD_FLAG(CMOD_KEEPPATTERNS, mods.keeppatterns, false, "'mods.keeppatterns'"); + OBJ_TO_CMOD_FLAG(CMOD_LOCKMARKS, mods.lockmarks, false, "'mods.lockmarks'"); + OBJ_TO_CMOD_FLAG(CMOD_NOSWAPFILE, mods.noswapfile, false, "'mods.noswapfile'"); + + if ((cmdinfo.cmdmod.cmod_flags & CMOD_SANDBOX) && !(ea.argt & EX_SBOXOK)) { VALIDATION_ERROR("Command cannot be run in sandbox"); } } @@ -631,6 +638,7 @@ end: return retv; #undef OBJ_TO_BOOL +#undef OBJ_TO_CMOD_FLAG #undef VALIDATION_ERROR } @@ -658,20 +666,20 @@ static void build_cmdline_str(char **cmdlinep, exarg_T *eap, CmdParseInfo *cmdin StringBuilder cmdline = KV_INITIAL_VALUE; // Add command modifiers - if (cmdinfo->cmdmod.tab != 0) { - kv_printf(cmdline, "%dtab ", cmdinfo->cmdmod.tab - 1); + if (cmdinfo->cmdmod.cmod_tab != 0) { + kv_printf(cmdline, "%dtab ", cmdinfo->cmdmod.cmod_tab - 1); } - if (cmdinfo->verbose != -1) { - kv_printf(cmdline, "%ldverbose ", cmdinfo->verbose); + if (cmdinfo->cmdmod.cmod_verbose > 0) { + kv_printf(cmdline, "%dverbose ", cmdinfo->cmdmod.cmod_verbose - 1); } - if (cmdinfo->emsg_silent) { + if (cmdinfo->cmdmod.cmod_flags & CMOD_ERRSILENT) { kv_concat(cmdline, "silent! "); - } else if (cmdinfo->silent) { + } else if (cmdinfo->cmdmod.cmod_flags & CMOD_SILENT) { kv_concat(cmdline, "silent "); } - switch (cmdinfo->cmdmod.split & (WSP_ABOVE | WSP_BELOW | WSP_TOP | WSP_BOT)) { + switch (cmdinfo->cmdmod.cmod_split & (WSP_ABOVE | WSP_BELOW | WSP_TOP | WSP_BOT)) { case WSP_ABOVE: kv_concat(cmdline, "aboveleft "); break; @@ -695,18 +703,18 @@ static void build_cmdline_str(char **cmdlinep, exarg_T *eap, CmdParseInfo *cmdin } \ } while (0) - CMDLINE_APPEND_IF(cmdinfo->cmdmod.split & WSP_VERT, "vertical "); - CMDLINE_APPEND_IF(cmdinfo->sandbox, "sandbox "); - CMDLINE_APPEND_IF(cmdinfo->noautocmd, "noautocmd "); - CMDLINE_APPEND_IF(cmdinfo->cmdmod.browse, "browse "); - CMDLINE_APPEND_IF(cmdinfo->cmdmod.confirm, "confirm "); - CMDLINE_APPEND_IF(cmdinfo->cmdmod.hide, "hide "); - CMDLINE_APPEND_IF(cmdinfo->cmdmod.keepalt, "keepalt "); - CMDLINE_APPEND_IF(cmdinfo->cmdmod.keepjumps, "keepjumps "); - CMDLINE_APPEND_IF(cmdinfo->cmdmod.keepmarks, "keepmarks "); - CMDLINE_APPEND_IF(cmdinfo->cmdmod.keeppatterns, "keeppatterns "); - CMDLINE_APPEND_IF(cmdinfo->cmdmod.lockmarks, "lockmarks "); - CMDLINE_APPEND_IF(cmdinfo->cmdmod.noswapfile, "noswapfile "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_split & WSP_VERT, "vertical "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_SANDBOX, "sandbox "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_NOAUTOCMD, "noautocmd "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_BROWSE, "browse "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_CONFIRM, "confirm "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_HIDE, "hide "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_KEEPALT, "keepalt "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_KEEPJUMPS, "keepjumps "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_KEEPMARKS, "keepmarks "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_KEEPPATTERNS, "keeppatterns "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_LOCKMARKS, "lockmarks "); + CMDLINE_APPEND_IF(cmdinfo->cmdmod.cmod_flags & CMOD_NOSWAPFILE, "noswapfile "); #undef CMDLINE_APPEND_IF // Command range / count. diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 921cd20943..4fb3f66349 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1191,7 +1191,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit) } if (!forceit && bufIsChanged(buf)) { - if ((p_confirm || cmdmod.confirm) && p_write) { + if ((p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) && p_write) { dialog_changed(buf, false); if (!bufref_valid(&bufref)) { // Autocommand deleted buffer, oops! It's not changed now. @@ -1211,7 +1211,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit) } if (!forceit && buf->terminal && terminal_running(buf->terminal)) { - if (p_confirm || cmdmod.confirm) { + if (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) { if (!dialog_close_terminal(buf)) { return FAIL; } @@ -1393,7 +1393,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit) // Check if the current buffer may be abandoned. if (action == DOBUF_GOTO && !can_abandon(curbuf, forceit)) { - if ((p_confirm || cmdmod.confirm) && p_write) { + if ((p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) && p_write) { bufref_T bufref; set_bufref(&bufref, buf); dialog_changed(curbuf, false); @@ -1439,7 +1439,7 @@ void set_curbuf(buf_T *buf, int action) long old_tw = curbuf->b_p_tw; setpcmark(); - if (!cmdmod.keepalt) { + if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0) { curwin->w_alt_fnum = curbuf->b_fnum; // remember alternate file } buflist_altfpos(curwin); // remember curpos @@ -2846,7 +2846,7 @@ buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum) // Create a buffer. 'buflisted' is not set if it's a new buffer buf = buflist_new(ffname, sfname, lnum, 0); - if (buf != NULL && !cmdmod.keepalt) { + if (buf != NULL && (cmdmod.cmod_flags & CMOD_KEEPALT) == 0) { curwin->w_alt_fnum = buf->b_fnum; } return buf; @@ -4659,7 +4659,7 @@ void do_arg_all(int count, int forceit, int keep_tabs) alist_T *alist; // argument list to be used buf_T *buf; tabpage_T *tpnext; - int had_tab = cmdmod.tab; + int had_tab = cmdmod.cmod_tab; win_T *old_curwin, *last_curwin; tabpage_T *old_curtab, *last_curtab; win_T *new_curwin = NULL; @@ -4870,7 +4870,7 @@ void do_arg_all(int count, int forceit, int keep_tabs) // When ":tab" was used open a new tab for a new window repeatedly. if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) { - cmdmod.tab = 9999; + cmdmod.cmod_tab = 9999; } } @@ -4917,7 +4917,7 @@ void ex_buffer_all(exarg_T *eap) int r; long count; // Maximum number of windows to open. int all; // When true also load inactive buffers. - int had_tab = cmdmod.tab; + int had_tab = cmdmod.cmod_tab; tabpage_T *tpnext; if (eap->addr_count == 0) { // make as many windows as possible @@ -4943,7 +4943,7 @@ void ex_buffer_all(exarg_T *eap) for (wp = firstwin; wp != NULL; wp = wpnext) { wpnext = wp->w_next; if ((wp->w_buffer->b_nwindows > 1 - || ((cmdmod.split & WSP_VERT) + || ((cmdmod.cmod_split & WSP_VERT) ? wp->w_height + wp->w_hsep_height + wp->w_status_height < Rows - p_ch - tabline_height() - global_stl_height() : wp->w_width != Columns) @@ -5056,7 +5056,7 @@ void ex_buffer_all(exarg_T *eap) } // When ":tab" was used open a new tab for a new window repeatedly. if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) { - cmdmod.tab = 9999; + cmdmod.cmod_tab = 9999; } } autocmd_no_enter--; @@ -5322,7 +5322,7 @@ bool buf_hide(const buf_T *const buf) case 'h': return true; // "hide" } - return p_hid || cmdmod.hide; + return p_hid || (cmdmod.cmod_flags & CMOD_HIDE); } /// @return special buffer name or diff --git a/src/nvim/change.c b/src/nvim/change.c index 21afbf66de..c0796386f1 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -148,7 +148,7 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T } // set the '. mark - if (!cmdmod.keepjumps) { + if ((cmdmod.cmod_flags & CMOD_KEEPJUMPS) == 0) { RESET_FMARK(&curbuf->b_last_change, ((pos_T) { lnum, col, 0 }), 0); // Create a new entry if a new undo-able change was started or we diff --git a/src/nvim/diff.c b/src/nvim/diff.c index a622100918..700e79ac75 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -790,14 +790,14 @@ static int diff_write(buf_T *buf, diffin_T *din) // Always use 'fileformat' set to "unix". char_u *save_ff = buf->b_p_ff; buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); - const bool save_lockmarks = cmdmod.lockmarks; + const bool save_cmod_flags = cmdmod.cmod_flags; // Writing the buffer is an implementation detail of performing the diff, // so it shouldn't update the '[ and '] marks. - cmdmod.lockmarks = true; + cmdmod.cmod_flags |= CMOD_LOCKMARKS; int r = buf_write(buf, (char *)din->din_fname, NULL, (linenr_T)1, buf->b_ml.ml_line_count, NULL, false, false, false, true); - cmdmod.lockmarks = save_lockmarks; + cmdmod.cmod_flags = save_cmod_flags; free_string_option(buf->b_p_ff); buf->b_p_ff = save_ff; return r; @@ -1263,7 +1263,7 @@ void ex_diffpatch(exarg_T *eap) } // don't use a new tab page, each tab page has its own diffs - cmdmod.tab = 0; + cmdmod.cmod_tab = 0; if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) { // Pretend it was a ":split fname" command @@ -1323,7 +1323,7 @@ void ex_diffsplit(exarg_T *eap) set_fraction(curwin); // don't use a new tab page, each tab page has its own diffs - cmdmod.tab = 0; + cmdmod.cmod_tab = 0; if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) { // Pretend it was a ":split fname" command diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 7bdce3eadd..8f7ba03b14 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -7956,7 +7956,7 @@ static bool ins_esc(long *count, int cmdchar, bool nomove) } // Remember the last Insert position in the '^ mark. - if (!cmdmod.keepjumps) { + if ((cmdmod.cmod_flags & CMOD_KEEPJUMPS) == 0) { RESET_FMARK(&curbuf->b_last_insert, curwin->w_cursor, curbuf->b_fnum); } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 9bb77ce928..73e6e4a62f 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -981,7 +981,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) foldMoveRange(win, &win->w_folds, line1, line2, dest); } } - if (!cmdmod.lockmarks) { + if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { curbuf->b_op_start.lnum = dest - num_lines + 1; curbuf->b_op_end.lnum = dest; } @@ -994,12 +994,12 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) foldMoveRange(win, &win->w_folds, dest + 1, line1 - 1, line2); } } - if (!cmdmod.lockmarks) { + if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { curbuf->b_op_start.lnum = dest + 1; curbuf->b_op_end.lnum = dest + num_lines; } } - if (!cmdmod.lockmarks) { + if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { curbuf->b_op_start.col = curbuf->b_op_end.col = 0; } mark_adjust_nofold(last_line - num_lines + 1, last_line, @@ -1064,7 +1064,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) char *p; count = line2 - line1 + 1; - if (!cmdmod.lockmarks) { + if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { curbuf->b_op_start.lnum = n + 1; curbuf->b_op_end.lnum = n + count; curbuf->b_op_start.col = curbuf->b_op_end.col = 0; @@ -1287,10 +1287,10 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b return; } - const bool save_lockmarks = cmdmod.lockmarks; + const int save_cmod_flags = cmdmod.cmod_flags; // Temporarily disable lockmarks since that's needed to propagate changed // regions of the buffer for foldUpdate(), linecount, etc. - cmdmod.lockmarks = false; + cmdmod.cmod_flags &= ~CMOD_LOCKMARKS; cursor_save = curwin->w_cursor; linecount = line2 - line1 + 1; @@ -1410,7 +1410,8 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, b } if (do_in) { - if (cmdmod.keepmarks || vim_strchr(p_cpo, CPO_REMMARK) == NULL) { + if ((cmdmod.cmod_flags & CMOD_KEEPMARKS) + || vim_strchr(p_cpo, CPO_REMMARK) == NULL) { // TODO(bfredl): Currently not active for extmarks. What would we // do if columns don't match, assume added/deleted bytes at the // end of each line? @@ -1471,11 +1472,11 @@ error: filterend: - cmdmod.lockmarks = save_lockmarks; + cmdmod.cmod_flags = save_cmod_flags; if (curbuf != old_curbuf) { no_wait_return--; emsg(_("E135: *Filter* Autocommands must not change current buffer")); - } else if (cmdmod.lockmarks) { + } else if (cmdmod.cmod_flags & CMOD_LOCKMARKS) { curbuf->b_op_start = orig_start; curbuf->b_op_end = orig_end; } @@ -1730,7 +1731,7 @@ int rename_buffer(char *new_fname) curbuf->b_flags |= BF_NOTEDITED; if (xfname != NULL && *xfname != NUL) { buf = buflist_new((char_u *)fname, (char_u *)xfname, curwin->w_cursor.lnum, 0); - if (buf != NULL && !cmdmod.keepalt) { + if (buf != NULL && (cmdmod.cmod_flags & CMOD_KEEPALT) == 0) { curwin->w_alt_fnum = buf->b_fnum; } } @@ -1866,7 +1867,7 @@ int do_write(exarg_T *eap) && !eap->forceit && !eap->append && !p_wa) { - if (p_confirm || cmdmod.confirm) { + if (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) { if (vim_dialog_yesno(VIM_QUESTION, NULL, (char_u *)_("Write partial file?"), 2) != VIM_YES) { goto theend; @@ -1985,7 +1986,7 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int oth return FAIL; } #endif - if (p_confirm || cmdmod.confirm) { + if (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) { char buff[DIALOG_MSG_SIZE]; dialog_msg((char *)buff, _("Overwrite existing file \"%s\"?"), fname); @@ -2021,7 +2022,7 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int oth swapname = (char *)makeswapname((char_u *)fname, (char_u *)ffname, curbuf, (char_u *)dir); xfree(dir); if (os_path_exists((char_u *)swapname)) { - if (p_confirm || cmdmod.confirm) { + if (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) { char buff[DIALOG_MSG_SIZE]; dialog_msg((char *)buff, @@ -2142,7 +2143,7 @@ static int check_readonly(int *forceit, buf_T *buf) if (!*forceit && (buf->b_p_ro || (os_path_exists(buf->b_ffname) && !os_file_is_writable((char *)buf->b_ffname)))) { - if ((p_confirm || cmdmod.confirm) && buf->b_fname != NULL) { + if ((p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) && buf->b_fname != NULL) { char buff[DIALOG_MSG_SIZE]; if (buf->b_p_ro) { @@ -2401,7 +2402,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum */ if (other_file) { if (!(flags & (ECMD_ADDBUF | ECMD_ALTBUF))) { - if (!cmdmod.keepalt) { + if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0) { curwin->w_alt_fnum = curbuf->b_fnum; } if (oldwin != NULL) { @@ -3028,7 +3029,7 @@ void ex_append(exarg_T *eap) // eap->line2 pointed to the end of the buffer and nothing was appended) // "end" is set to lnum when something has been appended, otherwise // it is the same as "start" -- Acevedo - if (!cmdmod.lockmarks) { + if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { curbuf->b_op_start.lnum = (eap->line2 < curbuf->b_ml.ml_line_count) ? eap->line2 + 1 : curbuf->b_ml.ml_line_count; if (eap->cmdidx != CMD_append) { @@ -3307,7 +3308,7 @@ static bool sub_joining_lines(exarg_T *eap, char *pat, char *sub, char *cmd, boo } if (save) { - if (!cmdmod.keeppatterns) { + if ((cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0) { save_re_pat(RE_SUBST, (char_u *)pat, p_magic); } add_to_history(HIST_SEARCH, (char_u *)pat, true, NUL); @@ -4373,7 +4374,7 @@ skip: } if (sub_nsubs > start_nsubs) { - if (!cmdmod.lockmarks) { + if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { // Set the '[ and '] marks. curbuf->b_op_start.lnum = eap->line1; curbuf->b_op_end.lnum = line2; @@ -4826,8 +4827,8 @@ void ex_help(exarg_T *eap) * Always open a new one for ":tab help". */ if (!bt_help(curwin->w_buffer) - || cmdmod.tab != 0) { - if (cmdmod.tab != 0) { + || cmdmod.cmod_tab != 0) { + if (cmdmod.cmod_tab != 0) { wp = NULL; } else { wp = NULL; @@ -4853,7 +4854,7 @@ void ex_help(exarg_T *eap) // specified, the current window is vertically split and // narrow. n = WSP_HELP; - if (cmdmod.split == 0 && curwin->w_width != Columns + if (cmdmod.cmod_split == 0 && curwin->w_width != Columns && curwin->w_width < 80) { n |= WSP_TOP; } @@ -4873,9 +4874,9 @@ void ex_help(exarg_T *eap) alt_fnum = curbuf->b_fnum; (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL, ECMD_HIDE + ECMD_SET_HELP, - NULL // buffer is still open, don't store info - ); - if (!cmdmod.keepalt) { + NULL); // buffer is still open, don't store info + + if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0) { curwin->w_alt_fnum = alt_fnum; } empty_fnum = curbuf->b_fnum; @@ -4901,7 +4902,8 @@ void ex_help(exarg_T *eap) } // keep the previous alternate file - if (alt_fnum != 0 && curwin->w_alt_fnum == empty_fnum && !cmdmod.keepalt) { + if (alt_fnum != 0 && curwin->w_alt_fnum == empty_fnum + && (cmdmod.cmod_flags & CMOD_KEEPALT) == 0) { curwin->w_alt_fnum = alt_fnum; } @@ -6069,7 +6071,7 @@ void ex_oldfiles(exarg_T *eap) got_int = false; // File selection prompt on ":browse oldfiles" - if (cmdmod.browse) { + if (cmdmod.cmod_flags & CMOD_BROWSE) { quit_more = false; nr = prompt_for_number(false); msg_starthere(); @@ -6081,7 +6083,7 @@ void ex_oldfiles(exarg_T *eap) char *const s = expand_env_save((char *)p); eap->arg = s; eap->cmdidx = CMD_edit; - cmdmod.browse = false; + cmdmod.cmod_flags &= ~CMOD_BROWSE; do_exedit(eap, NULL); xfree(s); } diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index d4555f9917..9b260f9091 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -506,7 +506,7 @@ bool check_changed(buf_T *buf, int flags) && bufIsChanged(buf) && ((flags & CCGD_MULTWIN) || buf->b_nwindows <= 1) && (!(flags & CCGD_AW) || autowrite(buf, forceit) == FAIL)) { - if ((p_confirm || cmdmod.confirm) && p_write) { + if ((p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) && p_write) { int count = 0; if (flags & CCGD_ALLBUF) { @@ -719,7 +719,7 @@ bool check_changed_any(bool hidden, bool unload) ret = true; exiting = false; // When ":confirm" used, don't give an error message. - if (!(p_confirm || cmdmod.confirm)) { + if (!(p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM))) { // There must be a wait_return for this message, do_buffer() // may cause a redraw. But wait_return() is a no-op when vgetc() // is busy (Quit used from window menu), then make sure we don't @@ -1127,7 +1127,7 @@ void do_argfile(exarg_T *eap, int argn) setpcmark(); // split window or create new tab page first - if (*eap->cmd == 's' || cmdmod.tab != 0) { + if (*eap->cmd == 's' || cmdmod.cmod_tab != 0) { if (win_split(0, 0) == FAIL) { return; } @@ -3027,7 +3027,7 @@ void ex_drop(exarg_T *eap) return; } - if (cmdmod.tab) { + if (cmdmod.cmod_tab) { // ":tab drop file ...": open a tab for each argument that isn't // edited in a window yet. It's like ":tab all" but without closing // windows or tabs. diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h index a5c9c6be2d..8280f99547 100644 --- a/src/nvim/ex_cmds_defs.h +++ b/src/nvim/ex_cmds_defs.h @@ -209,10 +209,6 @@ struct exarg { LineGetter getline; ///< Function used to get the next line void *cookie; ///< argument for getline() cstack_T *cstack; ///< condition stack for ":if" etc. - long verbose_save; ///< saved value of p_verbose - int save_msg_silent; ///< saved value of msg_silent - int did_esilent; ///< how many times emsg_silent was incremented - bool did_sandbox; ///< when true did sandbox++ }; #define FORCE_BIN 1 // ":edit ++bin file" @@ -247,33 +243,47 @@ struct expand { #define XP_BS_ONE 1 // uses one backslash before a space #define XP_BS_THREE 2 // uses three backslashes before a space +enum { + CMOD_SANDBOX = 0x0001, ///< ":sandbox" + CMOD_SILENT = 0x0002, ///< ":silent" + CMOD_ERRSILENT = 0x0004, ///< ":silent!" + CMOD_UNSILENT = 0x0008, ///< ":unsilent" + CMOD_NOAUTOCMD = 0x0010, ///< ":noautocmd" + CMOD_HIDE = 0x0020, ///< ":hide" + CMOD_BROWSE = 0x0040, ///< ":browse" - invoke file dialog + CMOD_CONFIRM = 0x0080, ///< ":confirm" - invoke yes/no dialog + CMOD_KEEPALT = 0x0100, ///< ":keepalt" + CMOD_KEEPMARKS = 0x0200, ///< ":keepmarks" + CMOD_KEEPJUMPS = 0x0400, ///< ":keepjumps" + CMOD_LOCKMARKS = 0x0800, ///< ":lockmarks" + CMOD_KEEPPATTERNS = 0x1000, ///< ":keeppatterns" + CMOD_NOSWAPFILE = 0x2000, ///< ":noswapfile" +}; + /// Command modifiers ":vertical", ":browse", ":confirm", ":hide", etc. set a /// flag. This needs to be saved for recursive commands, put them in a /// structure for easy manipulation. typedef struct { - int split; ///< flags for win_split() - int tab; ///< > 0 when ":tab" was used - bool browse; ///< true to invoke file dialog - bool confirm; ///< true to invoke yes/no dialog - bool hide; ///< true when ":hide" was used - bool keepalt; ///< true when ":keepalt" was used - bool keepjumps; ///< true when ":keepjumps" was used - bool keepmarks; ///< true when ":keepmarks" was used - bool keeppatterns; ///< true when ":keeppatterns" was used - bool lockmarks; ///< true when ":lockmarks" was used - bool noswapfile; ///< true when ":noswapfile" was used - char *save_ei; ///< saved value of 'eventignore' - regmatch_T filter_regmatch; ///< set by :filter /pat/ - b |