mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api: Rename dict_set_value to dict_set_var
Reasonings: 1. It is not used for anything, but scope dictionaries currenly. So there is no need to generalize and split it into dict_set_var (which will contain some scope-dictionary-specific checks) and dict_set_value (which will work for any dictionary). 2. Check for key size is no longer valid for non-scope dictionaries: you *can* use empty keys there. In scope dictionaries also, but you actually are not supposed to store there anything, but variables. Note that actually one may still do let b:[''] = 1 and “bypass” check for variable name. It won’t change what `echo b:` will show, but it may affect code which iterates over scope dictionary keys and sets them to something (if there is such code).
This commit is contained in:
parent
6550caee50
commit
8faa4af396
@ -456,7 +456,7 @@ void nvim_buf_set_var(Buffer buffer, String name, Object value, Error *err)
|
||||
return;
|
||||
}
|
||||
|
||||
dict_set_value(buf->b_vars, name, value, false, false, err);
|
||||
dict_set_var(buf->b_vars, name, value, false, false, err);
|
||||
}
|
||||
|
||||
/// Removes a buffer-scoped (b:) variable
|
||||
@ -472,7 +472,7 @@ void nvim_buf_del_var(Buffer buffer, String name, Error *err)
|
||||
return;
|
||||
}
|
||||
|
||||
dict_set_value(buf->b_vars, name, NIL, true, false, err);
|
||||
dict_set_var(buf->b_vars, name, NIL, true, false, err);
|
||||
}
|
||||
|
||||
/// Sets a buffer-scoped (b:) variable
|
||||
@ -495,7 +495,7 @@ Object buffer_set_var(Buffer buffer, String name, Object value, Error *err)
|
||||
return (Object) OBJECT_INIT;
|
||||
}
|
||||
|
||||
return dict_set_value(buf->b_vars, name, value, false, true, err);
|
||||
return dict_set_var(buf->b_vars, name, value, false, true, err);
|
||||
}
|
||||
|
||||
/// Removes a buffer-scoped (b:) variable
|
||||
@ -514,7 +514,7 @@ Object buffer_del_var(Buffer buffer, String name, Error *err)
|
||||
return (Object) OBJECT_INIT;
|
||||
}
|
||||
|
||||
return dict_set_value(buf->b_vars, name, NIL, true, true, err);
|
||||
return dict_set_var(buf->b_vars, name, NIL, true, true, err);
|
||||
}
|
||||
|
||||
|
||||
|
@ -98,7 +98,7 @@ Object dict_get_value(dict_T *dict, String key, Error *err)
|
||||
return vim_to_object(&di->di_tv);
|
||||
}
|
||||
|
||||
/// Set a value in a dict. Objects are recursively expanded into their
|
||||
/// Set a value in a scope dict. Objects are recursively expanded into their
|
||||
/// vimscript equivalents.
|
||||
///
|
||||
/// @param dict The vimscript dict
|
||||
@ -109,7 +109,7 @@ Object dict_get_value(dict_T *dict, String key, Error *err)
|
||||
/// @param retval If true the old value will be converted and returned.
|
||||
/// @param[out] err Details of an error that may have occurred
|
||||
/// @return The old value if `retval` is true and the key was present, else NIL
|
||||
Object dict_set_value(dict_T *dict, String key, Object value, bool del,
|
||||
Object dict_set_var(dict_T *dict, String key, Object value, bool del,
|
||||
bool retval, Error *err)
|
||||
{
|
||||
Object rv = OBJECT_INIT;
|
||||
@ -120,7 +120,7 @@ Object dict_set_value(dict_T *dict, String key, Object value, bool del,
|
||||
}
|
||||
|
||||
if (key.size == 0) {
|
||||
api_set_error(err, Validation, _("Empty dictionary keys aren't allowed"));
|
||||
api_set_error(err, Validation, _("Empty variable names aren't allowed"));
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ Object dict_set_value(dict_T *dict, String key, Object value, bool del,
|
||||
return rv;
|
||||
}
|
||||
|
||||
dictitem_T *di = dict_find(dict, (uint8_t *)key.data, (int)key.size);
|
||||
dictitem_T *di = dict_find(dict, (char_u *)key.data, (int)key.size);
|
||||
|
||||
if (del) {
|
||||
// Delete the key
|
||||
|
@ -71,7 +71,7 @@ void nvim_tabpage_set_var(Tabpage tabpage,
|
||||
return;
|
||||
}
|
||||
|
||||
dict_set_value(tab->tp_vars, name, value, false, false, err);
|
||||
dict_set_var(tab->tp_vars, name, value, false, false, err);
|
||||
}
|
||||
|
||||
/// Removes a tab-scoped (t:) variable
|
||||
@ -87,7 +87,7 @@ void nvim_tabpage_del_var(Tabpage tabpage, String name, Error *err)
|
||||
return;
|
||||
}
|
||||
|
||||
dict_set_value(tab->tp_vars, name, NIL, true, false, err);
|
||||
dict_set_var(tab->tp_vars, name, NIL, true, false, err);
|
||||
}
|
||||
|
||||
/// Sets a tab-scoped (t:) variable
|
||||
@ -110,7 +110,7 @@ Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err)
|
||||
return (Object) OBJECT_INIT;
|
||||
}
|
||||
|
||||
return dict_set_value(tab->tp_vars, name, value, false, true, err);
|
||||
return dict_set_var(tab->tp_vars, name, value, false, true, err);
|
||||
}
|
||||
|
||||
/// Removes a tab-scoped (t:) variable
|
||||
@ -129,7 +129,7 @@ Object tabpage_del_var(Tabpage tabpage, String name, Error *err)
|
||||
return (Object) OBJECT_INIT;
|
||||
}
|
||||
|
||||
return dict_set_value(tab->tp_vars, name, NIL, true, true, err);
|
||||
return dict_set_var(tab->tp_vars, name, NIL, true, true, err);
|
||||
}
|
||||
|
||||
/// Gets the current window in a tabpage
|
||||
|
@ -368,7 +368,7 @@ Object nvim_get_var(String name, Error *err)
|
||||
/// @param[out] err Error details, if any
|
||||
void nvim_set_var(String name, Object value, Error *err)
|
||||
{
|
||||
dict_set_value(&globvardict, name, value, false, false, err);
|
||||
dict_set_var(&globvardict, name, value, false, false, err);
|
||||
}
|
||||
|
||||
/// Removes a global (g:) variable
|
||||
@ -377,7 +377,7 @@ void nvim_set_var(String name, Object value, Error *err)
|
||||
/// @param[out] err Error details, if any
|
||||
void nvim_del_var(String name, Error *err)
|
||||
{
|
||||
dict_set_value(&globvardict, name, NIL, true, false, err);
|
||||
dict_set_var(&globvardict, name, NIL, true, false, err);
|
||||
}
|
||||
|
||||
/// Sets a global variable
|
||||
@ -393,7 +393,7 @@ void nvim_del_var(String name, Error *err)
|
||||
/// or if previous value was `v:null`.
|
||||
Object vim_set_var(String name, Object value, Error *err)
|
||||
{
|
||||
return dict_set_value(&globvardict, name, value, false, true, err);
|
||||
return dict_set_var(&globvardict, name, value, false, true, err);
|
||||
}
|
||||
|
||||
/// Removes a global variable
|
||||
@ -405,7 +405,7 @@ Object vim_set_var(String name, Object value, Error *err)
|
||||
/// @return Old value
|
||||
Object vim_del_var(String name, Error *err)
|
||||
{
|
||||
return dict_set_value(&globvardict, name, NIL, true, true, err);
|
||||
return dict_set_var(&globvardict, name, NIL, true, true, err);
|
||||
}
|
||||
|
||||
/// Gets a v: variable
|
||||
|
@ -210,7 +210,7 @@ void nvim_win_set_var(Window window, String name, Object value, Error *err)
|
||||
return;
|
||||
}
|
||||
|
||||
dict_set_value(win->w_vars, name, value, false, false, err);
|
||||
dict_set_var(win->w_vars, name, value, false, false, err);
|
||||
}
|
||||
|
||||
/// Removes a window-scoped (w:) variable
|
||||
@ -226,7 +226,7 @@ void nvim_win_del_var(Window window, String name, Error *err)
|
||||
return;
|
||||
}
|
||||
|
||||
dict_set_value(win->w_vars, name, NIL, true, false, err);
|
||||
dict_set_var(win->w_vars, name, NIL, true, false, err);
|
||||
}
|
||||
|
||||
/// Sets a window-scoped (w:) variable
|
||||
@ -249,7 +249,7 @@ Object window_set_var(Window window, String name, Object value, Error *err)
|
||||
return (Object) OBJECT_INIT;
|
||||
}
|
||||
|
||||
return dict_set_value(win->w_vars, name, value, false, true, err);
|
||||
return dict_set_var(win->w_vars, name, value, false, true, err);
|
||||
}
|
||||
|
||||
/// Removes a window-scoped (w:) variable
|
||||
@ -268,7 +268,7 @@ Object window_del_var(Window window, String name, Error *err)
|
||||
return (Object) OBJECT_INIT;
|
||||
}
|
||||
|
||||
return dict_set_value(win->w_vars, name, NIL, true, true, err);
|
||||
return dict_set_var(win->w_vars, name, NIL, true, true, err);
|
||||
}
|
||||
|
||||
/// Gets a window option value
|
||||
|
@ -17731,9 +17731,9 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
(void)setfname(curbuf, (uint8_t *)buf, NULL, true);
|
||||
// Save the job id and pid in b:terminal_job_{id,pid}
|
||||
Error err;
|
||||
dict_set_value(curbuf->b_vars, cstr_as_string("terminal_job_id"),
|
||||
dict_set_var(curbuf->b_vars, cstr_as_string("terminal_job_id"),
|
||||
INTEGER_OBJ(rettv->vval.v_number), false, false, &err);
|
||||
dict_set_value(curbuf->b_vars, cstr_as_string("terminal_job_pid"),
|
||||
dict_set_var(curbuf->b_vars, cstr_as_string("terminal_job_pid"),
|
||||
INTEGER_OBJ(pid), false, false, &err);
|
||||
|
||||
Terminal *term = terminal_open(topts);
|
||||
|
@ -623,8 +623,8 @@ static void buf_set_term_title(buf_T *buf, char *title)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
Error err;
|
||||
dict_set_value(buf->b_vars,
|
||||
cstr_as_string("term_title"),
|
||||
dict_set_var(buf->b_vars,
|
||||
STATIC_CSTR_AS_STRING("term_title"),
|
||||
STRING_OBJ(cstr_as_string(title)),
|
||||
false,
|
||||
false,
|
||||
|
Loading…
Reference in New Issue
Block a user