diff options
Diffstat (limited to 'src/nvim/api/deprecated.c')
-rw-r--r-- | src/nvim/api/deprecated.c | 114 |
1 files changed, 55 insertions, 59 deletions
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c index 2ec11236d7..6254e9fbd8 100644 --- a/src/nvim/api/deprecated.c +++ b/src/nvim/api/deprecated.c @@ -6,22 +6,24 @@ #include "nvim/api/deprecated.h" #include "nvim/api/extmark.h" #include "nvim/api/keysets_defs.h" -#include "nvim/api/options.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/validate.h" #include "nvim/api/vimscript.h" #include "nvim/buffer_defs.h" #include "nvim/decoration.h" +#include "nvim/decoration_defs.h" #include "nvim/extmark.h" -#include "nvim/func_attr.h" #include "nvim/globals.h" #include "nvim/highlight.h" #include "nvim/highlight_group.h" #include "nvim/lua/executor.h" #include "nvim/memory.h" +#include "nvim/memory_defs.h" #include "nvim/option.h" +#include "nvim/option_defs.h" #include "nvim/pos_defs.h" +#include "nvim/types_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/deprecated.c.generated.h" @@ -30,8 +32,8 @@ /// @deprecated Use nvim_exec2() instead. /// @see nvim_exec2 String nvim_exec(uint64_t channel_id, String src, Boolean output, Error *err) - FUNC_API_SINCE(7) - FUNC_API_DEPRECATED_SINCE(11) + FUNC_API_SINCE(7) FUNC_API_DEPRECATED_SINCE(11) + FUNC_API_RET_ALLOC { Dict(exec_opts) opts = { .output = output }; return exec_impl(channel_id, src, &opts, err); @@ -40,8 +42,8 @@ String nvim_exec(uint64_t channel_id, String src, Boolean output, Error *err) /// @deprecated /// @see nvim_exec2 String nvim_command_output(uint64_t channel_id, String command, Error *err) - FUNC_API_SINCE(1) - FUNC_API_DEPRECATED_SINCE(7) + FUNC_API_SINCE(1) FUNC_API_DEPRECATED_SINCE(7) + FUNC_API_RET_ALLOC { Dict(exec_opts) opts = { .output = true }; return exec_impl(channel_id, command, &opts, err); @@ -49,18 +51,17 @@ String nvim_command_output(uint64_t channel_id, String command, Error *err) /// @deprecated Use nvim_exec_lua() instead. /// @see nvim_exec_lua -Object nvim_execute_lua(String code, Array args, Error *err) +Object nvim_execute_lua(String code, Array args, Arena *arena, Error *err) FUNC_API_SINCE(3) FUNC_API_DEPRECATED_SINCE(7) FUNC_API_REMOTE_ONLY { - return nlua_exec(code, args, err); + return nlua_exec(code, args, kRetObject, arena, err); } /// Gets the buffer number /// -/// @deprecated The buffer number now is equal to the object id, -/// so there is no need to use this function. +/// @deprecated The buffer number now is equal to the object id /// /// @param buffer Buffer handle, or 0 for current buffer /// @param[out] err Error details, if any @@ -98,8 +99,7 @@ void nvim_buf_clear_highlight(Buffer buffer, Integer ns_id, Integer line_start, /// Set the virtual text (annotation) for a buffer line. /// -/// @deprecated use nvim_buf_set_extmark to use full virtual text -/// functionality. +/// @deprecated use nvim_buf_set_extmark to use full virtual text functionality. /// /// The text will be placed after the buffer text. Virtual text will never /// cause reflow, rather virtual text will be truncated at the end of the screen @@ -117,7 +117,7 @@ void nvim_buf_clear_highlight(Buffer buffer, Integer ns_id, Integer line_start, /// virtual text, the allocated id is then returned. /// /// @param buffer Buffer handle, or 0 for current buffer -/// @param ns_id Namespace to use or 0 to create a namespace, +/// @param src_id Namespace to use or 0 to create a namespace, /// or -1 for a ungrouped annotation /// @param line Line to annotate with virtual text (zero-indexed) /// @param chunks A list of [text, hl_group] arrays, each representing a @@ -127,7 +127,7 @@ void nvim_buf_clear_highlight(Buffer buffer, Integer ns_id, Integer line_start, /// @param[out] err Error details, if any /// @return The ns_id that was used Integer nvim_buf_set_virtual_text(Buffer buffer, Integer src_id, Integer line, Array chunks, - Dictionary opts, Error *err) + Dict(empty) *opts, Error *err) FUNC_API_SINCE(5) FUNC_API_DEPRECATED_SINCE(8) { @@ -141,11 +141,6 @@ Integer nvim_buf_set_virtual_text(Buffer buffer, Integer src_id, Integer line, A return 0; } - if (opts.size > 0) { - api_set_error(err, kErrorTypeValidation, "opts dict isn't empty"); - return 0; - } - uint32_t ns_id = src2ns(&src_id); int width; @@ -172,7 +167,7 @@ Integer nvim_buf_set_virtual_text(Buffer buffer, Integer src_id, Integer line, A DecorInline decor = { .ext = true, .data.ext.vt = vt, .data.ext.sh_idx = DECOR_ID_INVALID }; extmark_set(buf, ns_id, NULL, (int)line, 0, -1, -1, decor, 0, true, - false, false, false, NULL); + false, false, false, false, NULL); return src_id; } @@ -228,12 +223,12 @@ Dictionary nvim_get_hl_by_name(String name, Boolean rgb, Arena *arena, Error *er /// the end of the buffer. /// @param lines Array of lines /// @param[out] err Error details, if any -void buffer_insert(Buffer buffer, Integer lnum, ArrayOf(String) lines, Error *err) +void buffer_insert(Buffer buffer, Integer lnum, ArrayOf(String) lines, Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { // "lnum" will be the index of the line after inserting, // no matter if it is negative or not - nvim_buf_set_lines(0, buffer, lnum, lnum, true, lines, err); + nvim_buf_set_lines(0, buffer, lnum, lnum, true, lines, arena, err); } /// Gets a buffer line @@ -248,20 +243,18 @@ void buffer_insert(Buffer buffer, Integer lnum, ArrayOf(String) lines, Error *er /// @param index Line index /// @param[out] err Error details, if any /// @return Line string -String buffer_get_line(Buffer buffer, Integer index, Error *err) +String buffer_get_line(Buffer buffer, Integer index, Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { String rv = { .size = 0 }; index = convert_index(index); - Array slice = nvim_buf_get_lines(0, buffer, index, index + 1, true, NULL, err); + Array slice = nvim_buf_get_lines(0, buffer, index, index + 1, true, arena, NULL, err); if (!ERROR_SET(err) && slice.size) { rv = slice.items[0].data.string; } - xfree(slice.items); - return rv; } @@ -277,13 +270,13 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) /// @param index Line index /// @param line Contents of the new line /// @param[out] err Error details, if any -void buffer_set_line(Buffer buffer, Integer index, String line, Error *err) +void buffer_set_line(Buffer buffer, Integer index, String line, Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { Object l = STRING_OBJ(line); Array array = { .items = &l, .size = 1 }; index = convert_index(index); - nvim_buf_set_lines(0, buffer, index, index + 1, true, array, err); + nvim_buf_set_lines(0, buffer, index, index + 1, true, array, arena, err); } /// Deletes a buffer line @@ -296,12 +289,12 @@ void buffer_set_line(Buffer buffer, Integer index, String line, Error *err) /// @param buffer buffer handle /// @param index line index /// @param[out] err Error details, if any -void buffer_del_line(Buffer buffer, Integer index, Error *err) +void buffer_del_line(Buffer buffer, Integer index, Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { Array array = ARRAY_DICT_INIT; index = convert_index(index); - nvim_buf_set_lines(0, buffer, index, index + 1, true, array, err); + nvim_buf_set_lines(0, buffer, index, index + 1, true, array, arena, err); } /// Retrieves a line range from the buffer @@ -322,12 +315,13 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer, Integer end, Boolean include_start, Boolean include_end, + Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { start = convert_index(start) + !include_start; end = convert_index(end) + include_end; - return nvim_buf_get_lines(0, buffer, start, end, false, NULL, err); + return nvim_buf_get_lines(0, buffer, start, end, false, arena, NULL, err); } /// Replaces a line range on the buffer @@ -346,12 +340,13 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer, // array will delete the line range) /// @param[out] err Error details, if any void buffer_set_line_slice(Buffer buffer, Integer start, Integer end, Boolean include_start, - Boolean include_end, ArrayOf(String) replacement, Error *err) + Boolean include_end, ArrayOf(String) replacement, Arena *arena, + Error *err) FUNC_API_DEPRECATED_SINCE(1) { start = convert_index(start) + !include_start; end = convert_index(end) + include_end; - nvim_buf_set_lines(0, buffer, start, end, false, replacement, err); + nvim_buf_set_lines(0, buffer, start, end, false, replacement, arena, err); } /// Sets a buffer-scoped (b:) variable @@ -366,7 +361,7 @@ void buffer_set_line_slice(Buffer buffer, Integer start, Integer end, Boolean in /// /// @warning It may return nil if there was no previous value /// or if previous value was `v:null`. -Object buffer_set_var(Buffer buffer, String name, Object value, Error *err) +Object buffer_set_var(Buffer buffer, String name, Object value, Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -375,7 +370,7 @@ Object buffer_set_var(Buffer buffer, String name, Object value, Error *err) return NIL; } - return dict_set_var(buf->b_vars, name, value, false, true, err); + return dict_set_var(buf->b_vars, name, value, false, true, arena, err); } /// Removes a buffer-scoped (b:) variable @@ -386,7 +381,7 @@ Object buffer_set_var(Buffer buffer, String name, Object value, Error *err) /// @param name Variable name /// @param[out] err Error details, if any /// @return Old value -Object buffer_del_var(Buffer buffer, String name, Error *err) +Object buffer_del_var(Buffer buffer, String name, Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -395,7 +390,7 @@ Object buffer_del_var(Buffer buffer, String name, Error *err) return NIL; } - return dict_set_var(buf->b_vars, name, NIL, true, true, err); + return dict_set_var(buf->b_vars, name, NIL, true, true, arena, err); } /// Sets a window-scoped (w:) variable @@ -410,7 +405,7 @@ Object buffer_del_var(Buffer buffer, String name, Error *err) /// /// @warning It may return nil if there was no previous value /// or if previous value was `v:null`. -Object window_set_var(Window window, String name, Object value, Error *err) +Object window_set_var(Window window, String name, Object value, Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { win_T *win = find_window_by_handle(window, err); @@ -419,7 +414,7 @@ Object window_set_var(Window window, String name, Object value, Error *err) return NIL; } - return dict_set_var(win->w_vars, name, value, false, true, err); + return dict_set_var(win->w_vars, name, value, false, true, arena, err); } /// Removes a window-scoped (w:) variable @@ -430,7 +425,7 @@ Object window_set_var(Window window, String name, Object value, Error *err) /// @param name variable name /// @param[out] err Error details, if any /// @return Old value -Object window_del_var(Window window, String name, Error *err) +Object window_del_var(Window window, String name, Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { win_T *win = find_window_by_handle(window, err); @@ -439,7 +434,7 @@ Object window_del_var(Window window, String name, Error *err) return NIL; } - return dict_set_var(win->w_vars, name, NIL, true, true, err); + return dict_set_var(win->w_vars, name, NIL, true, true, arena, err); } /// Sets a tab-scoped (t:) variable @@ -454,7 +449,7 @@ Object window_del_var(Window window, String name, Error *err) /// /// @warning It may return nil if there was no previous value /// or if previous value was `v:null`. -Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err) +Object tabpage_set_var(Tabpage tabpage, String name, Object value, Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { tabpage_T *tab = find_tab_by_handle(tabpage, err); @@ -463,7 +458,7 @@ Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err) return NIL; } - return dict_set_var(tab->tp_vars, name, value, false, true, err); + return dict_set_var(tab->tp_vars, name, value, false, true, arena, err); } /// Removes a tab-scoped (t:) variable @@ -474,7 +469,7 @@ Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err) /// @param name Variable name /// @param[out] err Error details, if any /// @return Old value -Object tabpage_del_var(Tabpage tabpage, String name, Error *err) +Object tabpage_del_var(Tabpage tabpage, String name, Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { tabpage_T *tab = find_tab_by_handle(tabpage, err); @@ -483,7 +478,7 @@ Object tabpage_del_var(Tabpage tabpage, String name, Error *err) return NIL; } - return dict_set_var(tab->tp_vars, name, NIL, true, true, err); + return dict_set_var(tab->tp_vars, name, NIL, true, true, arena, err); } /// @deprecated @@ -491,18 +486,18 @@ Object tabpage_del_var(Tabpage tabpage, String name, Error *err) /// @warning May return nil if there was no previous value /// OR if previous value was `v:null`. /// @return Old value or nil if there was no previous value. -Object vim_set_var(String name, Object value, Error *err) +Object vim_set_var(String name, Object value, Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { - return dict_set_var(&globvardict, name, value, false, true, err); + return dict_set_var(&globvardict, name, value, false, true, arena, err); } /// @deprecated /// @see nvim_del_var -Object vim_del_var(String name, Error *err) +Object vim_del_var(String name, Arena *arena, Error *err) FUNC_API_DEPRECATED_SINCE(1) { - return dict_set_var(&globvardict, name, NIL, true, true, err); + return dict_set_var(&globvardict, name, NIL, true, true, arena, err); } static int64_t convert_index(int64_t index) @@ -517,11 +512,11 @@ static int64_t convert_index(int64_t index) /// @param name Option name /// @param[out] err Error details, if any /// @return Option Information -Dictionary nvim_get_option_info(String name, Error *err) +Dictionary nvim_get_option_info(String name, Arena *arena, Error *err) FUNC_API_SINCE(7) FUNC_API_DEPRECATED_SINCE(11) { - return get_vimoption(name, OPT_GLOBAL, curbuf, curwin, err); + return get_vimoption(name, OPT_GLOBAL, curbuf, curwin, arena, err); } /// Sets the global value of an option. @@ -544,7 +539,7 @@ void nvim_set_option(uint64_t channel_id, String name, Object value, Error *err) /// @param name Option name /// @param[out] err Error details, if any /// @return Option value (global) -Object nvim_get_option(String name, Arena *arena, Error *err) +Object nvim_get_option(String name, Error *err) FUNC_API_SINCE(1) FUNC_API_DEPRECATED_SINCE(11) { @@ -558,7 +553,7 @@ Object nvim_get_option(String name, Arena *arena, Error *err) /// @param name Option name /// @param[out] err Error details, if any /// @return Option value -Object nvim_buf_get_option(Buffer buffer, String name, Arena *arena, Error *err) +Object nvim_buf_get_option(Buffer buffer, String name, Error *err) FUNC_API_SINCE(1) FUNC_API_DEPRECATED_SINCE(11) { @@ -600,7 +595,7 @@ void nvim_buf_set_option(uint64_t channel_id, Buffer buffer, String name, Object /// @param name Option name /// @param[out] err Error details, if any /// @return Option value -Object nvim_win_get_option(Window window, String name, Arena *arena, Error *err) +Object nvim_win_get_option(Window window, String name, Error *err) FUNC_API_SINCE(1) FUNC_API_DEPRECATED_SINCE(11) { @@ -649,7 +644,7 @@ static Object get_option_from(void *from, OptReqScope req_scope, String name, Er return (Object)OBJECT_INIT; }); - OptVal value = get_option_value_strict(name.data, req_scope, from, err); + OptVal value = get_option_value_strict(find_option(name.data), req_scope, from, err); if (ERROR_SET(err)) { return (Object)OBJECT_INIT; } @@ -675,8 +670,8 @@ static void set_option_to(uint64_t channel_id, void *to, OptReqScope req_scope, return; }); - int flags = get_option_attrs(name.data); - VALIDATE_S(flags != 0, "option name", name.data, { + OptIndex opt_idx = find_option(name.data); + VALIDATE_S(opt_idx != kOptInvalid, "option name", name.data, { return; }); @@ -691,13 +686,14 @@ static void set_option_to(uint64_t channel_id, void *to, OptReqScope req_scope, return; }); + int attrs = get_option_attrs(opt_idx); // For global-win-local options -> setlocal // For win-local options -> setglobal and setlocal (opt_flags == 0) - const int opt_flags = (req_scope == kOptReqWin && !(flags & SOPT_GLOBAL)) + const int opt_flags = (req_scope == kOptReqWin && !(attrs & SOPT_GLOBAL)) ? 0 : (req_scope == kOptReqGlobal) ? OPT_GLOBAL : OPT_LOCAL; WITH_SCRIPT_CONTEXT(channel_id, { - set_option_value_for(name.data, optval, opt_flags, req_scope, to, err); + set_option_value_for(name.data, opt_idx, optval, opt_flags, req_scope, to, err); }); } |