diff options
Diffstat (limited to 'src/nvim/api')
-rw-r--r-- | src/nvim/api/autocmd.c | 2 | ||||
-rw-r--r-- | src/nvim/api/buffer.c | 8 | ||||
-rw-r--r-- | src/nvim/api/extmark.c | 4 | ||||
-rw-r--r-- | src/nvim/api/private/converter.c | 5 | ||||
-rw-r--r-- | src/nvim/api/private/helpers.c | 28 | ||||
-rw-r--r-- | src/nvim/api/vim.c | 2 | ||||
-rw-r--r-- | src/nvim/api/vimscript.c | 30 |
7 files changed, 44 insertions, 35 deletions
diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c index 4645b77a1c..76e531e7aa 100644 --- a/src/nvim/api/autocmd.c +++ b/src/nvim/api/autocmd.c @@ -462,7 +462,7 @@ Integer nvim_create_autocmd(uint64_t channel_id, Object event, Dict(create_autoc cb.data.luaref = api_new_luaref(callback->data.luaref); } else if (callback->type == kObjectTypeString) { cb.type = kCallbackFuncref; - cb.data.funcref = (char_u *)string_to_cstr(callback->data.string); + cb.data.funcref = string_to_cstr(callback->data.string); } else { api_set_error(err, kErrorTypeException, diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index b4d4265a37..45dadae1dd 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -452,7 +452,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ goto end; } - if (ml_replace((linenr_T)lnum, (char_u *)lines[i], false) == FAIL) { + if (ml_replace((linenr_T)lnum, lines[i], false) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to replace line"); goto end; } @@ -472,7 +472,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ goto end; } - if (ml_append((linenr_T)lnum, (char_u *)lines[i], 0, false) == FAIL) { + if (ml_append((linenr_T)lnum, lines[i], 0, false) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to insert line"); goto end; } @@ -692,7 +692,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In goto end; } - if (ml_replace((linenr_T)lnum, (char_u *)lines[i], false) == FAIL) { + if (ml_replace((linenr_T)lnum, lines[i], false) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to replace line"); goto end; } @@ -710,7 +710,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In goto end; } - if (ml_append((linenr_T)lnum, (char_u *)lines[i], 0, false) == FAIL) { + if (ml_append((linenr_T)lnum, lines[i], 0, false) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to insert line"); goto end; } diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index fa6923e6d5..bbc1ee9d71 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -688,8 +688,8 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer } if (opts->sign_text.type == kObjectTypeString) { - if (!init_sign_text(&decor.sign_text, - (char_u *)opts->sign_text.data.string.data)) { + if (!init_sign_text((char **)&decor.sign_text, + opts->sign_text.data.string.data)) { api_set_error(err, kErrorTypeValidation, "sign_text is not a valid value"); goto error; } diff --git a/src/nvim/api/private/converter.c b/src/nvim/api/private/converter.c index a26383ec7d..8724ef4432 100644 --- a/src/nvim/api/private/converter.c +++ b/src/nvim/api/private/converter.c @@ -353,9 +353,10 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err) case kObjectTypeLuaRef: { LuaCFunctionState *state = xmalloc(sizeof(LuaCFunctionState)); state->lua_callable.func_ref = api_new_luaref(obj.data.luaref); - char_u *name = register_cfunc(&nlua_CFunction_func_call, &nlua_CFunction_func_free, state); + char *name = + (char *)register_cfunc(&nlua_CFunction_func_call, &nlua_CFunction_func_free, state); tv->v_type = VAR_FUNC; - tv->vval.v_string = vim_strsave(name); + tv->vval.v_string = xstrdup(name); break; } diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index a89a254f20..9f894d5533 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -634,8 +634,8 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod } parsed_args.buffer = !global; - set_maparg_lhs_rhs((char_u *)lhs.data, lhs.size, - (char_u *)rhs.data, rhs.size, lua_funcref, + set_maparg_lhs_rhs(lhs.data, lhs.size, + rhs.data, rhs.size, lua_funcref, CPO_TO_CPO_FLAGS, &parsed_args); if (opts != NULL && opts->desc.type == kObjectTypeString) { parsed_args.desc = string_to_cstr(opts->desc.data.string); @@ -652,16 +652,16 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod goto fail_and_free; } int mode_val; // integer value of the mapping mode, to be passed to do_map() - char_u *p = (char_u *)((mode.size) ? mode.data : "m"); + char *p = (mode.size) ? mode.data : "m"; if (STRNCMP(p, "!", 2) == 0) { - mode_val = get_map_mode(&p, true); // mapmode-ic + mode_val = get_map_mode((char_u **)&p, true); // mapmode-ic } else { - mode_val = get_map_mode(&p, false); + mode_val = get_map_mode((char_u **)&p, false); if ((mode_val == VISUAL + SELECTMODE + NORMAL + OP_PENDING) && mode.size > 0) { // get_map_mode() treats unrecognized mode shortnames as ":map". // This is an error unless the given shortname was empty string "". - api_set_error(err, kErrorTypeValidation, "Invalid mode shortname: \"%s\"", (char *)p); + api_set_error(err, kErrorTypeValidation, "Invalid mode shortname: \"%s\"", p); goto fail_and_free; } } @@ -1269,7 +1269,7 @@ VirtText parse_virt_text(Array chunks, Error *err, int *width) } char *text = transstr(str.size > 0 ? str.data : "", false); // allocates - w += (int)mb_string2cells((char_u *)text); + w += (int)mb_string2cells(text); kv_push(virt_text, ((VirtTextChunk){ .text = text, .hl_id = hl_id })); } @@ -1658,19 +1658,19 @@ sctx_T api_set_sctx(uint64_t channel_id) // adapted from sign.c:sign_define_init_text. // TODO(lewis6991): Consider merging -int init_sign_text(char_u **sign_text, char_u *text) +int init_sign_text(char **sign_text, char *text) { - char_u *s; + char *s; - char_u *endp = text + (int)STRLEN(text); + char *endp = text + (int)STRLEN(text); // Count cells and check for non-printable chars int cells = 0; - for (s = text; s < endp; s += utfc_ptr2len(s)) { - if (!vim_isprintc(utf_ptr2char(s))) { + for (s = text; s < endp; s += utfc_ptr2len((char_u *)s)) { + if (!vim_isprintc(utf_ptr2char((char_u *)s))) { break; } - cells += utf_ptr2cells(s); + cells += utf_ptr2cells((char_u *)s); } // Currently must be empty, one or two display cells if (s != endp || cells > 2) { @@ -1683,7 +1683,7 @@ int init_sign_text(char_u **sign_text, char_u *text) // Allocate one byte more if we need to pad up // with a space. size_t len = (size_t)(endp - text + ((cells == 1) ? 1 : 0)); - *sign_text = vim_strnsave(text, len); + *sign_text = xstrnsave(text, len); if (cells == 1) { STRCPY(*sign_text + len - 1, " "); diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 2323b8db47..7f4fafa71b 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -474,7 +474,7 @@ Integer nvim_strwidth(String text, Error *err) return 0; } - return (Integer)mb_string2cells((char_u *)text.data); + return (Integer)mb_string2cells(text.data); } /// Gets the paths contained in 'runtimepath'. diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index acd89119f9..698b2d06fb 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -747,13 +747,12 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight, E /// @param[out] err Error details, if any. /// @return Dictionary containing command information, with these keys: /// - cmd: (string) Command name. -/// - range: (number) Number of items in the command |<range>|. Can be 0, 1 or 2. -/// - line1: (number) Starting line of command |<range>|. -1 if command cannot take a range. -/// |<line1>| -/// - line2: (number) Final line of command |<range>|. -1 if command cannot take a range. -/// |<line2>| +/// - range: (array) Command <range>. Can have 0-2 elements depending on how many items the +/// range contains. Has no elements if command doesn't accept a range or if +/// no range was specified, one element if only a single range item was +/// specified and two elements if both range items were specified. /// - count: (number) Any |<count>| that was supplied to the command. -1 if command cannot -/// take a count. +/// take a count. Mutually exclusive with "range". /// - reg: (number) The optional command |<register>|, if specified. Empty string if not /// specified or if command cannot take a register. /// - bang: (boolean) Whether command contains a |<bang>| (!) modifier. @@ -849,15 +848,24 @@ Dictionary nvim_parse_cmd(String str, Dictionary opts, Error *err) PUT(result, "cmd", CSTR_TO_OBJ((char *)get_command_name(NULL, ea.cmdidx))); } - PUT(result, "range", INTEGER_OBJ(ea.addr_count)); - PUT(result, "line1", INTEGER_OBJ((ea.argt & EX_RANGE) ? ea.line1 : -1)); - PUT(result, "line2", INTEGER_OBJ((ea.argt & EX_RANGE) ? ea.line2 : -1)); + if ((ea.argt & EX_RANGE) && !(ea.argt & EX_COUNT) && ea.addr_count > 0) { + Array range = ARRAY_DICT_INIT; + if (ea.addr_count > 1) { + ADD(range, INTEGER_OBJ(ea.line1)); + } + ADD(range, INTEGER_OBJ(ea.line2)); + PUT(result, "range", ARRAY_OBJ(range));; + } else { + PUT(result, "range", ARRAY_OBJ(ARRAY_DICT_INIT)); + } if (ea.argt & EX_COUNT) { - if (ea.addr_count > 0 || cmd == NULL) { + if (ea.addr_count > 0) { PUT(result, "count", INTEGER_OBJ(ea.line2)); - } else { + } else if (cmd != NULL) { PUT(result, "count", INTEGER_OBJ(cmd->uc_def)); + } else { + PUT(result, "count", INTEGER_OBJ(0)); } } else { PUT(result, "count", INTEGER_OBJ(-1)); |