diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/edit.c | 24 | ||||
-rw-r--r-- | src/nvim/eval.c | 83 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 3 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 29 | ||||
-rw-r--r-- | src/nvim/ops.c | 18 | ||||
-rw-r--r-- | src/nvim/quickfix.c | 18 | ||||
-rw-r--r-- | src/nvim/testdir/test_usercommands.vim | 6 |
8 files changed, 86 insertions, 97 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 98ec9ae280..a71104cfb6 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3530,21 +3530,15 @@ int ins_compl_add_tv(typval_T *tv, int dir) char_u *(cptext[CPT_COUNT]); if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL) { - word = get_dict_string(tv->vval.v_dict, (char_u *)"word", FALSE); - cptext[CPT_ABBR] = get_dict_string(tv->vval.v_dict, - (char_u *)"abbr", FALSE); - cptext[CPT_MENU] = get_dict_string(tv->vval.v_dict, - (char_u *)"menu", FALSE); - cptext[CPT_KIND] = get_dict_string(tv->vval.v_dict, - (char_u *)"kind", FALSE); - cptext[CPT_INFO] = get_dict_string(tv->vval.v_dict, - (char_u *)"info", FALSE); - if (get_dict_string(tv->vval.v_dict, (char_u *)"icase", FALSE) != NULL) - icase = get_dict_number(tv->vval.v_dict, (char_u *)"icase"); - if (get_dict_string(tv->vval.v_dict, (char_u *)"dup", FALSE) != NULL) - adup = get_dict_number(tv->vval.v_dict, (char_u *)"dup"); - if (get_dict_string(tv->vval.v_dict, (char_u *)"empty", FALSE) != NULL) - aempty = get_dict_number(tv->vval.v_dict, (char_u *)"empty"); + word = get_dict_string(tv->vval.v_dict, "word", false); + cptext[CPT_ABBR] = get_dict_string(tv->vval.v_dict, "abbr", false); + cptext[CPT_MENU] = get_dict_string(tv->vval.v_dict, "menu", false); + cptext[CPT_KIND] = get_dict_string(tv->vval.v_dict, "kind", false); + cptext[CPT_INFO] = get_dict_string(tv->vval.v_dict, "info", false); + + icase = get_dict_number(tv->vval.v_dict, "icase"); + adup = get_dict_number(tv->vval.v_dict, "dup"); + aempty = get_dict_number(tv->vval.v_dict, "empty"); } else { word = get_tv_string_chk(tv); memset(cptext, 0, sizeof(cptext)); diff --git a/src/nvim/eval.c b/src/nvim/eval.c index dce24230b0..bb46898135 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6482,19 +6482,20 @@ static ufunc_T *find_ufunc(uint8_t *name) return rv; } -/* - * Get a string item from a dictionary. - * When "save" is TRUE allocate memory for it. - * Returns NULL if the entry doesn't exist. - */ -char_u *get_dict_string(dict_T *d, char_u *key, int save) +/// Get a string item from a dictionary. +/// +/// @param save whether memory should be allocated for the return value +/// +/// @return the entry or NULL if the entry doesn't exist. +char_u *get_dict_string(dict_T *d, char *key, bool save) { dictitem_T *di; char_u *s; - di = dict_find(d, key, -1); - if (di == NULL) + di = dict_find(d, (char_u *)key, -1); + if (di == NULL) { return NULL; + } s = get_tv_string(&di->di_tv); if (save) { s = vim_strsave(s); @@ -6502,15 +6503,15 @@ char_u *get_dict_string(dict_T *d, char_u *key, int save) return s; } -/* - * Get a number item from a dictionary. - * Returns 0 if the entry doesn't exist. - */ -long get_dict_number(dict_T *d, char_u *key) +/// Get a number item from a dictionary. +/// +/// @return the entry or 0 if the entry doesn't exist. +long get_dict_number(dict_T *d, char *key) { - dictitem_T *di = dict_find(d, key, -1); - if (di == NULL) + dictitem_T *di = dict_find(d, (char_u *)key, -1); + if (di == NULL) { return 0; + } return get_tv_number(&di->di_tv); } @@ -11943,16 +11944,16 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv) if (argvars[1].v_type == VAR_DICT) { job_opts = argvars[1].vval.v_dict; - detach = get_dict_number(job_opts, (uint8_t *)"detach") != 0; - rpc = get_dict_number(job_opts, (uint8_t *)"rpc") != 0; - pty = get_dict_number(job_opts, (uint8_t *)"pty") != 0; + detach = get_dict_number(job_opts, "detach") != 0; + rpc = get_dict_number(job_opts, "rpc") != 0; + pty = get_dict_number(job_opts, "pty") != 0; if (pty && rpc) { EMSG2(_(e_invarg2), "job cannot have both 'pty' and 'rpc' options set"); shell_free_argv(argv); return; } - char *new_cwd = (char *)get_dict_string(job_opts, (char_u *)"cwd", false); + char *new_cwd = (char *)get_dict_string(job_opts, "cwd", false); if (new_cwd && strlen(new_cwd) > 0) { cwd = new_cwd; // The new cwd must be a directory. @@ -11974,15 +11975,15 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv) Process *proc = (Process *)&data->proc; if (pty) { - uint16_t width = get_dict_number(job_opts, (uint8_t *)"width"); + uint16_t width = get_dict_number(job_opts, "width"); if (width > 0) { data->proc.pty.width = width; } - uint16_t height = get_dict_number(job_opts, (uint8_t *)"height"); + uint16_t height = get_dict_number(job_opts, "height"); if (height > 0) { data->proc.pty.height = height; } - char *term = (char *)get_dict_string(job_opts, (uint8_t *)"TERM", true); + char *term = (char *)get_dict_string(job_opts, "TERM", true); if (term) { data->proc.pty.term_name = term; } @@ -12677,7 +12678,7 @@ static void f_matchadd(typval_T *argvars, typval_T *rettv) if (dict_find(argvars[4].vval.v_dict, (char_u *)"conceal", -1) != NULL) { conceal_char = get_dict_string(argvars[4].vval.v_dict, - (char_u *)"conceal", false); + "conceal", false); } } } @@ -12733,7 +12734,7 @@ static void f_matchaddpos(typval_T *argvars, typval_T *rettv) FUNC_ATTR_NONNULL_ if (dict_find(argvars[4].vval.v_dict, (char_u *)"conceal", -1) != NULL) { conceal_char = get_dict_string(argvars[4].vval.v_dict, - (char_u *)"conceal", false); + "conceal", false); } } } @@ -14697,7 +14698,7 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv) } if ((d = argvars[0].vval.v_dict) != NULL) { - csearch = get_dict_string(d, (char_u *)"char", FALSE); + csearch = get_dict_string(d, "char", false); if (csearch != NULL) { if (enc_utf8) { int pcc[MAX_MCO]; @@ -14971,16 +14972,16 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv) } } - char_u *group = get_dict_string(d, (char_u *)"group", false); - int priority = get_dict_number(d, (char_u *)"priority"); - int id = get_dict_number(d, (char_u *)"id"); + char_u *group = get_dict_string(d, "group", false); + int priority = get_dict_number(d, "priority"); + int id = get_dict_number(d, "id"); char_u *conceal = dict_find(d, (char_u *)"conceal", -1) != NULL - ? get_dict_string(d, (char_u *)"conceal", + ? get_dict_string(d, "conceal", false) : NULL; if (i == 0) { match_add(curwin, group, - get_dict_string(d, (char_u *)"pattern", false), + get_dict_string(d, "pattern", false), priority, id, NULL, conceal); } else { match_add(curwin, group, NULL, priority, id, s, conceal); @@ -16687,7 +16688,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv) if (argvars[1].v_type == VAR_DICT) { job_opts = argvars[1].vval.v_dict; - char *new_cwd = (char *)get_dict_string(job_opts, (char_u *)"cwd", false); + char *new_cwd = (char *)get_dict_string(job_opts, "cwd", false); if (new_cwd && strlen(new_cwd) > 0) { cwd = new_cwd; // The new cwd must be a directory. @@ -16785,7 +16786,7 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv) return; } if (dict_find(dict, (char_u *)"repeat", -1) != NULL) { - repeat = get_dict_number(dict, (char_u *)"repeat"); + repeat = get_dict_number(dict, "repeat"); if (repeat == 0) { repeat = 1; } @@ -17311,29 +17312,29 @@ static void f_winrestview(typval_T *argvars, typval_T *rettv) EMSG(_(e_invarg)); else { if (dict_find(dict, (char_u *)"lnum", -1) != NULL) { - curwin->w_cursor.lnum = get_dict_number(dict, (char_u *)"lnum"); + curwin->w_cursor.lnum = get_dict_number(dict, "lnum"); } if (dict_find(dict, (char_u *)"col", -1) != NULL) { - curwin->w_cursor.col = get_dict_number(dict, (char_u *)"col"); + curwin->w_cursor.col = get_dict_number(dict, "col"); } if (dict_find(dict, (char_u *)"coladd", -1) != NULL) { - curwin->w_cursor.coladd = get_dict_number(dict, (char_u *)"coladd"); + curwin->w_cursor.coladd = get_dict_number(dict, "coladd"); } if (dict_find(dict, (char_u *)"curswant", -1) != NULL) { - curwin->w_curswant = get_dict_number(dict, (char_u *)"curswant"); - curwin->w_set_curswant = FALSE; + curwin->w_curswant = get_dict_number(dict, "curswant"); + curwin->w_set_curswant = false; } if (dict_find(dict, (char_u *)"topline", -1) != NULL) { - set_topline(curwin, get_dict_number(dict, (char_u *)"topline")); + set_topline(curwin, get_dict_number(dict, "topline")); } if (dict_find(dict, (char_u *)"topfill", -1) != NULL) { - curwin->w_topfill = get_dict_number(dict, (char_u *)"topfill"); + curwin->w_topfill = get_dict_number(dict, "topfill"); } if (dict_find(dict, (char_u *)"leftcol", -1) != NULL) { - curwin->w_leftcol = get_dict_number(dict, (char_u *)"leftcol"); + curwin->w_leftcol = get_dict_number(dict, "leftcol"); } if (dict_find(dict, (char_u *)"skipcol", -1) != NULL) { - curwin->w_skipcol = get_dict_number(dict, (char_u *)"skipcol"); + curwin->w_skipcol = get_dict_number(dict, "skipcol"); } check_cursor(); diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index b7691997d7..e70ec9ab8a 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4053,9 +4053,7 @@ void ex_global(exarg_T *eap) smsg(_("Pattern not found: %s"), pat); } } else { - start_global_changes(); global_exe(cmd); - end_global_changes(); } ml_clearmarked(); /* clear rest of the marks */ vim_regfree(regmatch.regprog); diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 6d24ba91f2..d0a17ed099 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -1983,8 +1983,6 @@ void ex_listdo(exarg_T *eap) save_ei = au_event_disable(",Syntax"); } - start_global_changes(); - if (eap->cmdidx == CMD_windo || eap->cmdidx == CMD_tabdo || P_HID(curbuf) @@ -2181,7 +2179,6 @@ void ex_listdo(exarg_T *eap) apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname, true, curbuf); } - end_global_changes(); } /// Add files[count] to the arglist of the current window after arg "after". diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 0a20f540b4..967c4fc5b4 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -345,7 +345,8 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, msg_list = saved_msg_list; return FAIL; } - ++call_depth; + call_depth++; + start_batch_changes(); cstack.cs_idx = -1; cstack.cs_looplevel = 0; @@ -952,7 +953,8 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, did_endif = FALSE; /* in case do_cmdline used recursively */ - --call_depth; + call_depth--; + end_batch_changes(); return retval; } @@ -5380,7 +5382,7 @@ uc_check_code ( } // TODO(vim): How to support :noautocmd? - // TODO(vim): How to support :sandbox + // TODO(vim): How to support :sandbox? // :silent if (msg_silent > 0) { @@ -5396,7 +5398,7 @@ uc_check_code ( result += add_cmd_modifier(buf, "topleft", &multi_mods); } - // TODO(vim): How to support :unsilent + // TODO(vim): How to support :unsilent? // :verbose if (p_verbose > 0) { @@ -9613,20 +9615,15 @@ static void ex_foldopen(exarg_T *eap) static void ex_folddo(exarg_T *eap) { - linenr_T lnum; - - start_global_changes(); - - /* First set the marks for all lines closed/open. */ - for (lnum = eap->line1; lnum <= eap->line2; ++lnum) - if (hasFolding(lnum, NULL, NULL) == (eap->cmdidx == CMD_folddoclosed)) + // First set the marks for all lines closed/open. + for (linenr_T lnum = eap->line1; lnum <= eap->line2; ++lnum) { + if (hasFolding(lnum, NULL, NULL) == (eap->cmdidx == CMD_folddoclosed)) { ml_setmarked(lnum); + } + } - /* Execute the command on the marked lines. */ - global_exe(eap->arg); - ml_clearmarked(); /* clear rest of the marks */ - - end_global_changes(); + global_exe(eap->arg); // Execute the command on the marked lines. + ml_clearmarked(); // clear rest of the marks } static void ex_terminal(exarg_T *eap) diff --git a/src/nvim/ops.c b/src/nvim/ops.c index e8a79fa820..990b95829a 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -51,10 +51,10 @@ static yankreg_T *y_previous = NULL; /* ptr to last written yankreg */ static bool clipboard_didwarn_unnamed = false; -// for behavior between start_global_changes() and end_global_changes()) +// for behavior between start_batch_changes() and end_batch_changes()) static bool clipboard_delay_update = false; // delay clipboard update -static int global_change_count = 0; // if set, inside global changes -static bool clipboard_needs_update = false; // the clipboard was updated +static int batch_change_count = 0; // inside a script +static bool clipboard_needs_update = false; // clipboard was updated /* * structure used by block_prep, op_delete and op_yank for blockwise operators @@ -5630,20 +5630,20 @@ static void set_clipboard(int name, yankreg_T *reg) (void)eval_call_provider("clipboard", "set", args); } -/// Avoid clipboard (slow) during batch operations (:global). -void start_global_changes(void) +/// Avoid clipboard (slow) during batch operations (i.e., a script). +void start_batch_changes(void) { - if (++global_change_count > 1) { + if (++batch_change_count > 1) { return; } clipboard_delay_update = true; clipboard_needs_update = false; } -/// Update the clipboard after :global changes finished. -void end_global_changes(void) +/// Update the clipboard after batch changes finished. +void end_batch_changes(void) { - if (--global_change_count > 0) { + if (--batch_change_count > 0) { // recursive return; } diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 698f05c029..20bd0a62b8 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3505,15 +3505,15 @@ int set_errorlist(win_T *wp, list_T *list, int action, char_u *title) if (d == NULL) continue; - char_u *filename = get_dict_string(d, (char_u *)"filename", true); - int bufnum = (int)get_dict_number(d, (char_u *)"bufnr"); - long lnum = get_dict_number(d, (char_u *)"lnum"); - int col = (int)get_dict_number(d, (char_u *)"col"); - char_u vcol = (char_u)get_dict_number(d, (char_u *)"vcol"); - int nr = (int)get_dict_number(d, (char_u *)"nr"); - char_u *type = get_dict_string(d, (char_u *)"type", true); - char_u *pattern = get_dict_string(d, (char_u *)"pattern", true); - char_u *text = get_dict_string(d, (char_u *)"text", true); + char_u *filename = get_dict_string(d, "filename", true); + int bufnum = (int)get_dict_number(d, "bufnr"); + long lnum = get_dict_number(d, "lnum"); + int col = (int)get_dict_number(d, "col"); + char_u vcol = (char_u)get_dict_number(d, "vcol"); + int nr = (int)get_dict_number(d, "nr"); + char_u *type = get_dict_string(d, "type", true); + char_u *pattern = get_dict_string(d, "pattern", true); + char_u *text = get_dict_string(d, "text", true); if (text == NULL) { text = vim_strsave((char_u *)""); } diff --git a/src/nvim/testdir/test_usercommands.vim b/src/nvim/testdir/test_usercommands.vim index e8e9b6c18d..f593d16dbf 100644 --- a/src/nvim/testdir/test_usercommands.vim +++ b/src/nvim/testdir/test_usercommands.vim @@ -24,23 +24,25 @@ function Test_cmdmods() topleft MyCmd verbose MyCmd vertical MyCmd + aboveleft belowright botright browse confirm hide keepalt keepjumps \ keepmarks keeppatterns lockmarks noswapfile silent tab \ topleft verbose vertical MyCmd + call assert_equal(' aboveleft belowright botright browse confirm ' . \ 'hide keepalt keepjumps keepmarks keeppatterns lockmarks ' . \ 'noswapfile silent tab topleft verbose vertical aboveleft ' . \ 'belowright botright browse confirm hide keepalt keepjumps ' . \ 'keepmarks keeppatterns lockmarks noswapfile silent tab topleft ' . \ 'verbose vertical ', g:mods) - let g:mods = '' + let g:mods = '' command! -nargs=* MyQCmd let g:mods .= '<q-mods> ' + vertical MyQCmd call assert_equal('"vertical" ', g:mods) delcommand MyCmd delcommand MyQCmd - unlet g:mods endfunction |