diff options
Diffstat (limited to 'src')
124 files changed, 3196 insertions, 2213 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 0c68325f40..b4d4265a37 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -247,7 +247,7 @@ void nvim__buf_redraw_range(Buffer buffer, Integer first, Integer last, Error *e return; } - redraw_buf_range_later(buf, (linenr_T)first+1, (linenr_T)last); + redraw_buf_range_later(buf, (linenr_T)first + 1, (linenr_T)last); } /// Gets a line-range from the buffer. @@ -495,7 +495,7 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ (long)extra, kExtmarkNOOP); - extmark_splice(curbuf, (int)start-1, 0, (int)(end-start), 0, + extmark_splice(curbuf, (int)start - 1, 0, (int)(end - start), 0, deleted_bytes, (int)new_len, 0, inserted_bytes, kExtmarkUndo); @@ -602,15 +602,15 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In int64_t lnum = start_row + i; const char *bufline = (char *)ml_get_buf(buf, lnum, false); - old_byte += (bcount_t)(strlen(bufline))+1; + old_byte += (bcount_t)(strlen(bufline)) + 1; } - old_byte += (bcount_t)end_col+1; + old_byte += (bcount_t)end_col + 1; } String first_item = replacement.items[0].data.string; - String last_item = replacement.items[replacement.size-1].data.string; + String last_item = replacement.items[replacement.size - 1].data.string; - size_t firstlen = (size_t)start_col+first_item.size; + size_t firstlen = (size_t)start_col + first_item.size; size_t last_part_len = strlen(str_at_end) - (size_t)end_col; if (replacement.size == 1) { firstlen += last_part_len; @@ -618,32 +618,32 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In char *first = xmallocz(firstlen); char *last = NULL; memcpy(first, str_at_start, (size_t)start_col); - memcpy(first+start_col, first_item.data, first_item.size); - memchrsub(first+start_col, NUL, NL, first_item.size); + memcpy(first + start_col, first_item.data, first_item.size); + memchrsub(first + start_col, NUL, NL, first_item.size); if (replacement.size == 1) { - memcpy(first+start_col+first_item.size, str_at_end+end_col, last_part_len); + memcpy(first + start_col + first_item.size, str_at_end + end_col, last_part_len); } else { - last = xmallocz(last_item.size+last_part_len); + last = xmallocz(last_item.size + last_part_len); memcpy(last, last_item.data, last_item.size); memchrsub(last, NUL, NL, last_item.size); - memcpy(last+last_item.size, str_at_end+end_col, last_part_len); + memcpy(last + last_item.size, str_at_end + end_col, last_part_len); } char **lines = xcalloc(new_len, sizeof(char *)); lines[0] = first; new_byte += (bcount_t)(first_item.size); - for (size_t i = 1; i < new_len-1; i++) { + for (size_t i = 1; i < new_len - 1; i++) { const String l = replacement.items[i].data.string; // Fill lines[i] with l's contents. Convert NULs to newlines as required by // NL-used-for-NUL. lines[i] = xmemdupz(l.data, l.size); memchrsub(lines[i], NUL, NL, l.size); - new_byte += (bcount_t)(l.size)+1; + new_byte += (bcount_t)(l.size) + 1; } if (replacement.size > 1) { - lines[replacement.size-1] = last; - new_byte += (bcount_t)(last_item.size)+1; + lines[replacement.size - 1] = last; + new_byte += (bcount_t)(last_item.size) + 1; } try_start(); @@ -663,7 +663,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In } ptrdiff_t extra = 0; // lines added to text, can be negative - size_t old_len = (size_t)(end_row-start_row+1); + size_t old_len = (size_t)(end_row - start_row + 1); // If the size of the range is reducing (ie, new_len < old_len) we // need to delete some old_len. We do this at the start, by @@ -731,9 +731,9 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In colnr_T col_extent = (colnr_T)(end_col - ((end_row == start_row) ? start_col : 0)); - extmark_splice(buf, (int)start_row-1, (colnr_T)start_col, - (int)(end_row-start_row), col_extent, old_byte, - (int)new_len-1, (colnr_T)last_item.size, new_byte, + extmark_splice(buf, (int)start_row - 1, (colnr_T)start_col, + (int)(end_row - start_row), col_extent, old_byte, + (int)new_len - 1, (colnr_T)last_item.size, new_byte, kExtmarkUndo); @@ -829,7 +829,7 @@ ArrayOf(String) nvim_buf_get_text(uint64_t channel_id, Buffer buffer, rv.size = (size_t)(end_row - start_row) + 1; rv.items = xcalloc(rv.size, sizeof(Object)); - rv.items[0] = STRING_OBJ(buf_get_text(buf, start_row, start_col, MAXCOL-1, replace_nl, err)); + rv.items[0] = STRING_OBJ(buf_get_text(buf, start_row, start_col, MAXCOL - 1, replace_nl, err)); if (ERROR_SET(err)) { goto end; } @@ -842,7 +842,7 @@ ArrayOf(String) nvim_buf_get_text(uint64_t channel_id, Buffer buffer, } } - rv.items[rv.size-1] = STRING_OBJ(buf_get_text(buf, end_row, 0, end_col, replace_nl, err)); + rv.items[rv.size - 1] = STRING_OBJ(buf_get_text(buf, end_row, 0, end_col, replace_nl, err)); if (ERROR_SET(err)) { goto end; } @@ -889,7 +889,7 @@ Integer nvim_buf_get_offset(Buffer buffer, Integer index, Error *err) return 0; } - return ml_find_line_or_offset(buf, (int)index+1, NULL, true); + return ml_find_line_or_offset(buf, (int)index + 1, NULL, true); } /// Gets a buffer-scoped (b:) variable. @@ -1113,7 +1113,7 @@ void nvim_buf_set_name(Buffer buffer, String name, Error *err) // Using aucmd_*: autocommands will be executed by rename_buffer aco_save_T aco; aucmd_prepbuf(&aco, buf); - int ren_ret = rename_buffer((char_u *)name.data); + int ren_ret = rename_buffer(name.data); aucmd_restbuf(&aco); if (try_end(err)) { diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c index 6a41df0aa9..f968593e47 100644 --- a/src/nvim/api/deprecated.c +++ b/src/nvim/api/deprecated.c @@ -192,7 +192,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) String rv = { .size = 0 }; index = convert_index(index); - Array slice = nvim_buf_get_lines(0, buffer, index, index+1, true, err); + Array slice = nvim_buf_get_lines(0, buffer, index, index + 1, true, err); if (!ERROR_SET(err) && slice.size) { rv = slice.items[0].data.string; @@ -221,7 +221,7 @@ void buffer_set_line(Buffer buffer, Integer index, String line, Error *err) 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, err); } /// Deletes a buffer line @@ -239,7 +239,7 @@ void buffer_del_line(Buffer buffer, Integer index, Error *err) { 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, err); } /// Retrieves a line range from the buffer diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index 8dca37a321..e408d88854 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -546,6 +546,8 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer goto error; } + // uncrustify:off + struct { const char *name; Object *opt; @@ -559,6 +561,8 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer { NULL, NULL, NULL }, }; + // uncrustify:on + for (int j = 0; hls[j].name && hls[j].dest; j++) { if (HAS_KEY(*hls[j].opt)) { *hls[j].dest = object_to_hl_id(*hls[j].opt, hls[j].name, err); @@ -716,7 +720,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer line = buf->b_ml.ml_line_count; } } else if (line < buf->b_ml.ml_line_count) { - len = ephemeral ? MAXCOL : STRLEN(ml_get_buf(buf, (linenr_T)line+1, false)); + len = ephemeral ? MAXCOL : STRLEN(ml_get_buf(buf, (linenr_T)line + 1, false)); } if (col == -1) { @@ -923,7 +927,7 @@ void nvim_buf_clear_namespace(Buffer buffer, Integer ns_id, Integer line_start, } extmark_clear(buf, (ns_id < 0 ? 0 : (uint32_t)ns_id), (int)line_start, 0, - (int)line_end-1, MAXCOL); + (int)line_end - 1, MAXCOL); } /// Set or change decoration provider for a namespace diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 5ba4700f62..a07b5b6e3a 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -632,7 +632,7 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod } else { parsed_args.desc = NULL; } - if (parsed_args.lhs_len > MAXMAPLEN) { + if (parsed_args.lhs_len > MAXMAPLEN || parsed_args.alt_lhs_len > MAXMAPLEN) { api_set_error(err, kErrorTypeValidation, "LHS exceeds maximum map length: %s", lhs.data); goto fail_and_free; } @@ -1128,6 +1128,9 @@ ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf, bool from_lua) for (const mapblock_T *current_maphash = get_maphash(i, buf); current_maphash; current_maphash = current_maphash->m_next) { + if (current_maphash->m_simplified) { + continue; + } // Check for correct mode if (int_mode & current_maphash->m_mode) { mapblock_fill_dict(dict, current_maphash, buffer_value, false); @@ -1242,7 +1245,7 @@ VirtText parse_virt_text(Array chunks, Error *err, int *width) if (ERROR_SET(err)) { goto free_exit; } - if (j < arr.size-1) { + if (j < arr.size - 1) { kv_push(virt_text, ((VirtTextChunk){ .text = NULL, .hl_id = hl_id })); } @@ -1523,7 +1526,7 @@ void create_user_command(String name, Object command, Dict(user_command) *opts, } if (opts->addr.type == kObjectTypeString) { - if (parse_addr_type_arg((char_u *)opts->addr.data.string.data, (int)opts->addr.data.string.size, + if (parse_addr_type_arg(opts->addr.data.string.data, (int)opts->addr.data.string.size, &addr_type_arg) != OK) { api_set_error(err, kErrorTypeValidation, "Invalid value for 'addr'"); goto err; @@ -1571,9 +1574,9 @@ void create_user_command(String name, Object command, Dict(user_command) *opts, compl = EXPAND_USER_LUA; compl_luaref = api_new_luaref(opts->complete.data.luaref); } else if (opts->complete.type == kObjectTypeString) { - if (parse_compl_arg((char_u *)opts->complete.data.string.data, + if (parse_compl_arg(opts->complete.data.string.data, (int)opts->complete.data.string.size, &compl, &argt, - (char_u **)&compl_arg) != OK) { + &compl_arg) != OK) { api_set_error(err, kErrorTypeValidation, "Invalid value for 'complete'"); goto err; } @@ -1600,9 +1603,8 @@ void create_user_command(String name, Object command, Dict(user_command) *opts, goto err; } - if (uc_add_command((char_u *)name.data, name.size, (char_u *)rep, argt, def, flags, - compl, (char_u *)compl_arg, compl_luaref, addr_type_arg, luaref, - force) != OK) { + if (uc_add_command(name.data, name.size, rep, argt, def, flags, compl, compl_arg, compl_luaref, + addr_type_arg, luaref, force) != OK) { api_set_error(err, kErrorTypeException, "Failed to create user command"); goto err; } diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 650349cde7..bbbc3de7d5 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -140,9 +140,9 @@ typedef struct { // Useful macro for executing some `code` for each item in an array. #define FOREACH_ITEM(a, __foreach_item, code) \ - for (size_t (__foreach_item ## _index) = 0; (__foreach_item ## _index) < (a).size; \ - (__foreach_item ## _index)++) { \ - Object __foreach_item = (a).items[__foreach_item ## _index]; \ + for (size_t (__foreach_item##_index) = 0; (__foreach_item##_index) < (a).size; \ + (__foreach_item##_index)++) { \ + Object __foreach_item = (a).items[__foreach_item##_index]; \ code; \ } diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c index b994d18c43..b81fc3b7d7 100644 --- a/src/nvim/api/tabpage.c +++ b/src/nvim/api/tabpage.c @@ -150,4 +150,3 @@ Boolean nvim_tabpage_is_valid(Tabpage tabpage) api_clear_error(&stub); return ret; } - diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 383c9c16ab..997f0c218a 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -475,9 +475,9 @@ static void remote_ui_grid_scroll(UI *ui, Integer grid, Integer top, Integer bot } else { Array args = ARRAY_DICT_INIT; ADD(args, INTEGER_OBJ(top)); - ADD(args, INTEGER_OBJ(bot-1)); + ADD(args, INTEGER_OBJ(bot - 1)); ADD(args, INTEGER_OBJ(left)); - ADD(args, INTEGER_OBJ(right-1)); + ADD(args, INTEGER_OBJ(right - 1)); push_call(ui, "set_scroll_region", args); args = (Array)ARRAY_DICT_INIT; @@ -488,9 +488,9 @@ static void remote_ui_grid_scroll(UI *ui, Integer grid, Integer top, Integer bot // so reset it. args = (Array)ARRAY_DICT_INIT; ADD(args, INTEGER_OBJ(0)); - ADD(args, INTEGER_OBJ(ui->height-1)); + ADD(args, INTEGER_OBJ(ui->height - 1)); ADD(args, INTEGER_OBJ(0)); - ADD(args, INTEGER_OBJ(ui->width-1)); + ADD(args, INTEGER_OBJ(ui->width - 1)); push_call(ui, "set_scroll_region", args); } } @@ -615,12 +615,12 @@ static void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startc ADD(args, INTEGER_OBJ(startcol)); Array cells = ARRAY_DICT_INIT; int repeat = 0; - size_t ncells = (size_t)(endcol-startcol); + size_t ncells = (size_t)(endcol - startcol); int last_hl = -1; for (size_t i = 0; i < ncells; i++) { repeat++; - if (i == ncells-1 || attrs[i] != attrs[i+1] - || STRCMP(chunk[i], chunk[i+1])) { + if (i == ncells - 1 || attrs[i] != attrs[i + 1] + || STRCMP(chunk[i], chunk[i + 1])) { Array cell = ARRAY_DICT_INIT; ADD(cell, STRING_OBJ(cstr_to_string((const char *)chunk[i]))); if (attrs[i] != last_hl || repeat > 1) { @@ -638,15 +638,15 @@ static void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startc Array cell = ARRAY_DICT_INIT; ADD(cell, STRING_OBJ(cstr_to_string(" "))); ADD(cell, INTEGER_OBJ(clearattr)); - ADD(cell, INTEGER_OBJ(clearcol-endcol)); + ADD(cell, INTEGER_OBJ(clearcol - endcol)); ADD(cells, ARRAY_OBJ(cell)); } ADD(args, ARRAY_OBJ(cells)); push_call(ui, "grid_line", args); } else { - for (int i = 0; i < endcol-startcol; i++) { - remote_ui_cursor_goto(ui, row, startcol+i); + for (int i = 0; i < endcol - startcol; i++) { + remote_ui_cursor_goto(ui, row, startcol + i); remote_ui_highlight_set(ui, attrs[i]); remote_ui_put(ui, (const char *)chunk[i]); if (utf_ambiguous_width(utf_ptr2char(chunk[i]))) { diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 0f9a4a0e0d..3d1b5eade4 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -28,6 +28,7 @@ #include "nvim/eval/typval.h" #include "nvim/eval/userfunc.h" #include "nvim/ex_cmds2.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/file_search.h" #include "nvim/fileio.h" @@ -403,9 +404,19 @@ String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, Bool return (String) { .data = NULL, .size = 0 }; } + int flags = 0; + if (from_part) { + flags |= REPTERM_FROM_PART; + } + if (do_lt) { + flags |= REPTERM_DO_LT; + } + if (!special) { + flags |= REPTERM_NO_SPECIAL; + } + char *ptr = NULL; - replace_termcodes((char_u *)str.data, str.size, (char_u **)&ptr, - from_part, do_lt, special, CPO_TO_CPO_FLAGS); + replace_termcodes((char_u *)str.data, str.size, (char_u **)&ptr, flags, NULL, CPO_TO_CPO_FLAGS); return cstr_as_string(ptr); } @@ -558,7 +569,7 @@ void nvim_set_current_dir(String dir, Error *err) try_start(); - if (!changedir_func(string, kCdScopeGlobal)) { + if (!changedir_func((char *)string, kCdScopeGlobal)) { if (!try_end(err)) { api_set_error(err, kErrorTypeException, "Failed to change directory"); } @@ -2450,3 +2461,203 @@ void nvim_del_user_command(String name, Error *err) { nvim_buf_del_user_command(-1, name, err); } + +/// Parse command line. +/// +/// Doesn't check the validity of command arguments. +/// +/// @param str Command line string to parse. Cannot contain "\n". +/// @param opts Optional parameters. Reserved for future use. +/// @param[out] err Error details, if any. +/// @return Dictionary containing command information, with these keys: +/// - cmd: (string) Command name. +/// - line1: (number) Starting line of command range. Only applicable if command can take a +/// range. +/// - line2: (number) Final line of command range. Only applicable if command can take a +/// range. +/// - bang: (boolean) Whether command contains a bang (!) modifier. +/// - args: (array) Command arguments. +/// - addr: (string) Value of |:command-addr|. Uses short name. +/// - nargs: (string) Value of |:command-nargs|. +/// - nextcmd: (string) Next command if there are multiple commands separated by a |:bar|. +/// Empty if there isn't a next command. +/// - magic: (dictionary) Which characters have special meaning in the command arguments. +/// - file: (boolean) The command expands filenames. Which means characters such as "%", +/// "#" and wildcards are expanded. +/// - bar: (boolean) The "|" character is treated as a command separator and the double +/// quote character (\") is treated as the start of a comment. +/// - mods: (dictionary) |:command-modifiers|. +/// - silent: (boolean) |:silent|. +/// - emsg_silent: (boolean) |:silent!|. +/// - sandbox: (boolean) |:sandbox|. +/// - noautocmd: (boolean) |:noautocmd|. +/// - browse: (boolean) |:browse|. +/// - confirm: (boolean) |:confirm|. +/// - hide: (boolean) |:hide|. +/// - keepalt: (boolean) |:keepalt|. +/// - keepjumps: (boolean) |:keepjumps|. +/// - keepmarks: (boolean) |:keepmarks|. +/// - keeppatterns: (boolean) |:keeppatterns|. +/// - lockmarks: (boolean) |:lockmarks|. +/// - noswapfile: (boolean) |:noswapfile|. +/// - tab: (integer) |:tab|. +/// - verbose: (integer) |:verbose|. +/// - vertical: (boolean) |:vertical|. +/// - split: (string) Split modifier string, is an empty string when there's no split +/// modifier. If there is a split modifier it can be one of: +/// - "aboveleft": |:aboveleft|. +/// - "belowright": |:belowright|. +/// - "topleft": |:topleft|. +/// - "botright": |:botright|. +Dictionary nvim_parse_cmd(String str, Dictionary opts, Error *err) + FUNC_API_SINCE(10) FUNC_API_FAST +{ + Dictionary result = ARRAY_DICT_INIT; + + if (opts.size > 0) { + api_set_error(err, kErrorTypeValidation, "opts dict isn't empty"); + return result; + } + + // Parse command line + exarg_T ea; + CmdParseInfo cmdinfo; + char_u *cmdline = vim_strsave((char_u *)str.data); + + if (!parse_cmdline(cmdline, &ea, &cmdinfo)) { + api_set_error(err, kErrorTypeException, "Error while parsing command line"); + goto end; + } + + // Parse arguments + Array args = ARRAY_DICT_INIT; + size_t length = STRLEN(ea.arg); + + // For nargs = 1 or '?', pass the entire argument list as a single argument, + // otherwise split arguments by whitespace. + if (ea.argt & EX_NOSPC) { + if (*ea.arg != NUL) { + ADD(args, STRING_OBJ(cstrn_to_string((char *)ea.arg, length))); + } + } else { + size_t end = 0; + size_t len = 0; + char *buf = xcalloc(length, sizeof(char)); + bool done = false; + + while (!done) { + done = uc_split_args_iter(ea.arg, length, &end, buf, &len); + if (len > 0) { + ADD(args, STRING_OBJ(cstrn_to_string(buf, len))); + } + } + + xfree(buf); + } + + if (ea.cmdidx == CMD_USER) { + PUT(result, "cmd", CSTR_TO_OBJ((char *)USER_CMD(ea.useridx)->uc_name)); + } else if (ea.cmdidx == CMD_USER_BUF) { + PUT(result, "cmd", CSTR_TO_OBJ((char *)USER_CMD_GA(&curbuf->b_ucmds, ea.useridx)->uc_name)); + } else { + PUT(result, "cmd", CSTR_TO_OBJ((char *)get_command_name(NULL, ea.cmdidx))); + } + PUT(result, "line1", INTEGER_OBJ(ea.line1)); + PUT(result, "line2", INTEGER_OBJ(ea.line2)); + PUT(result, "bang", BOOLEAN_OBJ(ea.forceit)); + PUT(result, "args", ARRAY_OBJ(args)); + + char nargs[2]; + if (ea.argt & EX_EXTRA) { + if (ea.argt & EX_NOSPC) { + if (ea.argt & EX_NEEDARG) { + nargs[0] = '1'; + } else { + nargs[0] = '?'; + } + } else if (ea.argt & EX_NEEDARG) { + nargs[0] = '+'; + } else { + nargs[0] = '*'; + } + } else { + nargs[0] = '0'; + } + nargs[1] = '\0'; + PUT(result, "nargs", CSTR_TO_OBJ(nargs)); + + const char *addr; + switch (ea.addr_type) { + case ADDR_LINES: + addr = "line"; + break; + case ADDR_ARGUMENTS: + addr = "arg"; + break; + case ADDR_BUFFERS: + addr = "buf"; + break; + case ADDR_LOADED_BUFFERS: + addr = "load"; + break; + case ADDR_WINDOWS: + addr = "win"; + break; + case ADDR_TABS: + addr = "tab"; + break; + case ADDR_QUICKFIX: + addr = "qf"; + break; + case ADDR_NONE: + addr = "none"; + break; + default: + addr = "?"; + break; + } + PUT(result, "addr", CSTR_TO_OBJ(addr)); + 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(cmdmod.tab)); + PUT(mods, "verbose", INTEGER_OBJ(cmdinfo.verbose)); + PUT(mods, "browse", BOOLEAN_OBJ(cmdmod.browse)); + PUT(mods, "confirm", BOOLEAN_OBJ(cmdmod.confirm)); + PUT(mods, "hide", BOOLEAN_OBJ(cmdmod.hide)); + PUT(mods, "keepalt", BOOLEAN_OBJ(cmdmod.keepalt)); + PUT(mods, "keepjumps", BOOLEAN_OBJ(cmdmod.keepjumps)); + PUT(mods, "keepmarks", BOOLEAN_OBJ(cmdmod.keepmarks)); + PUT(mods, "keeppatterns", BOOLEAN_OBJ(cmdmod.keeppatterns)); + PUT(mods, "lockmarks", BOOLEAN_OBJ(cmdmod.lockmarks)); + PUT(mods, "noswapfile", BOOLEAN_OBJ(cmdmod.noswapfile)); + PUT(mods, "vertical", BOOLEAN_OBJ(cmdmod.split & WSP_VERT)); + + const char *split; + if (cmdmod.split & WSP_BOT) { + split = "botright"; + } else if (cmdmod.split & WSP_TOP) { + split = "topleft"; + } else if (cmdmod.split & WSP_BELOW) { + split = "belowright"; + } else if (cmdmod.split & WSP_ABOVE) { + split = "aboveleft"; + } else { + split = ""; + } + PUT(mods, "split", CSTR_TO_OBJ(split)); + + PUT(result, "mods", DICTIONARY_OBJ(mods)); + + Dictionary magic = ARRAY_DICT_INIT; + PUT(magic, "file", BOOLEAN_OBJ(cmdinfo.magic.file)); + PUT(magic, "bar", BOOLEAN_OBJ(cmdinfo.magic.bar)); + PUT(result, "magic", DICTIONARY_OBJ(magic)); +end: + xfree(cmdline); + return result; +} diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 5e37596884..e7704f72d7 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -354,7 +354,7 @@ static void parse_border_style(Object style, FloatConfig *fconfig, Error *err) if (style.type == kObjectTypeArray) { Array arr = style.data.array; size_t size = arr.size; - if (!size || size > 8 || (size & (size-1))) { + if (!size || size > 8 || (size & (size - 1))) { api_set_error(err, kErrorTypeValidation, "invalid number of border chars"); return; @@ -392,7 +392,7 @@ static void parse_border_style(Object style, FloatConfig *fconfig, Error *err) "border chars must be one cell"); return; } - size_t len = MIN(string.size, sizeof(*chars)-1); + size_t len = MIN(string.size, sizeof(*chars) - 1); if (len) { memcpy(chars[i], string.data, len); } @@ -400,8 +400,8 @@ static void parse_border_style(Object style, FloatConfig *fconfig, Error *err) hl_ids[i] = hl_id; } while (size < 8) { - memcpy(chars+size, chars, sizeof(*chars) * size); - memcpy(hl_ids+size, hl_ids, sizeof(*hl_ids) * size); + memcpy(chars + size, chars, sizeof(*chars) * size); + memcpy(hl_ids + size, hl_ids, sizeof(*hl_ids) * size); size <<= 1; } if ((chars[7][0] && chars[1][0] && !chars[0][0]) diff --git a/src/nvim/assert.h b/src/nvim/assert.h index 65519a8004..bc5260b914 100644 --- a/src/nvim/assert.h +++ b/src/nvim/assert.h @@ -1,5 +1,3 @@ -// uncrustify:off - #ifndef NVIM_ASSERT_H #define NVIM_ASSERT_H @@ -110,6 +108,8 @@ # define STATIC_ASSERT_STATEMENT STATIC_ASSERT_EXPR #endif +// uncrustify:off + #define ASSERT_CONCAT_(a, b) a##b #define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) // These can't be used after statements in c89. @@ -125,6 +125,8 @@ ((enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)), }) 0) #endif +// uncrustify:on + /// @def STRICT_ADD /// @brief Adds (a + b) and stores result in `c`. Aborts on overflow. /// diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 783cec4d60..bfeb70dce9 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -4,6 +4,7 @@ // autocmd.c: Autocommand related functions #include <signal.h> +#include "lauxlib.h" #include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/autocmd.h" @@ -28,8 +29,6 @@ #include "nvim/vim.h" #include "nvim/window.h" -#include "lauxlib.h" - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "auevents_name_map.generated.h" # include "autocmd.c.generated.h" @@ -625,8 +624,7 @@ event_T event_name2nr(const char_u *start, char_u **end) int i; // the event name ends with end of line, '|', a blank or a comma - for (p = start; *p && !ascii_iswhite(*p) && *p != ',' && *p != '|'; p++) { - } + for (p = start; *p && !ascii_iswhite(*p) && *p != ',' && *p != '|'; p++) {} for (i = 0; event_names[i].name != NULL; i++) { int len = (int)event_names[i].len; if (len == p - start && STRNICMP(event_names[i].name, start, len) == 0) { @@ -833,7 +831,7 @@ void do_autocmd(char_u *arg_in, int forceit) // Find the start of the commands. // Expand <sfile> in it. if (*cmd != NUL) { - cmd = expand_sfile(cmd); + cmd = (char_u *)expand_sfile((char *)cmd); if (cmd == NULL) { // some error return; } @@ -2609,8 +2607,7 @@ static int arg_augroup_get(char_u **argp) char_u *arg = *argp; int group = AUGROUP_ALL; - for (p = arg; *p && !ascii_iswhite(*p) && *p != '|'; p++) { - } + for (p = arg; *p && !ascii_iswhite(*p) && *p != '|'; p++) {} if (p > arg) { char_u *group_name = vim_strnsave(arg, (size_t)(p - arg)); group = augroup_find((char *)group_name); diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 99a24464a8..c70d845c42 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2343,9 +2343,9 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) // if the current buffer is first in the list, place it at the end if (matches[0].buf == curbuf) { for (int i = 1; i < count; i++) { - (*file)[i-1] = matches[i].match; + (*file)[i - 1] = matches[i].match; } - (*file)[count-1] = matches[0].match; + (*file)[count - 1] = matches[0].match; } else { for (int i = 0; i < count; i++) { (*file)[i] = matches[i].match; @@ -4870,7 +4870,7 @@ void do_arg_all(int count, int forceit, int keep_tabs) new_curwin = curwin; new_curtab = curtab; } - (void)do_ecmd(0, alist_name(&AARGLIST(alist)[i]), NULL, NULL, ECMD_ONE, + (void)do_ecmd(0, (char *)alist_name(&AARGLIST(alist)[i]), NULL, NULL, ECMD_ONE, ((buf_hide(curwin->w_buffer) || bufIsChanged(curwin->w_buffer)) ? ECMD_HIDE : 0) + ECMD_OLDBUF, @@ -5410,8 +5410,8 @@ static int buf_signcols_inner(buf_T *buf, int maximum) if (sign->se_lnum > curline) { // Counted all signs, now add extmark signs if (curline > 0) { - linesum += decor_signcols(buf, &decor_state, (int)curline-1, (int)curline-1, - maximum-linesum); + linesum += decor_signcols(buf, &decor_state, (int)curline - 1, (int)curline - 1, + maximum - linesum); } curline = sign->se_lnum; if (linesum > signcols) { @@ -5429,7 +5429,8 @@ static int buf_signcols_inner(buf_T *buf, int maximum) } if (curline > 0) { - linesum += decor_signcols(buf, &decor_state, (int)curline-1, (int)curline-1, maximum-linesum); + linesum += decor_signcols(buf, &decor_state, (int)curline - 1, (int)curline - 1, + maximum - linesum); } if (linesum > signcols) { signcols = linesum; @@ -5439,7 +5440,7 @@ static int buf_signcols_inner(buf_T *buf, int maximum) } // Check extmarks between signs - linesum = decor_signcols(buf, &decor_state, 0, (int)buf->b_ml.ml_line_count-1, maximum); + linesum = decor_signcols(buf, &decor_state, 0, (int)buf->b_ml.ml_line_count - 1, maximum); if (linesum > signcols) { signcols = linesum; @@ -5511,8 +5512,8 @@ void buf_signcols_add_check(buf_T *buf, sign_entry_T *added) for (; s->se_next && s->se_lnum == s->se_next->se_lnum; s = s->se_next) { linesum++; } - linesum += decor_signcols(buf, &decor_state, (int)s->se_lnum-1, (int)s->se_lnum-1, - SIGN_SHOW_MAX-linesum); + linesum += decor_signcols(buf, &decor_state, (int)s->se_lnum - 1, (int)s->se_lnum - 1, + SIGN_SHOW_MAX - linesum); if (linesum > buf->b_signcols.size) { buf->b_signcols.size = linesum; diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 8d2f7c4545..1d994a9ff0 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -356,6 +356,8 @@ struct mapblock { LuaRef m_luaref; // lua function reference as rhs int m_keylen; // strlen(m_keys) int m_mode; // valid mode + int m_simplified; // m_keys was simplified, do no use this map + // if keys are typed int m_noremap; // if non-zero no re-mapping for m_str char m_silent; // <silent> used, don't echo commands char m_nowait; // <nowait> used @@ -1152,7 +1154,7 @@ struct VimMenu { char *name; ///< Name of menu, possibly translated char *dname; ///< Displayed Name ("name" without '&') char *en_name; ///< "name" untranslated, NULL when - ///< was not translated + ///< was not translated char *en_dname; ///< NULL when "dname" untranslated int mnemonic; ///< mnemonic key (after '&') char *actext; ///< accelerator text (after TAB) diff --git a/src/nvim/change.c b/src/nvim/change.c index 024969415d..c751507955 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -369,7 +369,7 @@ void changed_bytes(linenr_T lnum, colnr_T col) void inserted_bytes(linenr_T lnum, colnr_T col, int old, int new) { if (curbuf_splice_pending == 0) { - extmark_splice_cols(curbuf, (int)lnum-1, col, old, new, kExtmarkUndo); + extmark_splice_cols(curbuf, (int)lnum - 1, col, old, new, kExtmarkUndo); } changed_bytes(lnum, col); @@ -1306,8 +1306,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) p--; } for (lead_repl = p; lead_repl > curbuf->b_p_com - && lead_repl[-1] != ':'; lead_repl--) { - } + && lead_repl[-1] != ':'; lead_repl--) {} lead_repl_len = (int)(p - lead_repl); // We can probably always add an extra space when doing "O" on @@ -1379,8 +1378,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (c == COM_RIGHT) { // right adjusted leader // find last non-white in the leader to line up with for (p = leader + lead_len - 1; p > leader - && ascii_iswhite(*p); p--) { - } + && ascii_iswhite(*p); p--) {} p++; // Compute the length of the replaced characters in @@ -1728,8 +1726,8 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } // Always move extmarks - Here we move only the line where the // cursor is, the previous mark_adjust takes care of the lines after - int cols_added = mincol-1+less_cols_off-less_cols; - extmark_splice(curbuf, (int)lnum-1, mincol-1 - cols_spliced, + int cols_added = mincol - 1 + less_cols_off - less_cols; + extmark_splice(curbuf, (int)lnum - 1, mincol - 1 - cols_spliced, 0, less_cols_off, less_cols_off, 1, cols_added, 1 + cols_added, kExtmarkUndo); } else { @@ -1745,8 +1743,8 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) changed_lines(curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L, true); // bail out and just get the final length of the line we just manipulated bcount_t extra = (bcount_t)STRLEN(ml_get(curwin->w_cursor.lnum)); - extmark_splice(curbuf, (int)curwin->w_cursor.lnum-1, 0, - 0, 0, 0, 1, 0, 1+extra, kExtmarkUndo); + extmark_splice(curbuf, (int)curwin->w_cursor.lnum - 1, 0, + 0, 0, 0, 1, 0, 1 + extra, kExtmarkUndo); } curbuf_splice_pending--; @@ -1942,8 +1940,7 @@ int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_spa string++; } } - for (j = 0; string[j] != NUL && string[j] == line[i + j]; j++) { - } + for (j = 0; string[j] != NUL && string[j] == line[i + j]; j++) {} if (string[j] != NUL) { continue; // string doesn't match } @@ -2081,8 +2078,7 @@ int get_last_leader_offset(char_u *line, char_u **flags) // whitespace. Otherwise we would think we are inside a // comment if the middle part appears somewhere in the middle // of the line. E.g. for C the "*" appears often. - for (j = 0; j <= i && ascii_iswhite(line[j]); j++) { - } + for (j = 0; j <= i && ascii_iswhite(line[j]); j++) {} if (j < i) { continue; } diff --git a/src/nvim/channel.c b/src/nvim/channel.c index ac6c9cd110..cc76c6cf2d 100644 --- a/src/nvim/channel.c +++ b/src/nvim/channel.c @@ -25,7 +25,7 @@ static bool did_stdio = false; /// next free id for a job or rpc channel /// 1 is reserved for stdio channel /// 2 is reserved for stderr channel -static uint64_t next_chan_id = CHAN_STDERR+1; +static uint64_t next_chan_id = CHAN_STDERR + 1; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "channel.c.generated.h" diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index 73adff6579..82c3a714b1 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -23,15 +23,15 @@ cursorentry_T shape_table[SHAPE_IDX_COUNT] = { // Values are set by 'guicursor' and 'mouseshape'. // Adjust the SHAPE_IDX_ defines when changing this! - { "normal", 0, 0, 0, 700L, 400L, 250L, 0, 0, "n", SHAPE_CURSOR+SHAPE_MOUSE }, - { "visual", 0, 0, 0, 700L, 400L, 250L, 0, 0, "v", SHAPE_CURSOR+SHAPE_MOUSE }, - { "insert", 0, 0, 0, 700L, 400L, 250L, 0, 0, "i", SHAPE_CURSOR+SHAPE_MOUSE }, - { "replace", 0, 0, 0, 700L, 400L, 250L, 0, 0, "r", SHAPE_CURSOR+SHAPE_MOUSE }, - { "cmdline_normal", 0, 0, 0, 700L, 400L, 250L, 0, 0, "c", SHAPE_CURSOR+SHAPE_MOUSE }, - { "cmdline_insert", 0, 0, 0, 700L, 400L, 250L, 0, 0, "ci", SHAPE_CURSOR+SHAPE_MOUSE }, - { "cmdline_replace", 0, 0, 0, 700L, 400L, 250L, 0, 0, "cr", SHAPE_CURSOR+SHAPE_MOUSE }, - { "operator", 0, 0, 0, 700L, 400L, 250L, 0, 0, "o", SHAPE_CURSOR+SHAPE_MOUSE }, - { "visual_select", 0, 0, 0, 700L, 400L, 250L, 0, 0, "ve", SHAPE_CURSOR+SHAPE_MOUSE }, + { "normal", 0, 0, 0, 700L, 400L, 250L, 0, 0, "n", SHAPE_CURSOR + SHAPE_MOUSE }, + { "visual", 0, 0, 0, 700L, 400L, 250L, 0, 0, "v", SHAPE_CURSOR + SHAPE_MOUSE }, + { "insert", 0, 0, 0, 700L, 400L, 250L, 0, 0, "i", SHAPE_CURSOR + SHAPE_MOUSE }, + { "replace", 0, 0, 0, 700L, 400L, 250L, 0, 0, "r", SHAPE_CURSOR + SHAPE_MOUSE }, + { "cmdline_normal", 0, 0, 0, 700L, 400L, 250L, 0, 0, "c", SHAPE_CURSOR + SHAPE_MOUSE }, + { "cmdline_insert", 0, 0, 0, 700L, 400L, 250L, 0, 0, "ci", SHAPE_CURSOR + SHAPE_MOUSE }, + { "cmdline_replace", 0, 0, 0, 700L, 400L, 250L, 0, 0, "cr", SHAPE_CURSOR + SHAPE_MOUSE }, + { "operator", 0, 0, 0, 700L, 400L, 250L, 0, 0, "o", SHAPE_CURSOR + SHAPE_MOUSE }, + { "visual_select", 0, 0, 0, 700L, 400L, 250L, 0, 0, "ve", SHAPE_CURSOR + SHAPE_MOUSE }, { "cmdline_hover", 0, 0, 0, 0L, 0L, 0L, 0, 0, "e", SHAPE_MOUSE }, { "statusline_hover", 0, 0, 0, 0L, 0L, 0L, 0, 0, "s", SHAPE_MOUSE }, { "statusline_drag", 0, 0, 0, 0L, 0L, 0L, 0, 0, "sd", SHAPE_MOUSE }, diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index cd823546b4..c6fd8aade3 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -263,8 +263,7 @@ void do_debug(char_u *cmd) // don't debug this command n = debug_break_level; debug_break_level = -1; - (void)do_cmdline(cmdline, getexline, NULL, - DOCMD_VERBOSE|DOCMD_EXCRESET); + (void)do_cmdline((char *)cmdline, getexline, NULL, DOCMD_VERBOSE|DOCMD_EXCRESET); debug_break_level = n; } lines_left = Rows - 1; @@ -406,7 +405,7 @@ void dbg_check_breakpoint(exarg_T *eap) debug_breakpoint_name + (*p == NUL ? 0 : 3), (int64_t)debug_breakpoint_lnum); debug_breakpoint_name = NULL; - do_debug(eap->cmd); + do_debug((char_u *)eap->cmd); } else { debug_skipped = true; debug_skipped_name = debug_breakpoint_name; @@ -414,7 +413,7 @@ void dbg_check_breakpoint(exarg_T *eap) } } else if (ex_nesting_level <= debug_break_level) { if (!eap->skip) { - do_debug(eap->cmd); + do_debug((char_u *)eap->cmd); } else { debug_skipped = true; debug_skipped_name = NULL; diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c index a0f189ca38..c8f4b3e875 100644 --- a/src/nvim/decoration.c +++ b/src/nvim/decoration.c @@ -45,7 +45,7 @@ void bufhl_add_hl_pos_offset(buf_T *buf, int src_id, int hl_id, lpos_T pos_start // substituted text. But it would be more consistent to highlight // a space _after_ the previous line instead (like highlight EOL list // char) - hl_start = MAX(offset-1, 0); + hl_start = MAX(offset - 1, 0); end_off = 1; hl_end = 0; } else if (lnum == pos_start.lnum && lnum < pos_end.lnum) { @@ -53,14 +53,14 @@ void bufhl_add_hl_pos_offset(buf_T *buf, int src_id, int hl_id, lpos_T pos_start end_off = 1; hl_end = 0; } else if (pos_start.lnum < lnum && lnum == pos_end.lnum) { - hl_start = MAX(offset-1, 0); + hl_start = MAX(offset - 1, 0); hl_end = pos_end.col + offset; } else if (pos_start.lnum == lnum && pos_end.lnum == lnum) { hl_start = pos_start.col + offset; hl_end = pos_end.col + offset; } extmark_set(buf, (uint32_t)src_id, NULL, - (int)lnum-1, hl_start, (int)lnum-1+end_off, hl_end, + (int)lnum - 1, hl_start, (int)lnum - 1 + end_off, hl_end, &decor, true, false, kExtmarkNoUndo); } } @@ -69,17 +69,17 @@ void decor_redraw(buf_T *buf, int row1, int row2, Decoration *decor) { if (row2 >= row1) { if (!decor || decor->hl_id || decor_has_sign(decor)) { - redraw_buf_range_later(buf, row1+1, row2+1); + redraw_buf_range_later(buf, row1 + 1, row2 + 1); } } if (decor && kv_size(decor->virt_text)) { - redraw_buf_line_later(buf, row1+1); + redraw_buf_line_later(buf, row1 + 1); } if (decor && kv_size(decor->virt_lines)) { redraw_buf_line_later(buf, MIN(buf->b_ml.ml_line_count, - row1+1+(decor->virt_lines_above?0:1))); + row1 + 1 + (decor->virt_lines_above?0:1))); } } @@ -96,7 +96,7 @@ void decor_remove(buf_T *buf, int row, int row2, Decoration *decor) buf->b_signs--; } if (row2 >= row && decor->sign_text) { - buf_signcols_del_check(buf, row+1, row2+1); + buf_signcols_del_check(buf, row + 1, row2 + 1); } } decor_free(decor); @@ -256,12 +256,12 @@ static void decor_add(DecorState *state, int start_row, int start_col, int end_r kv_pushp(state->active); size_t index; - for (index = kv_size(state->active)-1; index > 0; index--) { - DecorRange item = kv_A(state->active, index-1); + for (index = kv_size(state->active) - 1; index > 0; index--) { + DecorRange item = kv_A(state->active, index - 1); if (item.decor.priority <= range.decor.priority) { break; } - kv_A(state->active, index) = kv_A(state->active, index-1); + kv_A(state->active, index) = kv_A(state->active, index - 1); } kv_A(state->active, index) = range; } @@ -279,7 +279,7 @@ int decor_redraw_col(buf_T *buf, int col, int win_col, bool hidden, DecorState * if (mark.pos.row < 0 || mark.pos.row > state->row) { break; } else if (mark.pos.row == state->row && mark.pos.col > col) { - state->col_until = mark.pos.col-1; + state->col_until = mark.pos.col - 1; break; } @@ -329,11 +329,11 @@ next_mark: || (item.start_row == state->row && item.start_col <= col)) { active = true; if (item.end_row == state->row && item.end_col > col) { - state->col_until = MIN(state->col_until, item.end_col-1); + state->col_until = MIN(state->col_until, item.end_col - 1); } } else { if (item.start_row == state->row) { - state->col_until = MIN(state->col_until, item.start_col-1); + state->col_until = MIN(state->col_until, item.start_col - 1); } } } @@ -397,7 +397,7 @@ void decor_redraw_signs(buf_T *buf, int row, int *num_signs, sign_attrs_T sattrs if (sattrs[j].sat_prio <= decor->priority) { break; } - sattrs[j] = sattrs[j-1]; + sattrs[j] = sattrs[j - 1]; } if (j < SIGN_SHOW_MAX) { memset(&sattrs[j], 0, sizeof(sign_attrs_T)); @@ -538,7 +538,6 @@ void decor_add_ephemeral(int start_row, int start_col, int end_row, int end_col, } - int decor_virt_lines(win_T *wp, linenr_T lnum, VirtLines *lines) { buf_T *buf = wp->w_buffer; diff --git a/src/nvim/decoration_provider.c b/src/nvim/decoration_provider.c index 6efcb08b9d..ef27b2af1c 100644 --- a/src/nvim/decoration_provider.c +++ b/src/nvim/decoration_provider.c @@ -16,8 +16,8 @@ static kvec_t(DecorProvider) decor_providers = KV_INITIAL_VALUE; LUA_NOREF, LUA_NOREF, LUA_NOREF, \ LUA_NOREF, -1 } -static bool decor_provider_invoke(NS ns_id, const char *name, LuaRef ref, - Array args, bool default_true, char **perr) +static bool decor_provider_invoke(NS ns_id, const char *name, LuaRef ref, Array args, + bool default_true, char **perr) { Error err = ERROR_INIT; @@ -100,7 +100,7 @@ void decor_providers_invoke_win(win_T *wp, DecorProviders *providers, args.items[0] = WINDOW_OBJ(wp->handle); args.items[1] = BUFFER_OBJ(wp->w_buffer->handle); // TODO(bfredl): we are not using this, but should be first drawn line? - args.items[2] = INTEGER_OBJ(wp->w_topline-1); + args.items[2] = INTEGER_OBJ(wp->w_topline - 1); args.items[3] = INTEGER_OBJ(knownmax); if (decor_provider_invoke(p->ns_id, "win", p->redraw_win, args, true, err)) { kvi_push(*line_providers, p); @@ -228,4 +228,3 @@ void decor_free_all_mem(void) } kv_destroy(decor_providers); } - diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 2fa96e4fc2..cfb1c35817 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -2558,8 +2558,7 @@ void ex_diffgetput(exarg_T *eap) p--; } - for (i = 0; ascii_isdigit(eap->arg[i]) && eap->arg + i < p; i++) { - } + for (i = 0; ascii_isdigit(eap->arg[i]) && eap->arg + i < p; i++) {} if (eap->arg + i == p) { // digits only diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 0e148543aa..02851b235f 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -36,11 +36,11 @@ typedef struct digraph { } digr_T; static char e_digraph_must_be_just_two_characters_str[] - = N_("E1214: Digraph must be just two characters: %s"); + = N_("E1214: Digraph must be just two characters: %s"); static char e_digraph_argument_must_be_one_character_str[] - = N_("E1215: Digraph must be one character: %s"); + = N_("E1215: Digraph must be one character: %s"); static char e_digraph_setlist_argument_must_be_list_of_lists_with_two_items[] - = N_("E1216: digraph_setlist() argument must be a list of lists with two items"); + = N_("E1216: digraph_setlist() argument must be a list of lists with two items"); #ifdef INCLUDE_GENERATED_DECLARATIONS # include "digraph.c.generated.h" @@ -1513,8 +1513,10 @@ char_u *get_digraph_for_char(int val_arg) int get_digraph(bool cmdline) { no_mapping++; + allow_keys++; int c = plain_vgetc(); no_mapping--; + allow_keys--; if (c != ESC) { // ESC cancels CTRL-K @@ -1531,8 +1533,10 @@ int get_digraph(bool cmdline) add_to_showcmd(c); } no_mapping++; + allow_keys++; int cc = plain_vgetc(); no_mapping--; + allow_keys--; if (cc != ESC) { // ESC cancels CTRL-K diff --git a/src/nvim/digraph.h b/src/nvim/digraph.h index 80b4148213..039fc3370d 100644 --- a/src/nvim/digraph.h +++ b/src/nvim/digraph.h @@ -1,8 +1,8 @@ #ifndef NVIM_DIGRAPH_H #define NVIM_DIGRAPH_H -#include "nvim/ex_cmds_defs.h" #include "nvim/eval/funcs.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/types.h" #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 48436f1115..a94f7a803a 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -762,8 +762,10 @@ static int insert_execute(VimState *state, int key) // may need to redraw when no more chars available now ins_redraw(false); no_mapping++; + allow_keys++; s->c = plain_vgetc(); no_mapping--; + allow_keys--; if (s->c != Ctrl_N && s->c != Ctrl_G && s->c != Ctrl_O) { // it's something else vungetc(s->c); @@ -1587,7 +1589,8 @@ static void ins_ctrl_v(void) add_to_showcmd_c(Ctrl_V); - c = get_literal(); + // Do not include modifiers into the key for CTRL-SHIFT-V. + c = get_literal(mod_mask & MOD_MASK_SHIFT); if (did_putchar) { // when the line fits in 'columns' the '^' is at the start of the next // line and will not removed by the redraw @@ -2000,7 +2003,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang // TODO(bfredl): test for crazy edge cases, like we stand on a TAB or // something? does this even do the right text change then? int delta = orig_col - new_col; - extmark_splice_cols(curbuf, curwin->w_cursor.lnum-1, new_col, + extmark_splice_cols(curbuf, curwin->w_cursor.lnum - 1, new_col, delta < 0 ? -delta : 0, delta > 0 ? delta : 0, kExtmarkUndo); @@ -3959,8 +3962,7 @@ static buf_T *ins_compl_next_buf(buf_T *buf, int flag) } assert(wp); while ((wp = (wp->w_next != NULL ? wp->w_next : firstwin)) != curwin - && wp->w_buffer->b_scanned) { - } + && wp->w_buffer->b_scanned) {} buf = wp->w_buffer; } else { /* 'b' (just loaded buffers), 'u' (just non-loaded buffers) or 'U' @@ -3971,8 +3973,7 @@ static buf_T *ins_compl_next_buf(buf_T *buf, int flag) ? buf->b_p_bl : (!buf->b_p_bl || (buf->b_ml.ml_mfp == NULL) != (flag == 'u'))) - || buf->b_scanned)) { - } + || buf->b_scanned)) {} } return buf; } @@ -5175,8 +5176,7 @@ static int ins_complete(int c, bool enable_pum) if ((compl_cont_status & CONT_SOL) || ctrl_x_mode == CTRL_X_PATH_DEFINES) { if (!(compl_cont_status & CONT_ADDING)) { - while (--startcol >= 0 && vim_isIDc(line[startcol])) { - } + while (--startcol >= 0 && vim_isIDc(line[startcol])) {} compl_col += ++startcol; compl_length = curs_col - startcol; } @@ -5612,13 +5612,13 @@ static unsigned quote_meta(char_u *dest, char_u *src, int len) return m; } -/* - * Next character is interpreted literally. - * A one, two or three digit decimal number is interpreted as its byte value. - * If one or two digits are entered, the next character is given to vungetc(). - * For Unicode a character > 255 may be returned. - */ -int get_literal(void) +/// Next character is interpreted literally. +/// A one, two or three digit decimal number is interpreted as its byte value. +/// If one or two digits are entered, the next character is given to vungetc(). +/// For Unicode a character > 255 may be returned. +/// +/// @param no_simplify do not include modifiers into the key +int get_literal(bool no_simplify) { int cc; int nc; @@ -5636,6 +5636,9 @@ int get_literal(void) i = 0; for (;;) { nc = plain_vgetc(); + if (!no_simplify) { + nc = merge_modifiers(nc, &mod_mask); + } if ((mod_mask & ~MOD_MASK_SHIFT) != 0) { // A character with non-Shift modifiers should not be a valid // character for i_CTRL-V_digit. @@ -5864,8 +5867,7 @@ void insertchar(int c, int flags, int second_indent) // Skip white space before the cursor i = curwin->w_cursor.col; - while (--i >= 0 && ascii_iswhite(line[i])) { - } + while (--i >= 0 && ascii_iswhite(line[i])) {} i++; // Skip to before the middle leader @@ -5936,7 +5938,7 @@ void insertchar(int c, int flags, int second_indent) } do_digraph(-1); // clear digraphs - do_digraph(buf[i-1]); // may be the start of a digraph + do_digraph(buf[i - 1]); // may be the start of a digraph buf[i] = NUL; ins_str(buf); if (flags & INSCHAR_CTRLV) { @@ -6453,7 +6455,7 @@ void auto_format(bool trailblank, bool prev_line) * be adjusted for the text formatting. */ saved_cursor = pos; - format_lines((linenr_T)-1, FALSE); + format_lines((linenr_T) - 1, false); curwin->w_cursor = saved_cursor; saved_cursor.lnum = 0; @@ -7711,7 +7713,7 @@ int hkmap(int c) (char_u)BET, // b (char_u)hKAF, // c (char_u)DALET, // d - (char_u)-1, // e + (char_u) - 1, // e (char_u)PEIsofit, // f (char_u)GIMEL, // g (char_u)HEI, // h @@ -7723,14 +7725,14 @@ int hkmap(int c) (char_u)NUN, // n (char_u)SAMEH, // o (char_u)PEI, // p - (char_u)-1, // q + (char_u) - 1, // q (char_u)RESH, // r (char_u)ZAIN, // s (char_u)TAV, // t (char_u)TET, // u (char_u)VAV, // v (char_u)hSHIN, // w - (char_u)-1, // x + (char_u) - 1, // x (char_u)AIN, // y (char_u)ZADI, // z }; @@ -7811,11 +7813,10 @@ static void ins_reg(void) } - /* - * Don't map the register name. This also prevents the mode message to be - * deleted when ESC is hit. - */ - ++no_mapping; + // Don't map the register name. This also prevents the mode message to be + // deleted when ESC is hit. + no_mapping++; + allow_keys++; regname = plain_vgetc(); LANGMAP_ADJUST(regname, TRUE); if (regname == Ctrl_R || regname == Ctrl_O || regname == Ctrl_P) { @@ -7825,7 +7826,8 @@ static void ins_reg(void) regname = plain_vgetc(); LANGMAP_ADJUST(regname, TRUE); } - --no_mapping; + no_mapping--; + allow_keys--; // Don't call u_sync() while typing the expression or giving an error // message for it. Only call it explicitly. @@ -7893,13 +7895,13 @@ static void ins_ctrl_g(void) // Right after CTRL-X the cursor will be after the ruler. setcursor(); - /* - * Don't map the second key. This also prevents the mode message to be - * deleted when ESC is hit. - */ - ++no_mapping; + // Don't map the second key. This also prevents the mode message to be + // deleted when ESC is hit. + no_mapping++; + allow_keys++; c = plain_vgetc(); - --no_mapping; + no_mapping--; + allow_keys--; switch (c) { // CTRL-G k and CTRL-G <Up>: cursor up to Insstart.col case K_UP: @@ -9233,8 +9235,10 @@ static int ins_digraph(void) // don't map the digraph chars. This also prevents the // mode message to be deleted when ESC is hit no_mapping++; + allow_keys++; c = plain_vgetc(); no_mapping--; + allow_keys--; if (did_putchar) { // when the line fits in 'columns' the '?' is at the start of the next // line and will not be removed by the redraw @@ -9260,8 +9264,10 @@ static int ins_digraph(void) add_to_showcmd_c(c); } no_mapping++; + allow_keys++; cc = plain_vgetc(); no_mapping--; + allow_keys--; if (did_putchar) { // when the line fits in 'columns' the '?' is at the start of the // next line and will not be removed by a redraw @@ -9383,8 +9389,7 @@ static void ins_try_si(int c) ptr = ml_get(pos->lnum); i = pos->col; if (i > 0) { // skip blanks before '{' - while (--i > 0 && ascii_iswhite(ptr[i])) { - } + while (--i > 0 && ascii_iswhite(ptr[i])) {} } curwin->w_cursor.lnum = pos->lnum; curwin->w_cursor.col = i; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index e192a6de6b..da869df5cc 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -161,7 +161,7 @@ static struct vimvar { VV(VV_STATUSMSG, "statusmsg", VAR_STRING, 0), VV(VV_SHELL_ERROR, "shell_error", VAR_NUMBER, VV_RO), VV(VV_THIS_SESSION, "this_session", VAR_STRING, 0), - VV(VV_VERSION, "version", VAR_NUMBER, VV_COMPAT+VV_RO), + VV(VV_VERSION, "version", VAR_NUMBER, VV_COMPAT + VV_RO), VV(VV_LNUM, "lnum", VAR_NUMBER, VV_RO_SBX), VV(VV_TERMRESPONSE, "termresponse", VAR_STRING, VV_RO), VV(VV_FNAME, "fname", VAR_STRING, VV_RO), @@ -2095,8 +2095,7 @@ char_u *get_lval(char_u *const name, typval_T *const rettv, lval_T *const lp, co char_u *key = NULL; if (*p == '.') { key = p + 1; - for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; len++) { - } + for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; len++) {} if (len == 0) { if (!quiet) { emsg(_("E713: Cannot use empty key after .")); @@ -2444,6 +2443,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, co ? lp->ll_tv->v_lock : lp->ll_tv->vval.v_dict->dv_lock, lp->ll_name, TV_CSTRING)) { + // Skip } else if (lp->ll_range) { listitem_T *ll_li = lp->ll_li; int ll_n1 = lp->ll_n1; @@ -2774,8 +2774,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) xp->xp_context = EXPAND_NOTHING; } else if (c == '\'') { // literal string // Trick: '' is like stopping and starting a literal string. - while ((c = *++xp->xp_pattern) != NUL && c != '\'') { - } + while ((c = *++xp->xp_pattern) != NUL && c != '\'') {} xp->xp_context = EXPAND_NOTHING; } else if (c == '|') { if (xp->xp_pattern[1] == '|') { @@ -2794,8 +2793,7 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) } arg = xp->xp_pattern; if (*arg != NUL) { - while ((c = *++arg) != NUL && (c == ' ' || c == '\t')) { - } + while ((c = *++arg) != NUL && (c == ' ' || c == '\t')) {} } } @@ -3972,12 +3970,16 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string) if (op == '*') { f1 = f1 * f2; } else if (op == '/') { + // uncrustify:off + // Division by zero triggers error from AddressSanitizer f1 = (f2 == 0 ? ( #ifdef NAN f1 == 0 ? (float_T)NAN : #endif (f1 > 0 ? (float_T)INFINITY : (float_T)-INFINITY)) : f1 / f2); + + // uncrustify:on } else { emsg(_("E804: Cannot use '%' with Float")); return FAIL; @@ -4532,8 +4534,7 @@ static int eval_index(char_u **arg, typval_T *rettv, int evaluate, int verbose) * dict.name */ key = *arg + 1; - for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; len++) { - } + for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; len++) {} if (len == 0) { return FAIL; } @@ -4964,8 +4965,13 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) break; // Special key, e.g.: "\<C-W>" - case '<': - extra = trans_special((const char_u **)&p, STRLEN(p), name, true, true); + case '<': { + int flags = FSK_KEYCODE | FSK_IN_STRING; + + if (p[1] != '*') { + flags |= FSK_SIMPLIFY; + } + extra = trans_special((const char_u **)&p, STRLEN(p), name, flags, NULL); if (extra != 0) { name += extra; if (name >= rettv->vval.v_string + len) { @@ -4973,6 +4979,7 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) } break; } + } FALLTHROUGH; default: @@ -5700,8 +5707,7 @@ static int get_literal_key(char_u **arg, typval_T *tv) if (!ASCII_ISALNUM(**arg) && **arg != '_' && **arg != '-') { return FAIL; } - for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; p++) { - } + for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; p++) {} tv->v_type = VAR_STRING; tv->vval.v_string = vim_strnsave(*arg, p - *arg); @@ -5837,7 +5843,7 @@ size_t string2float(const char *const text, float_T *const ret_value) return 3; } if (STRNICMP(text, "-inf", 3) == 0) { - *ret_value = (float_T)-INFINITY; + *ret_value = (float_T) - INFINITY; return 4; } if (STRNICMP(text, "nan", 3) == 0) { @@ -6638,8 +6644,8 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const const int xp_namelen = (int)strlen(xp_name); uint32_t argt; - if (parse_compl_arg((char_u *)xp_name, xp_namelen, &xp_type, - &argt, (char_u **)&xp_arg) == FAIL) { + if (parse_compl_arg(xp_name, xp_namelen, &xp_type, + &argt, &xp_arg) == FAIL) { return; } } @@ -6653,7 +6659,7 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const if (!ui_has(kUICmdline)) { const char *lastnl = strrchr(prompt, '\n'); if (lastnl != NULL) { - p = lastnl+1; + p = lastnl + 1; msg_start(); msg_clr_eos(); msg_puts_attr_len(prompt, p - prompt, echo_attr); @@ -7938,8 +7944,7 @@ static int get_env_len(const char_u **arg) int len; const char_u *p; - for (p = *arg; vim_isIDc(*p); p++) { - } + for (p = *arg; vim_isIDc(*p); p++) {} if (p == *arg) { // No name found. return 0; } @@ -8081,8 +8086,7 @@ const char_u *find_name_end(const char_u *arg, const char_u **expr_start, const || br_nest != 0); MB_PTR_ADV(p)) { if (*p == '\'') { // skip over 'string' to avoid counting [ and ] inside it. - for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p)) { - } + for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p)) {} if (*p == NUL) { break; } @@ -8556,7 +8560,7 @@ int check_luafunc_name(const char *const str, const bool paren) if (*p != (paren ? '(' : NUL)) { return 0; } else { - return (int)(p-str); + return (int)(p - str); } } @@ -9575,8 +9579,7 @@ void ex_execute(exarg_T *eap) did_emsg = save_did_emsg; } } else if (eap->cmdidx == CMD_execute) { - do_cmdline((char_u *)ga.ga_data, - eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE); + do_cmdline(ga.ga_data, eap->getline, eap->cookie, DOCMD_NOWAIT|DOCMD_VERBOSE); } } diff --git a/src/nvim/eval.h b/src/nvim/eval.h index a9ec5d47a6..83e9c6370d 100644 --- a/src/nvim/eval.h +++ b/src/nvim/eval.h @@ -235,8 +235,7 @@ typedef struct { } timer_T; /// Type of assert_* check being performed -typedef enum -{ +typedef enum { ASSERT_EQUAL, ASSERT_NOTEQUAL, ASSERT_MATCH, diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index f97ceedeb7..c6993d2ff8 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -15,8 +15,8 @@ #include "nvim/charset.h" #include "nvim/context.h" #include "nvim/cursor.h" -#include "nvim/digraph.h" #include "nvim/diff.h" +#include "nvim/digraph.h" #include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/decode.h" @@ -135,8 +135,7 @@ char_u *get_function_name(expand_T *xp, int idx) } } while ((size_t)++intidx < ARRAY_SIZE(functions) - && functions[intidx].name[0] == '\0') { - } + && functions[intidx].name[0] == '\0') {} if ((size_t)intidx >= ARRAY_SIZE(functions)) { return NULL; @@ -1019,7 +1018,7 @@ static void f_chdir(typval_T *argvars, typval_T *rettv, FunPtr fptr) scope = kCdScopeTabpage; } - if (!changedir_func(argvars[0].vval.v_string, scope)) { + if (!changedir_func((char *)argvars[0].vval.v_string, scope)) { // Directory change failed XFREE_CLEAR(rettv->vval.v_string); } @@ -2194,7 +2193,7 @@ static void f_expandcmd(typval_T *argvars, typval_T *rettv, FunPtr fptr) char_u *cmdstr = (char_u *)xstrdup(tv_get_string(&argvars[0])); exarg_T eap = { - .cmd = cmdstr, + .cmd = (char *)cmdstr, .arg = cmdstr, .usefilter = false, .nextcmd = NULL, @@ -2445,7 +2444,7 @@ static void f_float2nr(typval_T *argvars, typval_T *rettv, FunPtr fptr) float_T f; if (tv_get_float_chk(argvars, &f)) { - if (f <= (float_T)-VARNUMBER_MAX + DBL_EPSILON) { + if (f <= (float_T) - VARNUMBER_MAX + DBL_EPSILON) { rettv->vval.v_number = -VARNUMBER_MAX; } else if (f >= (float_T)VARNUMBER_MAX - DBL_EPSILON) { rettv->vval.v_number = VARNUMBER_MAX; @@ -2631,8 +2630,7 @@ static void f_foldtextresult(typval_T *argvars, typval_T *rettv, FunPtr fptr) /// "foreground()" function static void f_foreground(typval_T *argvars, typval_T *rettv, FunPtr fptr) -{ -} +{} static void f_funcref(typval_T *argvars, typval_T *rettv, FunPtr fptr) { @@ -2975,6 +2973,7 @@ static void getchar_common(typval_T *argvars, typval_T *rettv) bool error = false; no_mapping++; + allow_keys++; for (;;) { // Position the cursor. Needed after a message that ends in a space, // or if event processing caused a redraw. @@ -3012,6 +3011,7 @@ static void getchar_common(typval_T *argvars, typval_T *rettv) break; } no_mapping--; + allow_keys--; set_vim_var_nr(VV_MOUSE_WIN, 0); set_vim_var_nr(VV_MOUSE_WINID, 0); @@ -3855,8 +3855,7 @@ static void f_getwininfo(typval_T *argvars, typval_T *rettv, FunPtr fptr) /// Dummy timer callback. Used by f_wait(). static void dummy_timer_due_cb(TimeWatcher *tw, void *data) -{ -} +{} /// Dummy timer close callback. Used by f_wait(). static void dummy_timer_close_cb(TimeWatcher *tw, void *data) @@ -5648,6 +5647,8 @@ static void f_localtime(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) { char_u *keys_buf = NULL; + char_u *alt_keys_buf = NULL; + bool did_simplify = false; char_u *rhs; LuaRef rhs_lua; int mode; @@ -5655,6 +5656,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) int get_dict = FALSE; mapblock_T *mp; int buffer_local; + int flags = REPTERM_FROM_PART | REPTERM_DO_LT; // Return empty string for failure. rettv->v_type = VAR_STRING; @@ -5684,10 +5686,16 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) mode = get_map_mode((char_u **)&which, 0); - keys = replace_termcodes(keys, STRLEN(keys), &keys_buf, true, true, true, - CPO_TO_CPO_FLAGS); - rhs = check_map(keys, mode, exact, false, abbr, &mp, &buffer_local, &rhs_lua); - xfree(keys_buf); + char_u *keys_simplified + = replace_termcodes(keys, STRLEN(keys), &keys_buf, flags, &did_simplify, CPO_TO_CPO_FLAGS); + rhs = check_map(keys_simplified, mode, exact, false, abbr, &mp, &buffer_local, &rhs_lua); + if (did_simplify) { + // When the lhs is being simplified the not-simplified keys are + // preferred for printing, like in do_map(). + (void)replace_termcodes(keys, STRLEN(keys), &alt_keys_buf, flags | REPTERM_NO_SIMPLIFY, NULL, + CPO_TO_CPO_FLAGS); + rhs = check_map(alt_keys_buf, mode, exact, false, abbr, &mp, &buffer_local, &rhs_lua); + } if (!get_dict) { // Return a string. @@ -5710,6 +5718,9 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) mapblock_fill_dict(rettv->vval.v_dict, mp, buffer_local, true); } } + + xfree(keys_buf); + xfree(alt_keys_buf); } /// luaeval() function implementation diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 11ca93cff9..8b47468aad 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1761,14 +1761,14 @@ char_u *trans_function_name(char_u **pp, bool skip, int flags, funcdict_T *fdp, } else if (lv.ll_tv->v_type == VAR_PARTIAL && lv.ll_tv->vval.v_partial != NULL) { if (is_luafunc(lv.ll_tv->vval.v_partial) && *end == '.') { - len = check_luafunc_name((const char *)end+1, true); + len = check_luafunc_name((const char *)end + 1, true); if (len == 0) { semsg(e_invexpr2, "v:lua"); goto theend; } name = xmallocz((size_t)len); - memcpy(name, end+1, (size_t)len); - *pp = (char_u *)end+1+len; + memcpy(name, end + 1, (size_t)len); + *pp = (char_u *)end + 1 + len; } else { name = vim_strsave(partial_name(lv.ll_tv->vval.v_partial)); *pp = (char_u *)end; @@ -2269,11 +2269,10 @@ void ex_function(exarg_T *eap) } } else { // skip ':' and blanks - for (p = theline; ascii_iswhite(*p) || *p == ':'; p++) { - } + for (p = theline; ascii_iswhite(*p) || *p == ':'; p++) {} // Check for "endfunction". - if (checkforcmd(&p, "endfunction", 4) && nesting-- == 0) { + if (checkforcmd((char **)&p, "endfunction", 4) && nesting-- == 0) { if (*p == '!') { p++; } @@ -2312,7 +2311,7 @@ void ex_function(exarg_T *eap) } // Check for defining a function inside this function. - if (checkforcmd(&p, "function", 2)) { + if (checkforcmd((char **)&p, "function", 2)) { if (*p == '!') { p = skipwhite(p + 1); } @@ -2325,7 +2324,7 @@ void ex_function(exarg_T *eap) } // Check for ":append", ":change", ":insert". - p = skip_range(p, NULL); + p = (char_u *)skip_range((char *)p, NULL); if ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p')) || (p[0] == 'c' && (!ASCII_ISALPHA(p[1]) diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c index c20716496f..060b432b18 100644 --- a/src/nvim/event/socket.c +++ b/src/nvim/event/socket.c @@ -106,7 +106,7 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb) : (STRUCT_CAST(struct sockaddr_in6, &sas))->sin6_port); // v:servername uses the string from watcher->addr size_t len = strlen(watcher->addr); - snprintf(watcher->addr+len, sizeof(watcher->addr)-len, ":%" PRIu16, + snprintf(watcher->addr + len, sizeof(watcher->addr) - len, ":%" PRIu16, ntohs(port)); break; } @@ -225,7 +225,7 @@ bool socket_connect(Loop *loop, Stream *stream, bool is_tcp, const char *address .ai_socktype = SOCK_STREAM, .ai_flags = AI_NUMERICSERV }; int retval = uv_getaddrinfo(&loop->uv, &addr_req, NULL, - addr, host_end+1, &hints); + addr, host_end + 1, &hints); if (retval != 0) { *error = _("failed to lookup host or port"); goto cleanup; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 7564b9326b..5cd3e7f968 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -117,7 +117,7 @@ static int preview_bufnr = 0; /// ":ascii" and "ga" implementation void do_ascii(const exarg_T *const eap) { - char_u *dig; + char *dig; int cc[MAX_MCO]; int c = utfc_ptr2char(get_cursor_pos_ptr(), cc); if (c == NUL) { @@ -137,8 +137,8 @@ void do_ascii(const exarg_T *const eap) : c); char buf1[20]; if (vim_isprintc_strict(c) && (c < ' ' || c > '~')) { - char_u buf3[7]; - transchar_nonprint(curbuf, buf3, c); + char buf3[7]; + transchar_nonprint(curbuf, (char_u *)buf3, c); vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3); } else { buf1[0] = NUL; @@ -146,7 +146,7 @@ void do_ascii(const exarg_T *const eap) char buf2[20]; buf2[0] = NUL; - dig = get_digraph_for_char(cval); + dig = (char *)get_digraph_for_char(cval); if (dig != NULL) { iobuff_len += ( vim_snprintf((char *)IObuff + iobuff_len, @@ -196,7 +196,7 @@ void do_ascii(const exarg_T *const eap) } iobuff_len += utf_char2bytes(c, IObuff + iobuff_len); - dig = get_digraph_for_char(c); + dig = (char *)get_digraph_for_char(c); if (dig != NULL) { iobuff_len += ( vim_snprintf((char *)IObuff + iobuff_len, @@ -326,32 +326,31 @@ void ex_align(exarg_T *eap) /// @return the length of the current line, excluding trailing white space. static int linelen(int *has_tab) { - char_u *line; - char_u *first; - char_u *last; + char *line; + char *first; + char *last; int save; int len; // Get the line. If it's empty bail out early (could be the empty string // for an unloaded buffer). - line = get_cursor_line_ptr(); + line = (char *)get_cursor_line_ptr(); if (*line == NUL) { return 0; } // find the first non-blank character - first = skipwhite(line); + first = (char *)skipwhite((char_u *)line); // find the character after the last non-blank character for (last = first + STRLEN(first); - last > first && ascii_iswhite(last[-1]); last--) { - } - save = *last; + last > first && ascii_iswhite(last[-1]); last--) {} + save = (char_u)(*last); *last = NUL; // Get line length. - len = linetabsize(line); + len = linetabsize((char_u *)line); // Check for embedded TAB. if (has_tab != NULL) { - *has_tab = vim_strchr(first, TAB) != NULL; + *has_tab = vim_strchr((char_u *)first, TAB) != NULL; } *last = save; @@ -360,8 +359,8 @@ static int linelen(int *has_tab) // Buffer for two lines used during sorting. They are allocated to // contain the longest line being sorted. -static char_u *sortbuf1; -static char_u *sortbuf2; +static char *sortbuf1; +static char *sortbuf2; static int sort_lc; ///< sort using locale static int sort_ic; ///< ignore case @@ -458,10 +457,10 @@ void ex_sort(exarg_T *eap) long maxlen = 0; size_t count = (size_t)(eap->line2 - eap->line1 + 1); size_t i; - char_u *p; - char_u *s; - char_u *s2; - char_u c; // temporary character storage + char *p; + char *s; + char *s2; + char c; // temporary character storage bool unique = false; long deleted; colnr_T start_col; @@ -485,8 +484,9 @@ void ex_sort(exarg_T *eap) size_t format_found = 0; bool change_occurred = false; // Buffer contents changed. - for (p = eap->arg; *p != NUL; ++p) { + for (p = (char *)eap->arg; *p != NUL; p++) { if (ascii_iswhite(*p)) { + // Skip } else if (*p == 'i') { sort_ic = true; } else if (*p == 'l') { @@ -513,11 +513,11 @@ void ex_sort(exarg_T *eap) } else if (*p == '"') { // comment start break; - } else if (check_nextcmd(p) != NULL) { - eap->nextcmd = check_nextcmd(p); + } else if (check_nextcmd((char_u *)p) != NULL) { + eap->nextcmd = check_nextcmd((char_u *)p); break; } else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) { - s = skip_regexp(p + 1, *p, true, NULL); + s = (char *)skip_regexp((char_u *)p + 1, *p, true, NULL); if (*s != *p) { emsg(_(e_invalpat)); goto sortend; @@ -531,7 +531,7 @@ void ex_sort(exarg_T *eap) } regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC); } else { - regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC); + regmatch.regprog = vim_regcomp((char_u *)p + 1, RE_MAGIC); } if (regmatch.regprog == NULL) { goto sortend; @@ -560,8 +560,8 @@ void ex_sort(exarg_T *eap) // numbers sorting it's the number to sort on. This means the pattern // matching and number conversion only has to be done once per line. // Also get the longest line length for allocating "sortbuf". - for (lnum = eap->line1; lnum <= eap->line2; ++lnum) { - s = ml_get(lnum); + for (lnum = eap->line1; lnum <= eap->line2; lnum++) { + s = (char *)ml_get(lnum); len = (int)STRLEN(s); if (maxlen < len) { maxlen = len; @@ -569,12 +569,12 @@ void ex_sort(exarg_T *eap) start_col = 0; end_col = len; - if (regmatch.regprog != NULL && vim_regexec(®match, s, 0)) { + if (regmatch.regprog != NULL && vim_regexec(®match, (char_u *)s, 0)) { if (sort_rx) { - start_col = (colnr_T)(regmatch.startp[0] - s); - end_col = (colnr_T)(regmatch.endp[0] - s); + start_col = (colnr_T)(regmatch.startp[0] - (char_u *)s); + end_col = (colnr_T)(regmatch.endp[0] - (char_u *)s); } else { - start_col = (colnr_T)(regmatch.endp[0] - s); + start_col = (colnr_T)(regmatch.endp[0] - (char_u *)s); } } else if (regmatch.regprog != NULL) { end_col = 0; @@ -590,11 +590,11 @@ void ex_sort(exarg_T *eap) p = s + start_col; if (sort_nr) { if (sort_what & STR2NR_HEX) { - s = skiptohex(p); + s = (char *)skiptohex((char_u *)p); } else if (sort_what & STR2NR_BIN) { - s = (char_u *)skiptobin((char *)p); + s = (char *)skiptobin(p); } else { - s = skiptodigit(p); + s = (char *)skiptodigit((char_u *)p); } if (s > p && s[-1] == '-') { s--; // include preceding negative sign @@ -605,20 +605,20 @@ void ex_sort(exarg_T *eap) nrs[lnum - eap->line1].st_u.num.value = 0; } else { nrs[lnum - eap->line1].st_u.num.is_number = true; - vim_str2nr(s, NULL, NULL, sort_what, + vim_str2nr((char_u *)s, NULL, NULL, sort_what, &nrs[lnum - eap->line1].st_u.num.value, NULL, 0, false); } } else { - s = skipwhite(p); + s = (char *)skipwhite((char_u *)p); if (*s == '+') { - s = skipwhite(s + 1); + s = (char *)skipwhite((char_u *)s + 1); } if (*s == NUL) { // empty line should sort before any number nrs[lnum - eap->line1].st_u.value_flt = -DBL_MAX; } else { - nrs[lnum - eap->line1].st_u.value_flt = strtod((char *)s, NULL); + nrs[lnum - eap->line1].st_u.value_flt = strtod(s, NULL); } } *s2 = c; @@ -662,14 +662,14 @@ void ex_sort(exarg_T *eap) change_occurred = true; } - s = ml_get(get_lnum); + s = (char *)ml_get(get_lnum); size_t bytelen = STRLEN(s) + 1; // include EOL in bytelen old_count += bytelen; if (!unique || i == 0 || string_compare(s, sortbuf1) != 0) { // Copy the line into a buffer, it may become invalid in // ml_append(). And it's needed for "unique". STRCPY(sortbuf1, s); - if (ml_append(lnum++, sortbuf1, (colnr_T)0, false) == FAIL) { + if (ml_append(lnum++, (char_u *)sortbuf1, (colnr_T)0, false) == FAIL) { break; } new_count += bytelen; @@ -700,7 +700,7 @@ void ex_sort(exarg_T *eap) } if (change_occurred || deleted != 0) { - extmark_splice(curbuf, eap->line1-1, 0, + extmark_splice(curbuf, eap->line1 - 1, 0, count, 0, old_count, lnum - eap->line2, 0, new_count, kExtmarkUndo); @@ -733,11 +733,11 @@ void ex_retab(exarg_T *eap) long start_col = 0; // For start of white-space string long start_vcol = 0; // For start of white-space string long old_len; - char_u *ptr; - char_u *new_line = (char_u *)1; // init to non-NULL + char *ptr; + char *new_line = (char *)1; // init to non-NULL bool did_undo; // called u_save for current line long *new_vts_array = NULL; - char_u *new_ts_str; // string value of tab argument + char *new_ts_str; // string value of tab argument int save_list; linenr_T first_line = 0; // first changed line @@ -746,7 +746,7 @@ void ex_retab(exarg_T *eap) save_list = curwin->w_p_list; curwin->w_p_list = 0; // don't want list mode here - new_ts_str = eap->arg; + new_ts_str = (char *)eap->arg; if (!tabstop_set(eap->arg, &new_vts_array)) { return; } @@ -761,10 +761,10 @@ void ex_retab(exarg_T *eap) new_vts_array = curbuf->b_p_vts_array; new_ts_str = NULL; } else { - new_ts_str = vim_strnsave(new_ts_str, eap->arg - new_ts_str); + new_ts_str = xstrnsave(new_ts_str, eap->arg - (char_u *)new_ts_str); } for (lnum = eap->line1; !got_int && lnum <= eap->line2; lnum++) { - ptr = ml_get(lnum); + ptr = (char *)ml_get(lnum); col = 0; vcol = 0; did_undo = false; @@ -825,9 +825,9 @@ void ex_retab(exarg_T *eap) for (col = 0; col < len; col++) { ptr[col] = (col < num_tabs) ? '\t' : ' '; } - if (ml_replace(lnum, new_line, false) == OK) { + if (ml_replace(lnum, (char_u *)new_line, false) == OK) { // "new_line" may have been copied - new_line = curbuf->b_ml.ml_line_ptr; + new_line = (char *)curbuf->b_ml.ml_line_ptr; extmark_splice_cols(curbuf, lnum - 1, 0, (colnr_T)old_len, (colnr_T)new_len - 1, kExtmarkUndo); } @@ -845,12 +845,12 @@ void ex_retab(exarg_T *eap) if (ptr[col] == NUL) { break; } - vcol += win_chartabsize(curwin, ptr + col, (colnr_T)vcol); + vcol += win_chartabsize(curwin, (char_u *)ptr + col, (colnr_T)vcol); if (vcol >= MAXCOL) { emsg(_(e_resulting_text_too_long)); break; } - col += utfc_ptr2len(ptr + col); + col += utfc_ptr2len((char_u *)ptr + col); } if (new_line == NULL) { // out of memory break; @@ -885,7 +885,7 @@ void ex_retab(exarg_T *eap) long *old_vts_ary = curbuf->b_p_vts_array; if (tabstop_count(old_vts_ary) > 0 || tabstop_count(new_vts_array) > 1) { - set_string_option_direct("vts", -1, new_ts_str, + set_string_option_direct("vts", -1, (char_u *)new_ts_str, OPT_FREE | OPT_LOCAL, 0); curbuf->b_p_vts_array = new_vts_array; xfree(old_vts_ary); @@ -907,7 +907,7 @@ void ex_retab(exarg_T *eap) /// @return FAIL for failure, OK otherwise int do_move(linenr_T line1, linenr_T line2, linenr_T dest) { - char_u *str; + char *str; linenr_T l; linenr_T extra; // Num lines added before line1 linenr_T num_lines; // Num lines moved @@ -932,9 +932,9 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) } bcount_t start_byte = ml_find_line_or_offset(curbuf, line1, NULL, true); - bcount_t end_byte = ml_find_line_or_offset(curbuf, line2+1, NULL, true); - bcount_t extent_byte = end_byte-start_byte; - bcount_t dest_byte = ml_find_line_or_offset(curbuf, dest+1, NULL, true); + bcount_t end_byte = ml_find_line_or_offset(curbuf, line2 + 1, NULL, true); + bcount_t extent_byte = end_byte - start_byte; + bcount_t dest_byte = ml_find_line_or_offset(curbuf, dest + 1, NULL, true); num_lines = line2 - line1 + 1; @@ -946,8 +946,8 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) return FAIL; } for (extra = 0, l = line1; l <= line2; l++) { - str = vim_strsave(ml_get(l + extra)); - ml_append(dest + l - line1, str, (colnr_T)0, false); + str = (char *)vim_strsave(ml_get(l + extra)); + ml_append(dest + l - line1, (char_u *)str, (colnr_T)0, false); xfree(str); if (dest < line1) { extra++; @@ -1024,9 +1024,9 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) smsg(NGETTEXT("1 line moved", "%" PRId64 " lines moved", num_lines), (int64_t)num_lines); } - extmark_move_region(curbuf, line1-1, 0, start_byte, - line2-line1+1, 0, extent_byte, - dest+line_off, 0, dest_byte+byte_off, + extmark_move_region(curbuf, line1 - 1, 0, start_byte, + line2 - line1 + 1, 0, extent_byte, + dest + line_off, 0, dest_byte + byte_off, kExtmarkUndo); /* @@ -1059,7 +1059,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) { linenr_T count; - char_u *p; + char *p; count = line2 - line1 + 1; if (!cmdmod.lockmarks) { @@ -1087,8 +1087,8 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) while (line1 <= line2) { // need to use vim_strsave() because the line will be unlocked within // ml_append() - p = vim_strsave(ml_get(line1)); - ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, false); + p = (char *)vim_strsave(ml_get(line1)); + ml_append(curwin->w_cursor.lnum, (char_u *)p, (colnr_T)0, false); xfree(p); // situation 2: skip already copied lines @@ -1113,7 +1113,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) msgmore((long)count); } -static char_u *prevcmd = NULL; // the previous command +static char *prevcmd = NULL; // the previous command #if defined(EXITFREE) void free_prev_shellcmd(void) @@ -1129,14 +1129,14 @@ void free_prev_shellcmd(void) void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out) FUNC_ATTR_NONNULL_ALL { - char_u *arg = eap->arg; // command + char *arg = (char *)eap->arg; // command linenr_T line1 = eap->line1; // start of range linenr_T line2 = eap->line2; // end of range - char_u *newcmd = NULL; // the new command + char *newcmd = NULL; // the new command bool free_newcmd = false; // need to free() newcmd - char_u *t; - char_u *p; - char_u *trailarg; + char *t; + char *p; + char *trailarg; int len; int scroll_save = msg_scroll; @@ -1213,9 +1213,9 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out // If % or # appears in the command, it must have been escaped. // Reescape them, so that redoing them does not substitute them by the // buffername. - char_u *cmd = vim_strsave_escaped(prevcmd, (char_u *)"%#"); + char *cmd = (char *)vim_strsave_escaped((char_u *)prevcmd, (char_u *)"%#"); - AppendToRedobuffLit(cmd, -1); + AppendToRedobuffLit((char_u *)cmd, -1); xfree(cmd); AppendToRedobuff("\n"); bangredo = false; @@ -1235,7 +1235,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out msg_start(); msg_putchar(':'); msg_putchar('!'); - msg_outtrans(newcmd); + msg_outtrans((char_u *)newcmd); msg_clr_eos(); ui_cursor_goto(msg_row, msg_col); @@ -1266,15 +1266,15 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out /// We use output redirection if do_out is true. /// /// @param eap for forced 'ff' and 'fenc' -static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, bool do_in, +static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char *cmd, bool do_in, bool do_out) { - char_u *itmp = NULL; - char_u *otmp = NULL; + char *itmp = NULL; + char *otmp = NULL; linenr_T linecount; linenr_T read_linecount; pos_T cursor_save; - char_u *cmd_buf; + char *cmd_buf; buf_T *old_curbuf = curbuf; int shell_flags = 0; const pos_T orig_start = curbuf->b_op_start; @@ -1330,8 +1330,8 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, curbuf->b_op_start.lnum = line1; curbuf->b_op_end.lnum = line2; curwin->w_cursor.lnum = line2; - } else if ((do_in && (itmp = vim_tempname()) == NULL) - || (do_out && (otmp = vim_tempname()) == NULL)) { + } else if ((do_in && (itmp = (char *)vim_tempname()) == NULL) + || (do_out && (otmp = (char *)vim_tempname()) == NULL)) { emsg(_(e_notmp)); goto filterend; } @@ -1340,8 +1340,8 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, * The writing and reading of temp files will not be shown. * Vi also doesn't do this and the messages are not very informative. */ - ++no_wait_return; // don't call wait_return() while busy - if (itmp != NULL && buf_write(curbuf, itmp, NULL, line1, line2, eap, + no_wait_return++; // don't call wait_return() while busy + if (itmp != NULL && buf_write(curbuf, (char_u *)itmp, NULL, line1, line2, eap, false, false, false, true) == FAIL) { msg_putchar('\n'); // Keep message from buf_write(). no_wait_return--; @@ -1372,7 +1372,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, read_linecount = curbuf->b_ml.ml_line_count; // Pass on the kShellOptDoOut flag when the output is being redirected. - call_shell(cmd_buf, kShellOptFilter | shell_flags, NULL); + call_shell((char_u *)cmd_buf, kShellOptFilter | shell_flags, NULL); xfree(cmd_buf); did_check_timestamps = FALSE; @@ -1386,7 +1386,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, if (do_out) { if (otmp != NULL) { - if (readfile(otmp, NULL, line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, + if (readfile((char_u *)otmp, NULL, line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, READ_FILTER, false) != OK) { if (!aborting()) { msg_putchar('\n'); @@ -1479,10 +1479,10 @@ filterend: } if (itmp != NULL) { - os_remove((char *)itmp); + os_remove(itmp); } if (otmp != NULL) { - os_remove((char *)otmp); + os_remove(otmp); } xfree(itmp); xfree(otmp); @@ -1492,7 +1492,7 @@ filterend: /// When "cmd" is NULL start an interactive shell. /// /// @param flags may be SHELL_DOOUT when output is redirected -void do_shell(char_u *cmd, int flags) +void do_shell(char *cmd, int flags) { // Disallow shell commands from .exrc and .vimrc in current directory for // security reasons. @@ -1524,7 +1524,7 @@ void do_shell(char_u *cmd, int flags) // This ui_cursor_goto is required for when the '\n' resulted in a "delete line // 1" command to the terminal. ui_cursor_goto(msg_row, msg_col); - (void)call_shell(cmd, flags, NULL); + (void)call_shell((char_u *)cmd, flags, NULL); msg_didout = true; did_check_timestamps = false; need_check_timestamps = true; @@ -1563,7 +1563,7 @@ static char *find_pipe(const char *cmd) /// @param itmp NULL or the input file. /// @param otmp NULL or the output file. /// @returns an allocated string with the shell command. -char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp) +char *make_filter_cmd(char *cmd, char *itmp, char *otmp) { bool is_fish_shell = #if defined(UNIX) @@ -1591,9 +1591,9 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp) if (itmp != NULL || otmp != NULL) { char *fmt = is_fish_shell ? "begin; %s; end" : "(%s)"; - vim_snprintf(buf, len, fmt, (char *)cmd); + vim_snprintf(buf, len, fmt, cmd); } else { - xstrlcpy(buf, (char *)cmd, len); + xstrlcpy(buf, cmd, len); } if (itmp != NULL) { @@ -1626,9 +1626,9 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp) } #endif if (otmp != NULL) { - append_redir(buf, len, (char *)p_srr, (char *)otmp); + append_redir(buf, len, (char *)p_srr, otmp); } - return (char_u *)buf; + return buf; } /// Append output redirection for the given file to the end of the buffer @@ -1695,9 +1695,9 @@ void print_line(linenr_T lnum, int use_number, int list) info_message = false; } -int rename_buffer(char_u *new_fname) +int rename_buffer(char *new_fname) { - char_u *fname, *sfname, *xfname; + char *fname, *sfname, *xfname; buf_T *buf; buf = curbuf; @@ -1716,19 +1716,19 @@ int rename_buffer(char_u *new_fname) * But don't set the alternate file name if the buffer didn't have a * name. */ - fname = curbuf->b_ffname; - sfname = curbuf->b_sfname; - xfname = curbuf->b_fname; + fname = (char *)curbuf->b_ffname; + sfname = (char *)curbuf->b_sfname; + xfname = (char *)curbuf->b_fname; curbuf->b_ffname = NULL; curbuf->b_sfname = NULL; - if (setfname(curbuf, new_fname, NULL, true) == FAIL) { - curbuf->b_ffname = fname; - curbuf->b_sfname = sfname; + if (setfname(curbuf, (char_u *)new_fname, NULL, true) == FAIL) { + curbuf->b_ffname = (char_u *)fname; + curbuf->b_sfname = (char_u *)sfname; return FAIL; } curbuf->b_flags |= BF_NOTEDITED; if (xfname != NULL && *xfname != NUL) { - buf = buflist_new(fname, xfname, curwin->w_cursor.lnum, 0); + buf = buflist_new((char_u *)fname, (char_u *)xfname, curwin->w_cursor.lnum, 0); if (buf != NULL && !cmdmod.keepalt) { curwin->w_alt_fnum = buf->b_fnum; } @@ -1755,7 +1755,7 @@ void ex_file(exarg_T *eap) } if (*eap->arg != NUL || eap->addr_count == 1) { - if (rename_buffer(eap->arg) == FAIL) { + if (rename_buffer((char *)eap->arg) == FAIL) { return; } redraw_tabline = true; @@ -1800,10 +1800,10 @@ void ex_write(exarg_T *eap) int do_write(exarg_T *eap) { int other; - char_u *fname = NULL; // init to shut up gcc - char_u *ffname; + char *fname = NULL; // init to shut up gcc + char *ffname; int retval = FAIL; - char_u *free_fname = NULL; + char *free_fname = NULL; buf_T *alt_buf = NULL; int name_was_missing; @@ -1811,7 +1811,7 @@ int do_write(exarg_T *eap) return FAIL; } - ffname = eap->arg; + ffname = (char *)eap->arg; if (*ffname == NUL) { if (eap->cmdidx == CMD_saveas) { emsg(_(e_argreq)); @@ -1820,15 +1820,13 @@ int do_write(exarg_T *eap) other = FALSE; } else { fname = ffname; - free_fname = (char_u *)fix_fname((char *)ffname); - /* - * When out-of-memory, keep unexpanded file name, because we MUST be - * able to write the file in this situation. - */ + free_fname = fix_fname(ffname); + // When out-of-memory, keep unexpanded file name, because we MUST be + // able to write the file in this situation. if (free_fname != NULL) { ffname = free_fname; } - other = otherfile(ffname); + other = otherfile((char_u *)ffname); } /* @@ -1837,9 +1835,9 @@ int do_write(exarg_T *eap) if (other) { if (vim_strchr(p_cpo, CPO_ALTWRITE) != NULL || eap->cmdidx == CMD_saveas) { - alt_buf = setaltfname(ffname, fname, (linenr_T)1); + alt_buf = setaltfname((char_u *)ffname, (char_u *)fname, (linenr_T)1); } else { - alt_buf = buflist_findname(ffname); + alt_buf = buflist_findname((char_u *)ffname); } if (alt_buf != NULL && alt_buf->b_ml.ml_mfp != NULL) { // Overwriting a file that is loaded in another buffer is not a @@ -1859,11 +1857,9 @@ int do_write(exarg_T *eap) } if (!other) { - ffname = curbuf->b_ffname; - fname = curbuf->b_fname; - /* - * Not writing the whole file is only allowed with '!'. - */ + ffname = (char *)curbuf->b_ffname; + fname = (char *)curbuf->b_fname; + // Not writing the whole file is only allowed with '!'. if ((eap->line1 != 1 || eap->line2 != curbuf->b_ml.ml_line_count) && !eap->forceit @@ -1898,15 +1894,15 @@ int do_write(exarg_T *eap) // under the new name. Must be done before buf_write(), because // if there is no file name and 'cpo' contains 'F', it will set // the file name. - fname = alt_buf->b_fname; + fname = (char *)alt_buf->b_fname; alt_buf->b_fname = curbuf->b_fname; - curbuf->b_fname = fname; - fname = alt_buf->b_ffname; + curbuf->b_fname = (char_u *)fname; + fname = (char *)alt_buf->b_ffname; alt_buf->b_ffname = curbuf->b_ffname; - curbuf->b_ffname = fname; - fname = alt_buf->b_sfname; + curbuf->b_ffname = (char_u *)fname; + fname = (char *)alt_buf->b_sfname; alt_buf->b_sfname = curbuf->b_sfname; - curbuf->b_sfname = fname; + curbuf->b_sfname = (char_u *)fname; buf_name_changed(curbuf); apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, false, curbuf); apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, false, alt_buf); @@ -1930,12 +1926,12 @@ int do_write(exarg_T *eap) // Autocommands may have changed buffer names, esp. when // 'autochdir' is set. - fname = curbuf->b_sfname; + fname = (char *)curbuf->b_sfname; } name_was_missing = curbuf->b_ffname == NULL; - retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, - eap, eap->append, eap->forceit, TRUE, FALSE); + retval = buf_write(curbuf, (char_u *)ffname, (char_u *)fname, eap->line1, eap->line2, + eap, eap->append, eap->forceit, true, false); // After ":saveas fname" reset 'readonly'. if (eap->cmdidx == CMD_saveas) { @@ -1966,7 +1962,7 @@ theend: /// @param other writing under other name /// /// @return OK if it's OK, FAIL if it is not. -int check_overwrite(exarg_T *eap, buf_T *buf, char_u *fname, char_u *ffname, int other) +int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int other) { /* * write to other file or b_flags set or not writing the whole file: @@ -1979,20 +1975,20 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char_u *fname, char_u *ffname, int || (buf->b_flags & BF_READERR)) && !p_wa && !bt_nofile(buf) - && os_path_exists(ffname)) { + && os_path_exists((char_u *)ffname)) { if (!eap->forceit && !eap->append) { #ifdef UNIX // It is possible to open a directory on Unix. - if (os_isdir(ffname)) { + if (os_isdir((char_u *)ffname)) { semsg(_(e_isadir2), ffname); return FAIL; } #endif if (p_confirm || cmdmod.confirm) { - char_u buff[DIALOG_MSG_SIZE]; + char buff[DIALOG_MSG_SIZE]; - dialog_msg(buff, _("Overwrite existing file \"%s\"?"), fname); - if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) != VIM_YES) { + dialog_msg((char *)buff, _("Overwrite existing file \"%s\"?"), fname); + if (vim_dialog_yesno(VIM_QUESTION, NULL, (char_u *)buff, 2) != VIM_YES) { return FAIL; } eap->forceit = TRUE; @@ -2004,9 +2000,9 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char_u *fname, char_u *ffname, int // For ":w! filename" check that no swap file exists for "filename". if (other && !emsg_silent) { - char_u *dir; - char_u *p; - char_u *swapname; + char *dir; + char *p; + char *swapname; // We only try the first entry in 'directory', without checking if // it's writable. If the "." directory is not writable the write @@ -2018,19 +2014,19 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char_u *fname, char_u *ffname, int STRCPY(dir, "."); } else { dir = xmalloc(MAXPATHL); - p = p_dir; - copy_option_part(&p, dir, MAXPATHL, ","); + p = (char *)p_dir; + copy_option_part((char_u **)&p, (char_u *)dir, MAXPATHL, ","); } - swapname = makeswapname(fname, ffname, curbuf, dir); + swapname = (char *)makeswapname((char_u *)fname, (char_u *)ffname, curbuf, (char_u *)dir); xfree(dir); - if (os_path_exists(swapname)) { + if (os_path_exists((char_u *)swapname)) { if (p_confirm || cmdmod.confirm) { - char_u buff[DIALOG_MSG_SIZE]; + char buff[DIALOG_MSG_SIZE]; - dialog_msg(buff, + dialog_msg((char *)buff, _("Swap file \"%s\" exists, overwrite anyway?"), swapname); - if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) + if (vim_dialog_yesno(VIM_QUESTION, NULL, (char_u *)buff, 2) != VIM_YES) { xfree(swapname); return FAIL; @@ -2100,9 +2096,9 @@ void do_wqall(exarg_T *eap) semsg(_("E141: No file name for buffer %" PRId64), (int64_t)buf->b_fnum); error++; } else if (check_readonly(&eap->forceit, buf) - || check_overwrite(eap, buf, buf->b_fname, buf->b_ffname, - FALSE) == FAIL) { - ++error; + || check_overwrite(eap, buf, (char *)buf->b_fname, (char *)buf->b_ffname, + false) == FAIL) { + error++; } else { bufref_T bufref; set_bufref(&bufref, buf); @@ -2147,20 +2143,20 @@ static int check_readonly(int *forceit, buf_T *buf) || (os_path_exists(buf->b_ffname) && !os_file_is_writable((char *)buf->b_ffname)))) { if ((p_confirm || cmdmod.confirm) && buf->b_fname != NULL) { - char_u buff[DIALOG_MSG_SIZE]; + char buff[DIALOG_MSG_SIZE]; if (buf->b_p_ro) { - dialog_msg(buff, + dialog_msg((char *)buff, _("'readonly' option is set for \"%s\".\nDo you wish to write anyway?"), - buf->b_fname); + (char *)buf->b_fname); } else { - dialog_msg(buff, - _( - "File permissions of \"%s\" are read-only.\nIt may still be possible to write it.\nDo you wish to try?"), - buf->b_fname); + dialog_msg((char *)buff, + _("File permissions of \"%s\" are read-only.\nIt may still be possible to " + "write it.\nDo you wish to try?"), + (char *)buf->b_fname); } - if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES) { + if (vim_dialog_yesno(VIM_QUESTION, NULL, (char_u *)buff, 2) == VIM_YES) { // Set forceit, to force the writing of a readonly file *forceit = TRUE; return FALSE; @@ -2189,13 +2185,13 @@ static int check_readonly(int *forceit, buf_T *buf) /// GETFILE_NOT_WRITTEN for "not written" error, /// GETFILE_SAME_FILE for success /// GETFILE_OPEN_OTHER for successfully opening another file. -int getfile(int fnum, char_u *ffname_arg, char_u *sfname_arg, int setpm, linenr_T lnum, int forceit) +int getfile(int fnum, char *ffname_arg, char *sfname_arg, int setpm, linenr_T lnum, int forceit) { - char_u *ffname = ffname_arg; - char_u *sfname = sfname_arg; + char *ffname = ffname_arg; + char *sfname = sfname_arg; int other; int retval; - char_u *free_me = NULL; + char *free_me = NULL; if (text_locked()) { return GETFILE_ERROR; @@ -2206,8 +2202,8 @@ int getfile(int fnum, char_u *ffname_arg, char_u *sfname_arg, int setpm, linenr_ if (fnum == 0) { // make ffname full path, set sfname - fname_expand(curbuf, &ffname, &sfname); - other = otherfile(ffname); + fname_expand(curbuf, (char_u **)&ffname, (char_u **)&sfname); + other = otherfile((char_u *)ffname); free_me = ffname; // has been allocated, free() later } else { other = (fnum != curbuf->b_fnum); @@ -2284,19 +2280,19 @@ theend: /// info of the previous buffer for "oldwin" is stored. /// /// @return FAIL for failure, OK otherwise -int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T newlnum, int flags, +int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum, int flags, win_T *oldwin) { bool other_file; // true if editing another file int oldbuf; // TRUE if using existing buffer bool auto_buf = false; // true if autocommands brought us // into the buffer unexpectedly - char_u *new_name = NULL; + char *new_name = NULL; bool did_set_swapcommand = false; buf_T *buf; bufref_T bufref; bufref_T old_curbuf; - char_u *free_fname = NULL; + char *free_fname = NULL; int retval = FAIL; long n; pos_T orig_pos; @@ -2304,14 +2300,14 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new int newcol = -1; int solcol = -1; pos_T *pos; - char_u *command = NULL; + char *command = NULL; bool did_get_winopts = false; int readfile_flags = 0; bool did_inc_redrawing_disabled = false; long *so_ptr = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so; if (eap != NULL) { - command = eap->do_ecmd_cmd; + command = (char *)eap->do_ecmd_cmd; } set_bufref(&old_curbuf, curbuf); @@ -2328,7 +2324,7 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new } #ifdef USE_FNAME_CASE if (sfname != NULL) { - path_fix_case(sfname); // set correct case for sfname + path_fix_case((char_u *)sfname); // set correct case for sfname } #endif @@ -2343,14 +2339,14 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new other_file = false; } else { if (*ffname == NUL) { // re-edit with same file name - ffname = curbuf->b_ffname; - sfname = curbuf->b_fname; + ffname = (char *)curbuf->b_ffname; + sfname = (char *)curbuf->b_fname; } - free_fname = (char_u *)fix_fname((char *)ffname); // may expand to full path name + free_fname = fix_fname(ffname); // may expand to full path name if (free_fname != NULL) { ffname = free_fname; } - other_file = otherfile(ffname); + other_file = otherfile((char_u *)ffname); } } @@ -2373,7 +2369,7 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new | ((flags & ECMD_FORCEIT) ? CCGD_FORCEIT : 0) | (eap == NULL ? 0 : CCGD_EXCMD))) { if (fnum == 0 && other_file && ffname != NULL) { - (void)setaltfname(ffname, sfname, newlnum < 0 ? 0 : newlnum); + (void)setaltfname((char_u *)ffname, (char_u *)sfname, newlnum < 0 ? 0 : newlnum); } goto theend; } @@ -2422,7 +2418,7 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new linenr_T tlnum = 0; if (command != NULL) { - tlnum = atol((char *)command); + tlnum = atol(command); if (tlnum <= 0) { tlnum = 1L; } @@ -2430,13 +2426,13 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new // Add BLN_NOCURWIN to avoid a new wininfo items are associated // with the current window. const buf_T *const newbuf - = buflist_new(ffname, sfname, tlnum, BLN_LISTED | BLN_NOCURWIN); + = buflist_new((char_u *)ffname, (char_u *)sfname, tlnum, BLN_LISTED | BLN_NOCURWIN); if (newbuf != NULL && (flags & ECMD_ALTBUF)) { curwin->w_alt_fnum = newbuf->b_fnum; } goto theend; } - buf = buflist_new(ffname, sfname, 0L, + buf = buflist_new((char_u *)ffname, (char_u *)sfname, 0L, BLN_CURBUF | (flags & ECMD_SET_HELP ? 0 : BLN_LISTED)); // Autocmds may change curwin and curbuf. if (oldwin != NULL) { @@ -2495,7 +2491,7 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new // - If we ended up in the new buffer already, need to skip a few // things, set auto_buf. if (buf->b_fname != NULL) { - new_name = vim_strsave(buf->b_fname); + new_name = (char *)vim_strsave(buf->b_fname); } const bufref_T save_au_new_curbuf = au_new_curbuf; set_bufref(&au_new_curbuf, buf); @@ -2645,7 +2641,7 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new } buf = curbuf; if (buf->b_fname != NULL) { - new_name = vim_strsave(buf->b_fname); + new_name = (char *)vim_strsave(buf->b_fname); } else { new_name = NULL; } @@ -2769,10 +2765,10 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new // keep it. Also when it moves within a line. But not when it moves // to the first non-blank. if (!equalpos(curwin->w_cursor, orig_pos)) { - const char_u *text = get_cursor_line_ptr(); + const char *text = (char *)get_cursor_line_ptr(); if (curwin->w_cursor.lnum != orig_pos.lnum - || curwin->w_cursor.col != (int)(skipwhite(text) - text)) { + || curwin->w_cursor.col != (int)(skipwhite((char_u *)text) - (char_u *)text)) { newlnum = curwin->w_cursor.lnum; newcol = curwin->w_cursor.col; } @@ -2902,10 +2898,10 @@ theend: return retval; } -static void delbuf_msg(char_u *name) +static void delbuf_msg(char *name) { semsg(_("E143: Autocommands unexpectedly deleted new buffer %s"), - name == NULL ? (char_u *)"" : name); + name == NULL ? "" : name); xfree(name); au_new_curbuf.br_buf = NULL; au_new_curbuf.br_buf_free_count = 0; @@ -2916,11 +2912,11 @@ static int append_indent = 0; // autoindent for first line /// ":insert" and ":append", also used by ":change" void ex_append(exarg_T *eap) { - char_u *theline; + char *theline; bool did_undo = false; linenr_T lnum = eap->line2; int indent = 0; - char_u *p; + char *p; int vcol; int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); @@ -2965,22 +2961,22 @@ void ex_append(exarg_T *eap) if (eap->nextcmd == NULL || *eap->nextcmd == NUL) { break; } - p = vim_strchr(eap->nextcmd, NL); + p = (char *)vim_strchr(eap->nextcmd, NL); if (p == NULL) { - p = eap->nextcmd + STRLEN(eap->nextcmd); + p = (char *)eap->nextcmd + STRLEN(eap->nextcmd); } - theline = vim_strnsave(eap->nextcmd, p - eap->nextcmd); + theline = (char *)vim_strnsave(eap->nextcmd, (char_u *)p - eap->nextcmd); if (*p != NUL) { p++; } - eap->nextcmd = p; + eap->nextcmd = (char_u *)p; } else { // Set State to avoid the cursor shape to be set to INSERT mode // when getline() returns. int save_State = State; State = CMDLINE; - theline = eap->getline(eap->cstack->cs_looplevel > 0 ? -1 : - NUL, eap->cookie, indent, true); + theline = (char *)eap->getline(eap->cstack->cs_looplevel > 0 ? -1 : + NUL, eap->cookie, indent, true); State = save_State; } lines_left = Rows - 1; @@ -3012,7 +3008,7 @@ void ex_append(exarg_T *eap) } did_undo = true; - ml_append(lnum, theline, (colnr_T)0, false); + ml_append(lnum, (char_u *)theline, (colnr_T)0, false); if (empty) { // there are no marks below the inserted lines appended_lines(lnum, 1L); @@ -3088,9 +3084,9 @@ void ex_change(exarg_T *eap) void ex_z(exarg_T *eap) { - char_u *x; + char *x; int64_t bigness; - char_u *kind; + char *kind; int minus = 0; linenr_T start, end, curs, i; int j; @@ -3109,7 +3105,7 @@ void ex_z(exarg_T *eap) bigness = 1; } - x = eap->arg; + x = (char *)eap->arg; kind = x; if (*kind == '-' || *kind == '+' || *kind == '=' || *kind == '^' || *kind == '.') { @@ -3124,7 +3120,7 @@ void ex_z(exarg_T *eap) emsg(_("E144: non-numeric argument to :z")); return; } - bigness = atol((char *)x); + bigness = atol(x); // bigness could be < 0 if atol(x) overflows. if (bigness > 2 * curbuf->b_ml.ml_line_count || bigness < 0) { @@ -3139,8 +3135,7 @@ void ex_z(exarg_T *eap) // the number of '-' and '+' multiplies the distance if (*kind == '-' || *kind == '+') { - for (x = kind + 1; *x == *kind; x++) { - } + for (x = kind + 1; *x == *kind; x++) {} } switch (*kind) { @@ -3280,7 +3275,7 @@ void sub_set_replacement(SubReplacementString sub) /// @param[in] save Save pattern to options, history /// /// @returns true if :substitute can be replaced with a join command -static bool sub_joining_lines(exarg_T *eap, char_u *pat, char_u *sub, char_u *cmd, bool save) +static bool sub_joining_lines(exarg_T *eap, char *pat, char *sub, char *cmd, bool save) FUNC_ATTR_NONNULL_ARG(1, 3, 4) { // TODO(vim): find a generic solution to make line-joining operations more @@ -3319,9 +3314,9 @@ static bool sub_joining_lines(exarg_T *eap, char_u *pat, char_u *sub, char_u *cm if (save) { if (!cmdmod.keeppatterns) { - save_re_pat(RE_SUBST, pat, p_magic); + save_re_pat(RE_SUBST, (char_u *)pat, p_magic); } - add_to_history(HIST_SEARCH, pat, true, NUL); + add_to_history(HIST_SEARCH, (char_u *)pat, true, NUL); } return true; @@ -3339,11 +3334,11 @@ static bool sub_joining_lines(exarg_T *eap, char_u *pat, char_u *sub, char_u *cm /// @param[in] needed_len amount of memory needed /// /// @returns pointer to the end of the allocated memory -static char_u *sub_grow_buf(char_u **new_start, int needed_len) +static char *sub_grow_buf(char **new_start, int needed_len) FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_RET { int new_start_len = 0; - char_u *new_end; + char *new_end; if (*new_start == NULL) { // Get some space for a temporary buffer to do the // substitution into (and some extra space to avoid @@ -3375,7 +3370,7 @@ static char_u *sub_grow_buf(char_u **new_start, int needed_len) /// @param[in,out] which_pat pattern type from which to get default search /// /// @returns pointer to the end of the flags, which may be the end of the string -static char_u *sub_parse_flags(char_u *cmd, subflags_T *subflags, int *which_pat) +static char *sub_parse_flags(char *cmd, subflags_T *subflags, int *which_pat) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { // Find trailing options. When '&' is used, keep old options. @@ -3461,18 +3456,18 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle .do_number = false, .do_ic = kSubHonorOptions }; - char_u *pat = NULL, *sub = NULL; // init for GCC + char *pat = NULL, *sub = NULL; // init for GCC int delimiter; bool has_second_delim = false; int sublen; bool got_quit = false; bool got_match = false; int which_pat; - char_u *cmd = eap->arg; + char *cmd = (char *)eap->arg; linenr_T first_line = 0; // first changed line linenr_T last_line= 0; // below last changed line AFTER the change linenr_T old_line_count = curbuf->b_ml.ml_line_count; - char_u *sub_firstline; // allocated copy of first sub line + char *sub_firstline; // allocated copy of first sub line bool endcolumn = false; // cursor in last column when done PreviewLines preview_lines = { KV_INITIAL_VALUE, 0 }; static int pre_src_id = 0; // Source id for the preview highlight @@ -3517,14 +3512,14 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle if (*cmd != '&') { which_pat = RE_SEARCH; // use last '/' pattern } - pat = (char_u *)""; // empty search pattern - delimiter = *cmd++; // remember delimiter character + pat = ""; // empty search pattern + delimiter = (char_u)(*cmd++); // remember delimiter character has_second_delim = true; } else { // find the end of the regexp which_pat = RE_LAST; // use last used regexp - delimiter = *cmd++; // remember delimiter character + delimiter = (char_u)(*cmd++); // remember delimiter character pat = cmd; // remember start of search pat - cmd = skip_regexp(cmd, delimiter, p_magic, &eap->arg); + cmd = (char *)skip_regexp((char_u *)cmd, delimiter, p_magic, &eap->arg); if (cmd[0] == delimiter) { // end delimiter found *cmd++ = NUL; // replace it with a NUL has_second_delim = true; @@ -3550,7 +3545,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle if (!eap->skip && !preview) { sub_set_replacement((SubReplacementString) { - .sub = xstrdup((char *)sub), + .sub = xstrdup(sub), .timestamp = os_time(), .additional_elements = NULL, }); @@ -3561,7 +3556,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle return NULL; } pat = NULL; // search_regcomp() will use previous pattern - sub = (char_u *)old_sub.sub; + sub = old_sub.sub; // Vi compatibility quirk: repeating with ":s" keeps the cursor in the // last column after using "$". @@ -3578,9 +3573,9 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle bool save_do_ask = subflags.do_ask; // remember user specified 'c' flag // check for a trailing count - cmd = skipwhite(cmd); + cmd = (char *)skipwhite((char_u *)cmd); if (ascii_isdigit(*cmd)) { - i = getdigits_long(&cmd, true, 0); + i = getdigits_long((char_u **)&cmd, true, 0); if (i <= 0 && !eap->skip && subflags.do_error) { emsg(_(e_zerocount)); return NULL; @@ -3595,9 +3590,9 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle /* * check for trailing command or garbage */ - cmd = skipwhite(cmd); + cmd = (char *)skipwhite((char_u *)cmd); if (*cmd && *cmd != '"') { // if not end-of-line or comment - eap->nextcmd = check_nextcmd(cmd); + eap->nextcmd = check_nextcmd((char_u *)cmd); if (eap->nextcmd == NULL) { emsg(_(e_trailing)); return NULL; @@ -3614,7 +3609,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle return NULL; } - if (search_regcomp(pat, RE_SUBST, which_pat, (preview ? 0 : SEARCH_HIS), + if (search_regcomp((char_u *)pat, RE_SUBST, which_pat, (preview ? 0 : SEARCH_HIS), ®match) == FAIL) { if (subflags.do_error) { emsg(_(e_invcmd)); @@ -3634,7 +3629,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle assert(sub != NULL); bool sub_needs_free = false; - char_u *sub_copy = NULL; + char *sub_copy = NULL; // If the substitute pattern starts with "\=" then it's an expression. // Make a copy, a recursive function may free it. @@ -3642,11 +3637,11 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle // pattern. We do it here once to avoid it to be replaced over and over // again. if (sub[0] == '\\' && sub[1] == '=') { - sub = vim_strsave(sub); + sub = xstrdup(sub); sub_copy = sub; } else { - char_u *source = sub; - sub = regtilde(sub, p_magic, preview); + char *source = sub; + sub = (char *)regtilde((char_u *)sub, p_magic, preview); // When previewing, the new pattern allocated by regtilde() needs to be freed // in this function because it will not be used or freed by regtilde() later. sub_needs_free = preview && sub != source; @@ -3667,8 +3662,8 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle colnr_T copycol; colnr_T matchcol; colnr_T prev_matchcol = MAXCOL; - char_u *new_end, *new_start = NULL; - char_u *p1; + char *new_end, *new_start = NULL; + char *p1; bool did_sub = false; int lastone; long nmatch_tl = 0; // nr of lines matched below lnum @@ -3768,7 +3763,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle break; } if (sub_firstline == NULL) { - sub_firstline = vim_strsave(ml_get(sub_firstlnum)); + sub_firstline = (char *)vim_strsave(ml_get(sub_firstlnum)); } // Save the line number of the last change for the final @@ -3790,7 +3785,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle skip_match = true; } else { // search for a match at next column - matchcol += utfc_ptr2len(sub_firstline + matchcol); + matchcol += utfc_ptr2len((char_u *)sub_firstline + matchcol); } // match will be pushed to preview_lines, bring it into a proper state current_match.start.col = matchcol; @@ -3851,7 +3846,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle while (subflags.do_ask) { if (exmode_active) { char *prompt; - char_u *resp; + char *resp; colnr_T sc, ec; print_line_no_prefix(lnum, subflags.do_number, subflags.do_list); @@ -3871,12 +3866,11 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle prompt = xmallocz(ec + 1); memset(prompt, ' ', sc); memset(prompt + sc, '^', ec - sc + 1); - resp = (char_u *)getcmdline_prompt(-1, prompt, 0, EXPAND_NOTHING, - NULL, CALLBACK_NONE); + resp = getcmdline_prompt(-1, prompt, 0, EXPAND_NOTHING, NULL, CALLBACK_NONE); msg_putchar('\n'); xfree(prompt); if (resp != NULL) { - typed = *resp; + typed = (char_u)(*resp); xfree(resp); } else { // getcmdline_prompt() returns NULL if there is no command line to return. @@ -3889,7 +3883,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle typed = 'q'; } } else { - char_u *orig_line = NULL; + char *orig_line = NULL; int len_change = 0; const bool save_p_lz = p_lz; int save_p_fen = curwin->w_p_fen; @@ -3909,15 +3903,16 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle // really update the line, it would change // what matches. Temporarily replace the line // and change it back afterwards. - orig_line = vim_strsave(ml_get(lnum)); - char_u *new_line = concat_str(new_start, sub_firstline + copycol); + orig_line = (char *)vim_strsave(ml_get(lnum)); + char *new_line = (char *)concat_str((char_u *)new_start, + (char_u *)sub_firstline + copycol); // Position the cursor relative to the end of the line, the // previous substitute may have inserted or deleted characters // before the cursor. len_change = (int)STRLEN(new_line) - (int)STRLEN(orig_line); curwin->w_cursor.col += len_change; - ml_replace(lnum, new_line, false); + ml_replace(lnum, (char_u *)new_line, false); } search_match_lines = regmatch.endpos[0].lnum @@ -3951,8 +3946,10 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle RedrawingDisabled = temp; no_mapping++; // don't map this key + allow_keys++; // allow special keys typed = plain_vgetc(); no_mapping--; + allow_keys--; // clear the question msg_didout = false; // don't scroll up @@ -3962,7 +3959,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle // restore the line if (orig_line != NULL) { - ml_replace(lnum, orig_line, false); + ml_replace(lnum, (char_u *)orig_line, false); } } @@ -4035,7 +4032,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle if (nmatch > 1) { \ sub_firstlnum += nmatch - 1; \ xfree(sub_firstline); \ - sub_firstline = vim_strsave(ml_get(sub_firstlnum)); \ + sub_firstline = (char *)vim_strsave(ml_get(sub_firstlnum)); \ /* When going beyond the last line, stop substituting. */ \ if (sub_firstlnum <= line2) { \ do_again = true; \ @@ -4047,7 +4044,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle /* Already hit end of the buffer, sub_firstlnum is one */ \ /* less than what it ought to be. */ \ xfree(sub_firstline); \ - sub_firstline = vim_strsave((char_u *)""); \ + sub_firstline = xstrdup(""); \ copycol = 0; \ } \ } while (0) @@ -4085,7 +4082,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle // get length of substitution part sublen = vim_regsub_multi(®match, sub_firstlnum - regmatch.startpos[0].lnum, - sub, sub_firstline, false, p_magic, true); + (char_u *)sub, (char_u *)sub_firstline, false, p_magic, true); // If getting the substitute string caused an error, don't do // the replacement. // Don't keep flags set by a recursive call @@ -4106,7 +4103,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle if (nmatch == 1) { p1 = sub_firstline; } else { - p1 = ml_get(sub_firstlnum + nmatch - 1); + p1 = (char *)ml_get(sub_firstlnum + nmatch - 1); nmatch_tl += nmatch - 1; } size_t copy_len = regmatch.startpos[0].col - copycol; @@ -4125,7 +4122,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle (void)vim_regsub_multi(®match, sub_firstlnum - regmatch.startpos[0].lnum, - sub, new_end, true, p_magic, true); + (char_u *)sub, (char_u *)new_end, true, p_magic, true); sub_nsubs++; did_sub = true; @@ -4141,8 +4138,8 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle // TODO(bfredl): this has some robustness issues, look into later. bcount_t replaced_bytes = 0; lpos_T start = regmatch.startpos[0], end = regmatch.endpos[0]; - for (i = 0; i < nmatch-1; i++) { - replaced_bytes += STRLEN(ml_get(lnum_start+i)) + 1; + for (i = 0; i < nmatch - 1; i++) { + replaced_bytes += STRLEN(ml_get(lnum_start + i)) + 1; } replaced_bytes += end.col - start.col; @@ -4159,7 +4156,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle } else if (*p1 == CAR) { if (u_inssub(lnum) == OK) { // prepare for undo *p1 = NUL; // truncate up to the CR - ml_append(lnum - 1, new_start, + ml_append(lnum - 1, (char_u *)new_start, (colnr_T)(p1 - new_start + 1), false); mark_adjust(lnum + 1, (linenr_T)MAXLNUM, 1L, 0L, kExtmarkNOOP); @@ -4182,7 +4179,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle p1 = new_start - 1; } } else { - p1 += utfc_ptr2len(p1) - 1; + p1 += utfc_ptr2len((char_u *)p1) - 1; } } size_t new_endcol = STRLEN(new_start); @@ -4197,9 +4194,9 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle u_save_cursor(); did_save = true; } - extmark_splice(curbuf, lnum_start-1, start_col, - end.lnum-start.lnum, matchcols, replaced_bytes, - lnum-lnum_start, subcols, sublen-1, kExtmarkUndo); + extmark_splice(curbuf, lnum_start - 1, start_col, + end.lnum - start.lnum, matchcols, replaced_bytes, + lnum - lnum_start, subcols, sublen - 1, kExtmarkUndo); } @@ -4253,7 +4250,7 @@ skip: if (u_savesub(lnum) != OK) { break; } - ml_replace(lnum, new_start, true); + ml_replace(lnum, (char_u *)new_start, true); if (nmatch_tl > 0) { /* @@ -4315,6 +4312,8 @@ skip: lnum -= regmatch.startpos[0].lnum; } + // uncrustify:off + #define PUSH_PREVIEW_LINES() \ do { \ if (preview) { \ @@ -4334,6 +4333,8 @@ skip: } \ } while (0) + // uncrustify:on + // Push the match to preview_lines. PUSH_PREVIEW_LINES(); @@ -4455,8 +4456,8 @@ skip: preview_buf = show_sub(eap, old_cursor, &preview_lines, pre_hl_id, pre_src_id, bufnr); if (subsize > 0) { - extmark_clear(orig_buf, pre_src_id, eap->line1-1, 0, - kv_last(preview_lines.subresults).end.lnum-1, MAXCOL); + extmark_clear(orig_buf, pre_src_id, eap->line1 - 1, 0, + kv_last(preview_lines.subresults).end.lnum - 1, MAXCOL); } } } @@ -4517,12 +4518,12 @@ bool do_sub_msg(bool count_only) return false; } -static void global_exe_one(char_u *const cmd, const linenr_T lnum) +static void global_exe_one(char *const cmd, const linenr_T lnum) { curwin->w_cursor.lnum = lnum; curwin->w_cursor.col = 0; if (*cmd == NUL || *cmd == '\n') { - do_cmdline((char_u *)"p", NULL, NULL, DOCMD_NOWAIT); + do_cmdline("p", NULL, NULL, DOCMD_NOWAIT); } else { do_cmdline(cmd, NULL, NULL, DOCMD_NOWAIT); } @@ -4547,10 +4548,10 @@ void ex_global(exarg_T *eap) linenr_T lnum; // line number according to old situation int ndone = 0; int type; // first char of cmd: 'v' or 'g' - char_u *cmd; // command argument + char *cmd; // command argument - char_u delim; // delimiter, normally '/' - char_u *pat; + char delim; // delimiter, normally '/' + char *pat; regmmatch_T regmatch; int match; int which_pat; @@ -4567,9 +4568,9 @@ void ex_global(exarg_T *eap) if (eap->forceit) { // ":global!" is like ":vglobal" type = 'v'; } else { - type = *eap->cmd; + type = (uint8_t)(*eap->cmd); } - cmd = eap->arg; + cmd = (char *)eap->arg; which_pat = RE_LAST; // default: use last used regexp /* @@ -4588,8 +4589,8 @@ void ex_global(exarg_T *eap) } else { which_pat = RE_SEARCH; // use previous search pattern } - ++cmd; - pat = (char_u *)""; + cmd++; + pat = ""; } else if (*cmd == NUL) { emsg(_("E148: Regular expression missing from global")); return; @@ -4599,13 +4600,13 @@ void ex_global(exarg_T *eap) delim = *cmd; // get the delimiter cmd++; // skip delimiter if there is one pat = cmd; // remember start of pattern - cmd = skip_regexp(cmd, delim, p_magic, &eap->arg); + cmd = (char *)skip_regexp((char_u *)cmd, delim, p_magic, &eap->arg); if (cmd[0] == delim) { // end delimiter found *cmd++ = NUL; // replace it with a NUL } } - if (search_regcomp(pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL) { + if (search_regcomp((char_u *)pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL) { emsg(_(e_invcmd)); return; } @@ -4651,12 +4652,11 @@ void ex_global(exarg_T *eap) } /// Execute `cmd` on lines marked with ml_setmarked(). -void global_exe(char_u *cmd) +void global_exe(char *cmd) { linenr_T old_lcount; // b_ml.ml_line_count before the command buf_T *old_buf = curbuf; // remember what buffer we started in linenr_T lnum; // line number according to old situation - int save_mapped_ctrl_c = mapped_ctrl_c; // Set current position only once for a global command. // If global_busy is set, setpcmark() will not do anything. @@ -4665,8 +4665,6 @@ void global_exe(char_u *cmd) // When the command writes a message, don't overwrite the command. msg_didout = true; - // Disable CTRL-C mapping, let it interrupt (potentially long output). - mapped_ctrl_c = 0; sub_nsubs = 0; sub_nlines = 0; @@ -4679,7 +4677,6 @@ void global_exe(char_u *cmd) os_breakcheck(); } - mapped_ctrl_c = save_mapped_ctrl_c; global_busy = 0; if (global_need_beginline) { beginline(BL_WHITE | BL_FIX); @@ -4758,20 +4755,20 @@ bool prepare_tagpreview(bool undo_sync) /// ":help": open a read-only window on a help file void ex_help(exarg_T *eap) { - char_u *arg; - char_u *tag; + char *arg; + char *tag; FILE *helpfd; // file descriptor of help file int n; int i; win_T *wp; int num_matches; - char_u **matches; - char_u *p; + char **matches; + char *p; int empty_fnum = 0; int alt_fnum = 0; buf_T *buf; int len; - char_u *lang; + char *lang; const bool old_KeyTyped = KeyTyped; if (eap != NULL) { @@ -4779,15 +4776,15 @@ void ex_help(exarg_T *eap) * A ":help" command ends at the first LF, or at a '|' that is * followed by some text. Set nextcmd to the following command. */ - for (arg = eap->arg; *arg; ++arg) { + for (arg = (char *)eap->arg; *arg; arg++) { if (*arg == '\n' || *arg == '\r' || (*arg == '|' && arg[1] != NUL && arg[1] != '|')) { *arg++ = NUL; - eap->nextcmd = arg; + eap->nextcmd = (char_u *)arg; break; } } - arg = eap->arg; + arg = (char *)eap->arg; if (eap->forceit && *arg == NUL && !curbuf->b_help) { emsg(_("E478: Don't panic!")); @@ -4798,7 +4795,7 @@ void ex_help(exarg_T *eap) return; } } else { - arg = (char_u *)""; + arg = ""; } // remove trailing blanks @@ -4812,14 +4809,13 @@ void ex_help(exarg_T *eap) // When no argument given go to the index. if (*arg == NUL) { - arg = (char_u *)"help.txt"; + arg = "help.txt"; } /* * Check if there is a match for the argument. */ - n = find_help_tags(arg, &num_matches, &matches, - eap != NULL && eap->forceit); + n = find_help_tags(arg, &num_matches, &matches, eap != NULL && eap->forceit); i = 0; if (n != FAIL && lang != NULL) { @@ -4839,14 +4835,14 @@ void ex_help(exarg_T *eap) semsg(_("E149: Sorry, no help for %s"), arg); } if (n != FAIL) { - FreeWild(num_matches, matches); + FreeWild(num_matches, (char_u **)matches); } return; } // The first match (in the requested language) is the best match. - tag = vim_strsave(matches[i]); - FreeWild(num_matches, matches); + tag = xstrdup(matches[i]); + FreeWild(num_matches, (char_u **)matches); /* * Re-use an existing help window or open a new one. @@ -4916,7 +4912,7 @@ void ex_help(exarg_T *eap) // It is needed for do_tag top open folds under the cursor. KeyTyped = old_KeyTyped; - do_tag(tag, DT_HELP, 1, FALSE, TRUE); + do_tag((char_u *)tag, DT_HELP, 1, false, true); // Delete the empty buffer if we're not using it. Careful: autocommands // may have jumped to another window, check that the buffer is not in a @@ -4942,7 +4938,7 @@ erret: /// Changes the "@" to NUL if found, and returns a pointer to "xx". /// /// @return NULL if not found. -char_u *check_help_lang(char_u *arg) +char *check_help_lang(char *arg) { int len = (int)STRLEN(arg); @@ -4968,11 +4964,11 @@ char_u *check_help_lang(char_u *arg) /// @param wrong_case no matching case /// /// @return a heuristic indicating how well the given string matches. -int help_heuristic(char_u *matched_string, int offset, int wrong_case) +int help_heuristic(char *matched_string, int offset, int wrong_case) FUNC_ATTR_PURE { int num_letters; - char_u *p; + char *p; num_letters = 0; for (p = matched_string; *p; p++) { @@ -5024,7 +5020,7 @@ static int help_compare(const void *s1, const void *s2) /// the number of matches in num_matches. /// The matches will be sorted with a "best" match algorithm. /// When "keep_lang" is true try keeping the language of the current buffer. -int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches, bool keep_lang) +int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep_lang) { int i; static const char *(mtable[]) = { @@ -5057,7 +5053,7 @@ int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches, bool "!=?", "!~?", "<=?", "<?", "==?", "=~?", ">=?", ">?", "is?", "isnot?" }; - char_u *d = IObuff; // assume IObuff is long enough! + char *d = (char *)IObuff; // assume IObuff is long enough! if (STRNICMP(arg, "expr-", 5) == 0) { // When the string starting with "expr-" and containing '?' and matches @@ -5098,7 +5094,7 @@ int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches, bool && ((arg[1] != NUL && arg[2] == NUL) || (vim_strchr((char_u *)"%_z@", arg[1]) != NULL && arg[2] != NUL))) { - vim_snprintf((char *)d, IOSIZE, "/\\\\%s", arg + 1); + vim_snprintf(d, IOSIZE, "/\\\\%s", arg + 1); // Check for "/\\_$", should be "/\\_\$" if (d[3] == '_' && d[4] == '$') { STRCPY(d + 4, "\\$"); @@ -5118,14 +5114,14 @@ int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches, bool if (*arg == '(' && arg[1] == '\'') { arg++; } - for (const char_u *s = arg; *s; s++) { + for (const char *s = arg; *s; s++) { // Replace "|" with "bar" and '"' with "quote" to match the name of // the tags for these commands. // Replace "*" with ".*" and "?" with "." to match command line // completion. // Insert a backslash before '~', '$' and '.' to avoid their // special meaning. - if (d - IObuff > IOSIZE - 10) { // getting too long!? + if ((char_u *)d - IObuff > IOSIZE - 10) { // getting too long!? break; } switch (*s) { @@ -5159,7 +5155,7 @@ int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches, bool || vim_strchr((char_u *) "?@[\\]^", s[1]) != NULL))) { - if (d > IObuff && d[-1] != '_' && d[-1] != '\\') { + if ((char_u *)d > IObuff && d[-1] != '_' && d[-1] != '\\') { *d++ = '_'; // prepend a '_' to make x_CTRL-x } STRCPY(d, "CTRL-"); @@ -5217,15 +5213,15 @@ int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches, bool *d = NUL; if (*IObuff == '`') { - if (d > IObuff + 2 && d[-1] == '`') { + if ((char_u *)d > IObuff + 2 && d[-1] == '`') { // remove the backticks from `command` memmove(IObuff, IObuff + 1, STRLEN(IObuff)); d[-2] = NUL; - } else if (d > IObuff + 3 && d[-2] == '`' && d[-1] == ',') { + } else if ((char_u *)d > IObuff + 3 && d[-2] == '`' && d[-1] == ',') { // remove the backticks and comma from `command`, memmove(IObuff, IObuff + 1, STRLEN(IObuff)); d[-3] = NUL; - } else if (d > IObuff + 4 && d[-3] == '`' + } else if ((char_u *)d > IObuff + 4 && d[-3] == '`' && d[-2] == '\\' && d[-1] == '.') { // remove the backticks and dot from `command`\. memmove(IObuff, IObuff + 1, STRLEN(IObuff)); @@ -5241,7 +5237,7 @@ int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches, bool if (keep_lang) { flags |= TAG_KEEP_LANG; } - if (find_tags(IObuff, num_matches, matches, flags, MAXCOL, NULL) == OK + if (find_tags(IObuff, num_matches, (char_u ***)matches, flags, MAXCOL, NULL) == OK && *num_matches > 0) { // Sort the matches found on the heuristic number that is after the // tag name. @@ -5267,9 +5263,9 @@ static void prepare_help_buffer(void) // Accept all ASCII chars for keywords, except ' ', '*', '"', '|', and // latin1 word characters (for translated help files). // Only set it when needed, buf_init_chartab() is some work. - char_u *p = (char_u *)"!-~,^*,^|,^\",192-255"; + char *p = "!-~,^*,^|,^\",192-255"; if (STRCMP(curbuf->b_p_isk, p) != 0) { - set_string_option_direct("isk", -1, p, OPT_FREE|OPT_LOCAL, 0); + set_string_option_direct("isk", -1, (char_u *)p, OPT_FREE|OPT_LOCAL, 0); check_buf_options(curbuf); (void)buf_init_chartab(curbuf, FALSE); } @@ -5300,7 +5296,7 @@ static void prepare_help_buffer(void) void fix_help_buffer(void) { linenr_T lnum; - char_u *line; + char *line; bool in_example = false; // Set filetype to "help". @@ -5312,13 +5308,13 @@ void fix_help_buffer(void) if (!syntax_present(curwin)) { for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) { - line = ml_get_buf(curbuf, lnum, false); + line = (char *)ml_get_buf(curbuf, lnum, false); const size_t len = STRLEN(line); if (in_example && len > 0 && !ascii_iswhite(line[0])) { // End of example: non-white or '<' in first column. if (line[0] == '<') { // blank-out a '<' in the first column - line = ml_get_buf(curbuf, lnum, true); + line = (char *)ml_get_buf(curbuf, lnum, true); line[0] = ' '; } in_example = false; @@ -5326,12 +5322,12 @@ void fix_help_buffer(void) if (!in_example && len > 0) { if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) { // blank-out a '>' in the last column (start of example) - line = ml_get_buf(curbuf, lnum, true); + line = (char *)ml_get_buf(curbuf, lnum, true); line[len - 1] = ' '; in_example = true; } else if (line[len - 1] == '~') { // blank-out a '~' at the end of line (header marker) - line = ml_get_buf(curbuf, lnum, true); + line = (char *)ml_get_buf(curbuf, lnum, true); line[len - 1] = ' '; } } @@ -5342,7 +5338,7 @@ void fix_help_buffer(void) * In the "help.txt" and "help.abx" file, add the locally added help * files. This uses the very first line in the help file. */ - char_u *const fname = path_tail(curbuf->b_fname); + char *const fname = (char *)path_tail(curbuf->b_fname); if (FNAMECMP(fname, "help.txt") == 0 || (FNAMENCMP(fname, "help.", 5) == 0 && ASCII_ISALPHA(fname[5]) @@ -5350,24 +5346,24 @@ void fix_help_buffer(void) && TOLOWER_ASC(fname[7]) == 'x' && fname[8] == NUL)) { for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; lnum++) { - line = ml_get_buf(curbuf, lnum, false); - if (strstr((char *)line, "*local-additions*") == NULL) { + line = (char *)ml_get_buf(curbuf, lnum, false); + if (strstr(line, "*local-additions*") == NULL) { continue; } // Go through all directories in 'runtimepath', skipping // $VIMRUNTIME. - char_u *p = p_rtp; + char *p = (char *)p_rtp; while (*p != NUL) { - copy_option_part(&p, NameBuff, MAXPATHL, ","); - char_u *const rt = (char_u *)vim_getenv("VIMRUNTIME"); + copy_option_part((char_u **)&p, NameBuff, MAXPATHL, ","); + char *const rt = vim_getenv("VIMRUNTIME"); if (rt != NULL - && path_full_compare(rt, NameBuff, false, true) != kEqualFiles) { + && path_full_compare((char_u *)rt, NameBuff, false, true) != kEqualFiles) { int fcount; - char_u **fnames; - char_u *s; + char **fnames; + char *s; vimconv_T vc; - char_u *cp; + char *cp; // Find all "doc/ *.txt" files in this directory. if (!add_pathsep((char *)NameBuff) @@ -5379,9 +5375,9 @@ void fix_help_buffer(void) // Note: We cannot just do `&NameBuff` because it is a statically sized array // so `NameBuff == &NameBuff` according to C semantics. - char_u *buff_list[1] = { NameBuff }; - if (gen_expand_wildcards(1, buff_list, &fcount, - &fnames, EW_FILE|EW_SILENT) == OK + char *buff_list[1] = { (char *)NameBuff }; + if (gen_expand_wildcards(1, (char_u **)buff_list, &fcount, + (char_u ***)&fnames, EW_FILE|EW_SILENT) == OK && fcount > 0) { // If foo.abx is found use it instead of foo.txt in // the same directory. @@ -5393,12 +5389,12 @@ void fix_help_buffer(void) if (fnames[i1] == NULL || fnames[i2] == NULL) { continue; } - const char_u *const f1 = fnames[i1]; - const char_u *const f2 = fnames[i2]; - const char_u *const t1 = path_tail(f1); - const char_u *const t2 = path_tail(f2); - const char_u *const e1 = STRRCHR(t1, '.'); - const char_u *const e2 = STRRCHR(t2, '.'); + const char *const f1 = fnames[i1]; + const char *const f2 = fnames[i2]; + const char *const t1 = (char *)path_tail((char_u *)f1); + const char *const t2 = (char *)path_tail((char_u *)f2); + const char *const e1 = (char *)STRRCHR(t1, '.'); + const char *const e2 = (char *)STRRCHR(t2, '.'); if (e1 == NULL || e2 == NULL) { continue; } @@ -5424,13 +5420,13 @@ void fix_help_buffer(void) continue; } - FILE *const fd = os_fopen((char *)fnames[fi], "r"); + FILE *const fd = os_fopen(fnames[fi], "r"); if (fd == NULL) { continue; } vim_fgets(IObuff, IOSIZE, fd); if (IObuff[0] == '*' - && (s = vim_strchr(IObuff + 1, '*')) + && (s = (char *)vim_strchr(IObuff + 1, '*')) != NULL) { TriState this_utf = kNone; // Change tag definition to a @@ -5444,9 +5440,9 @@ void fix_help_buffer(void) // The text is utf-8 when a byte // above 127 is found and no // illegal byte sequence is found. - if (*s >= 0x80 && this_utf != kFalse) { + if ((char_u)(*s) >= 0x80 && this_utf != kFalse) { this_utf = kTrue; - const int l = utf_ptr2len(s); + const int l = utf_ptr2len((char_u *)s); if (l == 1) { this_utf = kFalse; } @@ -5463,26 +5459,26 @@ void fix_help_buffer(void) p_enc); if (vc.vc_type == CONV_NONE) { // No conversion needed. - cp = IObuff; + cp = (char *)IObuff; } else { // Do the conversion. If it fails // use the unconverted text. - cp = string_convert(&vc, IObuff, NULL); + cp = (char *)string_convert(&vc, IObuff, NULL); if (cp == NULL) { - cp = IObuff; + cp = (char *)IObuff; } } convert_setup(&vc, NULL, NULL); - ml_append(lnum, cp, (colnr_T)0, false); - if (cp != IObuff) { + ml_append(lnum, (char_u *)cp, (colnr_T)0, false); + if ((char_u *)cp != IObuff) { xfree(cp); } lnum++; } fclose(fd); } - FreeWild(fcount, fnames); + FreeWild(fcount, (char_u **)fnames); } } xfree(rt); @@ -5513,15 +5509,15 @@ void ex_viusage(exarg_T *eap) /// French) /// @param add_help_tags Whether to add the "help-tags" tag /// @param ignore_writeerr ignore write error -static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, bool add_help_tags, +static void helptags_one(char *dir, const char *ext, const char *tagfname, bool add_help_tags, bool ignore_writeerr) FUNC_ATTR_NONNULL_ALL { garray_T ga; int filecount; - char_u **files; - char_u *p1, *p2; - char_u *s; + char **files; + char *p1, *p2; + char *s; TriState utf8 = kNone; bool mix = false; // detected mixed encodings @@ -5536,8 +5532,8 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, // Note: We cannot just do `&NameBuff` because it is a statically sized array // so `NameBuff == &NameBuff` according to C semantics. - char_u *buff_list[1] = { NameBuff }; - if (gen_expand_wildcards(1, buff_list, &filecount, &files, + char *buff_list[1] = { (char *)NameBuff }; + if (gen_expand_wildcards(1, (char_u **)buff_list, &filecount, (char_u ***)&files, EW_FILE|EW_SILENT) == FAIL || filecount == 0) { if (!got_int) { @@ -5562,7 +5558,7 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, if (!ignore_writeerr) { semsg(_("E152: Cannot open %s for writing"), NameBuff); } - FreeWild(filecount, files); + FreeWild(filecount, (char_u **)files); return; } @@ -5571,31 +5567,31 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, ga_init(&ga, (int)sizeof(char_u *), 100); if (add_help_tags || path_full_compare((char_u *)"$VIMRUNTIME/doc", - dir, false, true) == kEqualFiles) { + (char_u *)dir, false, true) == kEqualFiles) { size_t s_len = 18 + STRLEN(tagfname); s = xmalloc(s_len); - snprintf((char *)s, s_len, "help-tags\t%s\t1\n", tagfname); - GA_APPEND(char_u *, &ga, s); + snprintf(s, s_len, "help-tags\t%s\t1\n", tagfname); + GA_APPEND(char *, &ga, s); } // Go over all the files and extract the tags. for (int fi = 0; fi < filecount && !got_int; fi++) { - FILE *const fd = os_fopen((char *)files[fi], "r"); + FILE *const fd = os_fopen(files[fi], "r"); if (fd == NULL) { semsg(_("E153: Unable to open %s for reading"), files[fi]); continue; } - const char_u *const fname = files[fi] + dirlen + 1; + const char *const fname = files[fi] + dirlen + 1; bool firstline = true; while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) { if (firstline) { // Detect utf-8 file by a non-ASCII char in the first line. TriState this_utf8 = kNone; - for (s = IObuff; *s != NUL; s++) { - if (*s >= 0x80) { + for (s = (char *)IObuff; *s != NUL; s++) { + if ((char_u)(*s) >= 0x80) { this_utf8 = kTrue; - const int l = utf_ptr2len(s); + const int l = utf_ptr2len((char_u *)s); if (l == 1) { // Illegal UTF-8 byte sequence. this_utf8 = kFalse; @@ -5617,9 +5613,9 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, } firstline = false; } - p1 = vim_strchr(IObuff, '*'); // find first '*' + p1 = (char *)vim_strchr(IObuff, '*'); // find first '*' while (p1 != NULL) { - p2 = (char_u *)strchr((const char *)p1 + 1, '*'); // Find second '*'. + p2 = strchr((const char *)p1 + 1, '*'); // Find second '*'. if (p2 != NULL && p2 > p1 + 1) { // Skip "*" and "**". for (s = p1 + 1; s < p2; s++) { if (*s == ' ' || *s == '\t' || *s == '|') { @@ -5631,18 +5627,18 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, // characters, there is white space before it and is // followed by a white character or end-of-line. if (s == p2 - && (p1 == IObuff || p1[-1] == ' ' || p1[-1] == '\t') + && ((char_u *)p1 == IObuff || p1[-1] == ' ' || p1[-1] == '\t') && (vim_strchr((char_u *)" \t\n\r", s[1]) != NULL || s[1] == '\0')) { *p2 = '\0'; p1++; size_t s_len= (p2 - p1) + STRLEN(fname) + 2; s = xmalloc(s_len); - GA_APPEND(char_u *, &ga, s); - snprintf((char *)s, s_len, "%s\t%s", p1, fname); + GA_APPEND(char *, &ga, s); + snprintf(s, s_len, "%s\t%s", p1, fname); // find next '*' - p2 = vim_strchr(p2 + 1, '*'); + p2 = (char *)vim_strchr((char_u *)p2 + 1, '*'); } } p1 = p2; @@ -5653,7 +5649,7 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, fclose(fd); } - FreeWild(filecount, files); + FreeWild(filecount, (char_u **)files); if (!got_int && ga.ga_data != NULL) { // Sort the tags. @@ -5661,8 +5657,8 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, // Check for duplicates. for (int i = 1; i < ga.ga_len; i++) { - p1 = ((char_u **)ga.ga_data)[i - 1]; - p2 = ((char_u **)ga.ga_data)[i]; + p1 = ((char **)ga.ga_data)[i - 1]; + p2 = ((char **)ga.ga_data)[i]; while (*p1 == *p2) { if (*p2 == '\t') { *p2 = NUL; @@ -5684,10 +5680,10 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, // Write the tags into the file. for (int i = 0; i < ga.ga_len; i++) { - s = ((char_u **)ga.ga_data)[i]; + s = ((char **)ga.ga_data)[i]; if (STRNCMP(s, "help-tags\t", 10) == 0) { // help-tags entry was added in formatted form - fputs((char *)s, fd_tags); + fputs(s, fd_tags); } else { fprintf(fd_tags, "%s\t/" "*", s); for (p1 = s; *p1 != '\t'; p1++) { @@ -5710,16 +5706,16 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, } /// Generate tags in one help directory, taking care of translations. -static void do_helptags(char_u *dirname, bool add_help_tags, bool ignore_writeerr) +static void do_helptags(char *dirname, bool add_help_tags, bool ignore_writeerr) FUNC_ATTR_NONNULL_ALL { int len; garray_T ga; - char_u lang[2]; - char_u ext[5]; - char_u fname[8]; + char lang[2]; + char ext[5]; + char fname[8]; int filecount; - char_u **files; + char **files; // Get a list of all files in the help directory and in subdirectories. STRLCPY(NameBuff, dirname, sizeof(NameBuff)); @@ -5731,8 +5727,8 @@ static void do_helptags(char_u *dirname, bool add_help_tags, bool ignore_writeer // Note: We cannot just do `&NameBuff` because it is a statically sized array // so `NameBuff == &NameBuff` according to C semantics. - char_u *buff_list[1] = { NameBuff }; - if (gen_expand_wildcards(1, buff_list, &filecount, &files, + char *buff_list[1] = { (char *)NameBuff }; + if (gen_expand_wildcards(1, (char_u **)buff_list, &filecount, (char_u ***)&files, EW_FILE|EW_SILENT) == FAIL || filecount == 0) { semsg(_("E151: No match: %s"), NameBuff); @@ -5794,24 +5790,24 @@ static void do_helptags(char_u *dirname, bool add_help_tags, bool ignore_writeer ext[1] = fname[5]; ext[2] = fname[6]; } - helptags_one(dirname, ext, fname, add_help_tags, ignore_writeerr); + helptags_one(dirname, (char *)ext, (char *)fname, add_help_tags, ignore_writeerr); } ga_clear(&ga); - FreeWild(filecount, files); + FreeWild(filecount, (char_u **)files); } static void helptags_cb(char_u *fname, void *cookie) FUNC_ATTR_NONNULL_ALL { - do_helptags(fname, *(bool *)cookie, true); + do_helptags((char *)fname, *(bool *)cookie, true); } /// ":helptags" void ex_helptags(exarg_T *eap) { expand_T xpc; - char_u *dirname; + char *dirname; bool add_help_tags = false; // Check for ":helptags ++t {dir}". @@ -5825,9 +5821,9 @@ void ex_helptags(exarg_T *eap) } else { ExpandInit(&xpc); xpc.xp_context = EXPAND_DIRECTORIES; - dirname = ExpandOne(&xpc, eap->arg, NULL, - WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); - if (dirname == NULL || !os_isdir(dirname)) { + dirname = (char *)ExpandOne(&xpc, eap->arg, NULL, + WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); + if (dirname == NULL || !os_isdir((char_u *)dirname)) { semsg(_("E150: Not a directory: %s"), eap->arg); } else { do_helptags(dirname, add_help_tags, false); @@ -5873,7 +5869,7 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines { win_T *save_curwin = curwin; cmdmod_T save_cmdmod = cmdmod; - char_u *save_shm_p = vim_strsave(p_shm); + char *save_shm_p = (char *)vim_strsave(p_shm); PreviewLines lines = *preview_lines; buf_T *orig_buf = curbuf; @@ -6006,7 +6002,7 @@ static buf_T *show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines update_screen(SOME_VALID); RedrawingDisabled = save_rd; - set_string_option_direct("shm", -1, save_shm_p, OPT_FREE, SID_NONE); + set_string_option_direct("shm", -1, (char_u *)save_shm_p, OPT_FREE, SID_NONE); xfree(save_shm_p); cmdmod = save_cmdmod; @@ -6042,7 +6038,7 @@ void ex_substitute(exarg_T *eap) block_autocmds(); // Disable events during command preview. - char_u *save_eap = eap->arg; + char *save_eap = (char *)eap->arg; garray_T save_view; win_size_save(&save_view); // Save current window sizes. save_search_patterns(); @@ -6083,7 +6079,7 @@ void ex_substitute(exarg_T *eap) curbuf->b_p_ul = save_b_p_ul; curwin->w_p_cul = save_w_p_cul; // Restore 'cursorline' curwin->w_p_cuc = save_w_p_cuc; // Restore 'cursorcolumn' - eap->arg = save_eap; + eap->arg = (char_u *)save_eap; restore_search_patterns(); win_size_restore(&save_view); ga_clear(&save_view); @@ -6097,7 +6093,7 @@ void ex_substitute(exarg_T *eap) /// @param s if not NULL, terminate the pattern with a NUL. /// /// @return a pointer to the char just past the pattern plus flags. -char_u *skip_vimgrep_pat(char_u *p, char_u **s, int *flags) +char *skip_vimgrep_pat(char *p, char **s, int *flags) { int c; @@ -6106,7 +6102,7 @@ char_u *skip_vimgrep_pat(char_u *p, char_u **s, int *flags) if (s != NULL) { *s = p; } - p = skiptowhite(p); + p = (char *)skiptowhite((char_u *)p); if (s != NULL && *p != NUL) { *p++ = NUL; } @@ -6115,8 +6111,8 @@ char_u *skip_vimgrep_pat(char_u *p, char_u **s, int *flags) if (s != NULL) { *s = p + 1; } - c = *p; - p = skip_regexp(p + 1, c, true, NULL); + c = (char_u)(*p); + p = (char *)skip_regexp((char_u *)p + 1, c, true, NULL); if (*p != c) { return NULL; } diff --git a/src/nvim/ex_cmds.h b/src/nvim/ex_cmds.h index 1c95b75001..a55e74a789 100644 --- a/src/nvim/ex_cmds.h +++ b/src/nvim/ex_cmds.h @@ -21,7 +21,7 @@ // for lnum argument in do_ecmd() #define ECMD_LASTL (linenr_T)0 // use last position in loaded file -#define ECMD_LAST ((linenr_T)-1) // use last position in all files +#define ECMD_LAST ((linenr_T) - 1) // use last position in all files #define ECMD_ONE (linenr_T)1 // use first line /// Previous :substitute replacement string definition diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 5af202c191..c439b29cf6 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -554,7 +554,7 @@ void dialog_changed(buf_T *buf, bool checkall) .forceit = false, }; - dialog_msg(buff, _("Save changes to \"%s\"?"), buf->b_fname); + dialog_msg((char *)buff, _("Save changes to \"%s\"?"), (char *)buf->b_fname); if (checkall) { ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, buff, 1); } else { @@ -565,8 +565,8 @@ void dialog_changed(buf_T *buf, bool checkall) if (buf->b_fname != NULL && check_overwrite(&ea, buf, - buf->b_fname, - buf->b_ffname, + (char *)buf->b_fname, + (char *)buf->b_ffname, false) == OK) { // didn't hit Cancel (void)buf_write_all(buf, false); @@ -583,8 +583,8 @@ void dialog_changed(buf_T *buf, bool checkall) set_bufref(&bufref, buf2); if (buf2->b_fname != NULL - && check_overwrite(&ea, buf2, buf2->b_fname, - buf2->b_ffname, false) == OK) { + && check_overwrite(&ea, buf2, (char *)buf2->b_fname, + (char *)buf2->b_ffname, false) == OK) { // didn't hit Cancel (void)buf_write_all(buf2, false); } @@ -610,8 +610,8 @@ bool dialog_close_terminal(buf_T *buf) { char_u buff[DIALOG_MSG_SIZE]; - dialog_msg(buff, _("Close \"%s\"?"), - (buf->b_fname != NULL) ? buf->b_fname : (char_u *)"?"); + dialog_msg((char *)buff, _("Close \"%s\"?"), + (buf->b_fname != NULL) ? (char *)buf->b_fname : "?"); int ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1); @@ -972,7 +972,7 @@ static int do_arglist(char_u *str, int what, int after, bool will_edit) xfree(exp_files); } else { assert(what == AL_SET); - alist_set(ALIST(curwin), exp_count, exp_files, will_edit, NULL, 0); + alist_set(ALIST(curwin), exp_count, (char **)exp_files, will_edit, NULL, 0); } } @@ -1166,7 +1166,7 @@ void do_argfile(exarg_T *eap, int argn) // Edit the file; always use the last known line number. // When it fails (e.g. Abort for already edited file) restore the // argument index. - if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL, + if (do_ecmd(0, (char *)alist_name(&ARGLIST[curwin->w_arg_idx]), NULL, eap, ECMD_LAST, (buf_hide(curwin->w_buffer) ? ECMD_HIDE : 0) + (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL) { @@ -1427,8 +1427,7 @@ void ex_listdo(exarg_T *eap) i++; // execute the command if (execute) { - do_cmdline(eap->arg, eap->getline, eap->cookie, - DOCMD_VERBOSE + DOCMD_NOWAIT); + do_cmdline((char *)eap->arg, eap->getline, eap->cookie, DOCMD_VERBOSE + DOCMD_NOWAIT); } if (eap->cmdidx == CMD_bufdo) { @@ -2086,7 +2085,7 @@ int do_source(char *fname, int check_other, int is_vimrc) sourcing_lnum = sourcing_lnum_backup; } else { // Call do_cmdline, which will call getsourceline() to get the lines. - do_cmdline(firstline, getsourceline, (void *)&cookie, + do_cmdline((char *)firstline, getsourceline, (void *)&cookie, DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); } retval = OK; diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h index 39dfc1b94c..f3b3e094f5 100644 --- a/src/nvim/ex_cmds_defs.h +++ b/src/nvim/ex_cmds_defs.h @@ -176,7 +176,7 @@ enum { struct exarg { char_u *arg; ///< argument of the command char_u *nextcmd; ///< next command (NULL if none) - char_u *cmd; ///< the name of the command (except for :make) + char *cmd; ///< the name of the command (except for :make) char_u **cmdlinep; ///< pointer to pointer of allocated cmdline cmdidx_T cmdidx; ///< the index for the command uint32_t argt; ///< flags for the command @@ -261,4 +261,18 @@ typedef struct { bool filter_force; ///< set for :filter! } cmdmod_T; +/// Stores command modifier info used by `nvim_parse_cmd` +typedef struct { + bool silent; + bool emsg_silent; + bool sandbox; + bool noautocmd; + long verbose; + cmdmod_T cmdmod; + struct { + bool file; + bool bar; + } magic; +} CmdParseInfo; + #endif // NVIM_EX_CMDS_DEFS_H diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 4562f6c751..7b5d14a404 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -95,7 +95,7 @@ garray_T ucmds = { 0, 0, sizeof(ucmd_T), 4, NULL }; // Struct for storing a line inside a while/for loop typedef struct { - char_u *line; // command line + char *line; // command line linenr_T lnum; // sourcing_lnum of the line } wcmd_T; @@ -121,8 +121,8 @@ struct dbg_stuff { int trylevel; int force_abort; except_T *caught_stack; - char_u *vv_exception; - char_u *vv_throwpoint; + char *vv_exception; + char *vv_throwpoint; int did_emsg; int got_int; int need_rethrow; @@ -145,15 +145,15 @@ struct dbg_stuff { # include "ex_cmds_defs.generated.h" #endif -static char_u dollar_command[2] = { '$', 0 }; +static char dollar_command[2] = { '$', 0 }; static void save_dbg_stuff(struct dbg_stuff *dsp) { dsp->trylevel = trylevel; trylevel = 0; dsp->force_abort = force_abort; force_abort = FALSE; dsp->caught_stack = caught_stack; caught_stack = NULL; - dsp->vv_exception = v_exception(NULL); - dsp->vv_throwpoint = v_throwpoint(NULL); + dsp->vv_exception = (char *)v_exception(NULL); + dsp->vv_throwpoint = (char *)v_throwpoint(NULL); // Necessary for debugging an inactive ":catch", ":finally", ":endtry". dsp->did_emsg = did_emsg; did_emsg = false; @@ -169,8 +169,8 @@ static void restore_dbg_stuff(struct dbg_stuff *dsp) trylevel = dsp->trylevel; force_abort = dsp->force_abort; caught_stack = dsp->caught_stack; - (void)v_exception(dsp->vv_exception); - (void)v_throwpoint(dsp->vv_throwpoint); + (void)v_exception((char_u *)dsp->vv_exception); + (void)v_throwpoint((char_u *)dsp->vv_throwpoint); did_emsg = dsp->did_emsg; got_int = dsp->got_int; need_rethrow = dsp->need_rethrow; @@ -255,7 +255,7 @@ void do_exmode(void) /// Print the executed command for when 'verbose' is set. /// /// @param lnum if 0, only print the command. -static void msg_verbose_cmd(linenr_T lnum, char_u *cmd) +static void msg_verbose_cmd(linenr_T lnum, char *cmd) FUNC_ATTR_NONNULL_ALL { no_wait_return++; @@ -277,8 +277,7 @@ static void msg_verbose_cmd(linenr_T lnum, char_u *cmd) /// Execute a simple command line. Used for translated commands like "*". int do_cmdline_cmd(const char *cmd) { - return do_cmdline((char_u *)cmd, NULL, NULL, - DOCMD_NOWAIT|DOCMD_KEYTYPED); + return do_cmdline((char *)cmd, NULL, NULL, DOCMD_NOWAIT|DOCMD_KEYTYPED); } /// do_cmdline(): execute one Ex command line @@ -301,10 +300,10 @@ int do_cmdline_cmd(const char *cmd) /// @param cookie argument for fgetline() /// /// @return FAIL if cmdline could not be executed, OK otherwise -int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) +int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) { - char_u *next_cmdline; // next cmd to execute - char_u *cmdline_copy = NULL; // copy of cmd line + char *next_cmdline; // next cmd to execute + char *cmdline_copy = NULL; // copy of cmd line bool used_getline = false; // used "fgetline" to obtain command static int recursive = 0; // recursive depth bool msg_didout_before_start = false; @@ -316,7 +315,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) }; garray_T lines_ga; // keep lines for ":while"/":for" int current_line = 0; // active line in lines_ga - char_u *fname = NULL; // function or script name + char *fname = NULL; // function or script name linenr_T *breakpoint = NULL; // ptr to breakpoint field in cookie int *dbg_tick = NULL; // ptr to dbg_tick field in cookie struct dbg_stuff debug_saved; // saved things for debug mode @@ -369,11 +368,11 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) // Get the function or script name and the address where the next breakpoint // line and the debug tick for a function or script are stored. if (getline_is_func) { - fname = func_name(real_cookie); + fname = (char *)func_name(real_cookie); breakpoint = func_breakpoint(real_cookie); dbg_tick = func_dbg_tick(real_cookie); } else if (getline_equal(fgetline, cookie, getsourceline)) { - fname = sourcing_name; + fname = (char *)sourcing_name; breakpoint = source_breakpoint(real_cookie); dbg_tick = source_dbg_tick(real_cookie); } @@ -466,7 +465,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) if (breakpoint != NULL && dbg_tick != NULL && *dbg_tick != debug_tick) { *breakpoint = dbg_find_breakpoint(getline_equal(fgetline, cookie, getsourceline), - fname, sourcing_lnum); + (char_u *)fname, sourcing_lnum); *dbg_tick = debug_tick; } @@ -476,10 +475,10 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) // Did we encounter a breakpoint? if (breakpoint != NULL && *breakpoint != 0 && *breakpoint <= sourcing_lnum) { - dbg_breakpoint(fname, sourcing_lnum); + dbg_breakpoint((char_u *)fname, sourcing_lnum); // Find next breakpoint. *breakpoint = dbg_find_breakpoint(getline_equal(fgetline, cookie, getsourceline), - fname, sourcing_lnum); + (char_u *)fname, sourcing_lnum); *dbg_tick = debug_tick; } if (do_profiling == PROF_YES) { @@ -519,10 +518,10 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) msg_didout = true; } if (fgetline == NULL - || (next_cmdline = fgetline(':', cookie, - cstack.cs_idx < - 0 ? 0 : (cstack.cs_idx + 1) * 2, - true)) == NULL) { + || (next_cmdline = (char *)fgetline(':', cookie, + cstack.cs_idx < + 0 ? 0 : (cstack.cs_idx + 1) * 2, + true)) == NULL) { // Don't call wait_return for aborted command line. The NULL // returned for the end of a sourced file or executed function // doesn't do this. @@ -540,15 +539,14 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) if (flags & DOCMD_KEEPLINE) { xfree(repeat_cmdline); if (count == 0) { - repeat_cmdline = vim_strsave(next_cmdline); + repeat_cmdline = vim_strsave((char_u *)next_cmdline); } else { repeat_cmdline = NULL; } } - } - // 3. Make a copy of the command so we can mess with it. - else if (cmdline_copy == NULL) { - next_cmdline = vim_strsave(next_cmdline); + } else if (cmdline_copy == NULL) { + // 3. Make a copy of the command so we can mess with it. + next_cmdline = xstrdup(next_cmdline); } cmdline_copy = next_cmdline; @@ -560,7 +558,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) * :endwhile/:endfor. */ if (current_line == lines_ga.ga_len - && (cstack.cs_looplevel || has_loop_cmd(next_cmdline))) { + && (cstack.cs_looplevel || has_loop_cmd((char_u *)next_cmdline))) { store_loop_line(&lines_ga, next_cmdline); } did_endif = false; @@ -593,9 +591,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) * "cmdline_copy" can change, e.g. for '%' and '#' expansion. */ recursive++; - next_cmdline = do_one_cmd(&cmdline_copy, flags, - &cstack, - cmd_getline, cmd_cookie); + next_cmdline = do_one_cmd(&cmdline_copy, flags, &cstack, cmd_getline, cmd_cookie); recursive--; // Ignore trailing '|'-separated commands in preview-mode ('inccommand'). @@ -667,8 +663,8 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) // or ":for". if (breakpoint != NULL) { *breakpoint = dbg_find_breakpoint(getline_equal(fgetline, cookie, getsourceline), - fname, - ((wcmd_T *)lines_ga.ga_data)[current_line].lnum-1); + (char_u *)fname, + ((wcmd_T *)lines_ga.ga_data)[current_line].lnum - 1); *dbg_tick = debug_tick; } } else { @@ -811,7 +807,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) // commands are executed. if (current_exception) { char *p = NULL; - char_u *saved_sourcing_name; + char *saved_sourcing_name; linenr_T saved_sourcing_lnum; struct msglist *messages = NULL; struct msglist *next; @@ -837,7 +833,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) break; } - saved_sourcing_name = sourcing_name; + saved_sourcing_name = (char *)sourcing_name; saved_sourcing_lnum = sourcing_lnum; sourcing_name = current_exception->throw_name; sourcing_lnum = current_exception->throw_lnum; @@ -861,7 +857,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, int flags) xfree(p); } xfree(sourcing_name); - sourcing_name = saved_sourcing_name; + sourcing_name = (char_u *)saved_sourcing_name; sourcing_lnum = saved_sourcing_lnum; } else if (got_int || (did_emsg && force_abort)) { // On an interrupt or an aborting error not converted to an exception, @@ -958,7 +954,7 @@ static char_u *get_loop_line(int c, void *cookie, int indent, bool do_concat) { struct loop_cookie *cp = (struct loop_cookie *)cookie; wcmd_T *wp; - char_u *line; + char *line; if (cp->current_line + 1 >= cp->lines_gap->ga_len) { if (cp->repeating) { @@ -966,30 +962,30 @@ static char_u *get_loop_line(int c, void *cookie, int indent, bool do_concat) } // First time inside the ":while"/":for": get line normally. if (cp->getline == NULL) { - line = getcmdline(c, 0L, indent, do_concat); + line = (char *)getcmdline(c, 0L, indent, do_concat); } else { - line = cp->getline(c, cp->cookie, indent, do_concat); + line = (char *)cp->getline(c, cp->cookie, indent, do_concat); } if (line != NULL) { store_loop_line(cp->lines_gap, line); ++cp->current_line; } - return line; + return (char_u *)line; } KeyTyped = false; cp->current_line++; wp = (wcmd_T *)(cp->lines_gap->ga_data) + cp->current_line; sourcing_lnum = wp->lnum; - return vim_strsave(wp->line); + return vim_strsave((char_u *)wp->line); } /// Store a line in "gap" so that a ":while" loop can execute it again. -static void store_loop_line(garray_T *gap, char_u *line) +static void store_loop_line(garray_T *gap, char *line) { wcmd_T *p = GA_APPEND_VIA_PTR(wcmd_T, gap); - p->line = vim_strsave(line); + p->line = xstrdup(line); p->lnum = sourcing_lnum; } @@ -1116,7 +1112,7 @@ static int current_tab_nr(tabpage_T *tab) /// Figure out the address type for ":wincmd". -static void get_wincmd_addr_type(char_u *arg, exarg_T *eap) +static void get_wincmd_addr_type(char *arg, exarg_T *eap) { switch (*arg) { case 'S': @@ -1207,17 +1203,237 @@ static void get_wincmd_addr_type(char_u *arg, exarg_T *eap) /// non-colon, non-whitespace character. // /// @param skipleadingwhite Skip leading whitespace too -static char_u *skip_colon_white(const char_u *p, bool skipleadingwhite) +static char *skip_colon_white(const char *p, bool skipleadingwhite) { if (skipleadingwhite) { - p = skipwhite(p); + p = (char *)skipwhite((char_u *)p); } while (*p == ':') { - p = skipwhite(p + 1); + p = (char *)skipwhite((char_u *)p + 1); + } + + return (char *)p; +} + +/// Set the addr type for command +/// +/// @param p pointer to character after command name in cmdline +static void set_cmd_addr_type(exarg_T *eap, char_u *p) +{ + // ea.addr_type for user commands is set by find_ucmd + if (IS_USER_CMDIDX(eap->cmdidx)) { + return; + } + if (eap->cmdidx != CMD_SIZE) { + eap->addr_type = cmdnames[(int)eap->cmdidx].cmd_addr_type; + } else { + eap->addr_type = ADDR_LINES; + } + // :wincmd range depends on the argument + if (eap->cmdidx == CMD_wincmd && p != NULL) { + get_wincmd_addr_type((char *)skipwhite(p), eap); + } + // :.cc in quickfix window uses line number + if ((eap->cmdidx == CMD_cc || eap->cmdidx == CMD_ll) && bt_quickfix(curbuf)) { + eap->addr_type = ADDR_OTHER; + } +} + +/// Set default command range based on the addr type of the command +static void set_cmd_default_range(exarg_T *eap) +{ + buf_T *buf; + + eap->line1 = 1; + switch (eap->addr_type) { + case ADDR_LINES: + case ADDR_OTHER: + eap->line2 = curbuf->b_ml.ml_line_count; + break; + case ADDR_LOADED_BUFFERS: + buf = firstbuf; + while (buf->b_next != NULL && buf->b_ml.ml_mfp == NULL) { + buf = buf->b_next; + } + eap->line1 = buf->b_fnum; + buf = lastbuf; + while (buf->b_prev != NULL && buf->b_ml.ml_mfp == NULL) { + buf = buf->b_prev; + } + eap->line2 = buf->b_fnum; + break; + case ADDR_BUFFERS: + eap->line1 = firstbuf->b_fnum; + eap->line2 = lastbuf->b_fnum; + break; + case ADDR_WINDOWS: + eap->line2 = LAST_WIN_NR; + break; + case ADDR_TABS: + eap->line2 = LAST_TAB_NR; + break; + case ADDR_TABS_RELATIVE: + eap->line2 = 1; + break; + case ADDR_ARGUMENTS: + if (ARGCOUNT == 0) { + eap->line1 = eap->line2 = 0; + } else { + eap->line2 = ARGCOUNT; + } + break; + case ADDR_QUICKFIX_VALID: + eap->line2 = (linenr_T)qf_get_valid_size(eap); + if (eap->line2 == 0) { + eap->line2 = 1; + } + break; + case ADDR_NONE: + case ADDR_UNSIGNED: + case ADDR_QUICKFIX: + iemsg(_("INTERNAL: Cannot use EX_DFLALL " + "with ADDR_NONE, ADDR_UNSIGNED or ADDR_QUICKFIX")); + break; + } +} + +/// Parse command line and return information about the first command. +/// +/// @return Success or failure +bool parse_cmdline(char_u *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo) +{ + char *errormsg = NULL; + char *cmd; + char *p; + + // Initialize cmdinfo + memset(cmdinfo, 0, sizeof(*cmdinfo)); + + // Initialize eap + memset(eap, 0, sizeof(*eap)); + eap->line1 = 1; + eap->line2 = 1; + eap->cmd = (char *)cmdline; + eap->cmdlinep = &cmdline; + eap->getline = NULL; + eap->cookie = NULL; + + // Parse command modifiers + if (parse_command_modifiers(eap, &errormsg, false) == FAIL) { + return false; + } + // Revert the side-effects of `parse_command_modifiers` + if (eap->save_msg_silent != -1) { + cmdinfo->silent = !!msg_silent; + msg_silent = eap->save_msg_silent; + } + if (eap->did_esilent) { + cmdinfo->emsg_silent = true; + emsg_silent--; + } + if (eap->did_sandbox) { + cmdinfo->sandbox = true; + sandbox--; + } + if (cmdmod.save_ei != NULL) { + cmdinfo->noautocmd = true; + set_string_option_direct("ei", -1, cmdmod.save_ei, OPT_FREE, SID_NONE); + free_string_option(cmdmod.save_ei); + } + if (eap->verbose_save != -1) { + cmdinfo->verbose = p_verbose; + p_verbose = eap->verbose_save; + } + cmdinfo->cmdmod = cmdmod; + + // Save location after command modifiers + cmd = eap->cmd; + // Skip ranges to find command name since we need the command to know what kind of range it uses + eap->cmd = skip_range(eap->cmd, NULL); + if (*eap->cmd == '*') { + eap->cmd = (char *)skipwhite((char_u *)eap->cmd + 1); + } + p = find_command(eap, NULL); + + // Set command attribute type and parse command range + set_cmd_addr_type(eap, (char_u *)p); + eap->cmd = cmd; + if (parse_cmd_address(eap, &errormsg, false) == FAIL) { + return false; + } + + // Skip colon and whitespace + eap->cmd = skip_colon_white(eap->cmd, true); + // Fail if command is a comment or if command doesn't exist + if (*eap->cmd == NUL || *eap->cmd == '"') { + return false; + } + // Fail if command is invalid + if (eap->cmdidx == CMD_SIZE) { + return false; + } + + // Correctly set 'forceit' for commands + if (*p == '!' && eap->cmdidx != CMD_substitute + && eap->cmdidx != CMD_smagic && eap->cmdidx != CMD_snomagic) { + p++; + eap->forceit = true; + } else { + eap->forceit = false; + } + + // Parse arguments. + if (!IS_USER_CMDIDX(eap->cmdidx)) { + eap->argt = cmdnames[(int)eap->cmdidx].cmd_argt; + } + // Skip to start of argument. + // Don't do this for the ":!" command, because ":!! -l" needs the space. + if (eap->cmdidx == CMD_bang) { + eap->arg = (char_u *)p; + } else { + eap->arg = skipwhite((char_u *)p); + } + + // Don't treat ":r! filter" like a bang + if (eap->cmdidx == CMD_read) { + if (eap->forceit) { + eap->forceit = false; // :r! filter + } + } + + // Check for '|' to separate commands and '"' to start comments. + // Don't do this for ":read !cmd" and ":write !cmd". + if ((eap->argt & EX_TRLBAR)) { + separate_nextcmd(eap); + } + // Fail if command doesn't support bang but is used with a bang + if (!(eap->argt & EX_BANG) && eap->forceit) { + return false; + } + // Fail if command doesn't support a range but it is given a range + if (!(eap->argt & EX_RANGE) && eap->addr_count > 0) { + return false; + } + // Set default range for command if required + if ((eap->argt & EX_DFLALL) && eap->addr_count == 0) { + set_cmd_default_range(eap); + } + + // Remove leading whitespace and colon from next command + if (eap->nextcmd) { + eap->nextcmd = (char_u *)skip_colon_white((char *)eap->nextcmd, true); } - return (char_u *)p; + // Set the "magic" values (characters that get treated specially) + if (eap->argt & EX_XFILE) { + cmdinfo->magic.file = true; + } + if (eap->argt & EX_TRLBAR) { + cmdinfo->magic.bar = true; + } + + return true; } /// Execute one Ex command. @@ -1237,20 +1453,20 @@ static char_u *skip_colon_white(const char_u *p, bool skipleadingwhite) /// This function may be called recursively! /// /// @param cookie argument for fgetline() -static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGetter fgetline, - void *cookie) +static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter fgetline, + void *cookie) { - char_u *p; + char *p; linenr_T lnum; long n; char *errormsg = NULL; // error message - char_u *after_modifier = NULL; + char *after_modifier = NULL; exarg_T ea; const int save_msg_scroll = msg_scroll; cmdmod_T save_cmdmod; const int save_reg_executing = reg_executing; const bool save_pending_end_reg_executing = pending_end_reg_executing; - char_u *cmd; + char *cmd; memset(&ea, 0, sizeof(ea)); ea.line1 = 1; @@ -1283,7 +1499,7 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe // The "ea" structure holds the arguments that can be used. ea.cmd = *cmdlinep; - ea.cmdlinep = cmdlinep; + ea.cmdlinep = (char_u **)cmdlinep; ea.getline = fgetline; ea.cookie = cookie; ea.cstack = cstack; @@ -1306,7 +1522,7 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe cmd = ea.cmd; ea.cmd = skip_range(ea.cmd, NULL); if (*ea.cmd == '*') { - ea.cmd = skipwhite(ea.cmd + 1); + ea.cmd = (char *)skipwhite((char_u *)ea.cmd + 1); } p = find_command(&ea, NULL); @@ -1365,23 +1581,7 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe // The ea.cmd pointer is updated to point to the first character following the // range spec. If an initial address is found, but no second, the upper bound // is equal to the lower. - - // ea.addr_type for user commands is set by find_ucmd - if (!IS_USER_CMDIDX(ea.cmdidx)) { - if (ea.cmdidx != CMD_SIZE) { - ea.addr_type = cmdnames[(int)ea.cmdidx].cmd_addr_type; - } else { - ea.addr_type = ADDR_LINES; - } - // :wincmd range depends on the argument - if (ea.cmdidx == CMD_wincmd && p != NULL) { - get_wincmd_addr_type(skipwhite(p), &ea); - } - // :.cc in quickfix window uses line number - if ((ea.cmdidx == CMD_cc || ea.cmdidx == CMD_ll) && bt_quickfix(curbuf)) { - ea.addr_type = ADDR_OTHER; - } - } + set_cmd_addr_type(&ea, (char_u *)p); ea.cmd = cmd; if (parse_cmd_address(&ea, &errormsg, false) == FAIL) { @@ -1402,7 +1602,7 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe * If we find a '|' or '\n' we set ea.nextcmd. */ if (*ea.cmd == NUL || *ea.cmd == '"' - || (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL) { + || (ea.nextcmd = check_nextcmd((char_u *)ea.cmd)) != NULL) { // strange vi behaviour: // ":3" jumps to line 3 // ":3|..." prints line 3 @@ -1445,8 +1645,8 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe while (ASCII_ISALNUM(*p)) { ++p; } - p = vim_strnsave(ea.cmd, (size_t)(p - ea.cmd)); - int ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, true, NULL); + p = xstrnsave(ea.cmd, (size_t)(p - ea.cmd)); + int ret = apply_autocmds(EVENT_CMDUNDEFINED, (char_u *)p, (char_u *)p, true, NULL); xfree(p); // If the autocommands did something and didn't cause an error, try // finding the command again. @@ -1465,7 +1665,7 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe STRCPY(IObuff, _("E492: Not an editor command")); // If the modifier was parsed OK the error must be in the following // command - char_u *cmdname = after_modifier ? after_modifier : *cmdlinep; + char *cmdname = after_modifier ? after_modifier : *cmdlinep; if (!(flags & DOCMD_VERBOSE)) { append_command(cmdname); } @@ -1598,9 +1798,9 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe * Don't do this for the ":!" command, because ":!! -l" needs the space. */ if (ea.cmdidx == CMD_bang) { - ea.arg = p; + ea.arg = (char_u *)p; } else { - ea.arg = skipwhite(p); + ea.arg = skipwhite((char_u *)p); } // ":file" cannot be run with an argument when "curbuf->b_ro_locked" is set @@ -1647,9 +1847,9 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe if (ea.cmdidx == CMD_lshift || ea.cmdidx == CMD_rshift) { ea.amount = 1; - while (*ea.arg == *ea.cmd) { // count number of '>' or '<' - ++ea.arg; - ++ea.amount; + while (*ea.arg == (char_u)(*ea.cmd)) { // count number of '>' or '<' + ea.arg++; + ea.amount++; } ea.arg = skipwhite(ea.arg); } @@ -1659,7 +1859,7 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe * Don't do this for ":read !cmd" and ":write !cmd". */ if ((ea.argt & EX_CMDARG) && !ea.usefilter) { - ea.do_ecmd_cmd = getargcmd(&ea.arg); + ea.do_ecmd_cmd = (char_u *)getargcmd((char **)&ea.arg); } /* @@ -1676,7 +1876,7 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe // Check for <newline> to end a shell command. // Also do this for ":read !cmd", ":write !cmd" and ":global". // Any others? - for (p = ea.arg; *p; p++) { + for (p = (char *)ea.arg; *p; p++) { // Remove one backslash before a newline, so that it's possible to // pass a newline to the shell and also a newline that is preceded // with a backslash. This makes it impossible to end a shell @@ -1686,7 +1886,7 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe if (*p == '\\' && p[1] == '\n') { STRMOVE(p, p + 1); } else if (*p == '\n') { - ea.nextcmd = p + 1; + ea.nextcmd = (char_u *)p + 1; *p = NUL; break; } @@ -1694,59 +1894,7 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe } if ((ea.argt & EX_DFLALL) && ea.addr_count == 0) { - buf_T *buf; - - ea.line1 = 1; - switch (ea.addr_type) { - case ADDR_LINES: - case ADDR_OTHER: - ea.line2 = curbuf->b_ml.ml_line_count; - break; - case ADDR_LOADED_BUFFERS: - buf = firstbuf; - while (buf->b_next != NULL && buf->b_ml.ml_mfp == NULL) { - buf = buf->b_next; - } - ea.line1 = buf->b_fnum; - buf = lastbuf; - while (buf->b_prev != NULL && buf->b_ml.ml_mfp == NULL) { - buf = buf->b_prev; - } - ea.line2 = buf->b_fnum; - break; - case ADDR_BUFFERS: - ea.line1 = firstbuf->b_fnum; - ea.line2 = lastbuf->b_fnum; - break; - case ADDR_WINDOWS: - ea.line2 = LAST_WIN_NR; - break; - case ADDR_TABS: - ea.line2 = LAST_TAB_NR; - break; - case ADDR_TABS_RELATIVE: - ea.line2 = 1; - break; - case ADDR_ARGUMENTS: - if (ARGCOUNT == 0) { - ea.line1 = ea.line2 = 0; - } else { - ea.line2 = ARGCOUNT; - } - break; - case ADDR_QUICKFIX_VALID: - ea.line2 = (linenr_T)qf_get_valid_size(&ea); - if (ea.line2 == 0) { - ea.line2 = 1; - } - break; - case ADDR_NONE: - case ADDR_UNSIGNED: - case ADDR_QUICKFIX: - iemsg(_("INTERNAL: Cannot use EX_DFLALL " - "with ADDR_NONE, ADDR_UNSIGNED or ADDR_QUICKFIX")); - break; - } + set_cmd_default_range(&ea); } // accept numbered register only when no count allowed (:put) @@ -1774,7 +1922,7 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe // count, it's a buffer name. /// if ((ea.argt & EX_COUNT) && ascii_isdigit(*ea.arg) - && (!(ea.argt & EX_BUFNAME) || *(p = skipdigits(ea.arg + 1)) == NUL + && (!(ea.argt & EX_BUFNAME) || *(p = (char *)skipdigits(ea.arg + 1)) == NUL || ascii_iswhite(*p))) { n = getdigits_long(&ea.arg, false, -1); ea.arg = skipwhite(ea.arg); @@ -1915,7 +2063,7 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe } if (ea.argt & EX_XFILE) { - if (expand_filename(&ea, cmdlinep, &errormsg) == FAIL) { + if (expand_filename(&ea, (char_u **)cmdlinep, &errormsg) == FAIL) { goto doend; } } @@ -1933,20 +2081,20 @@ static char_u *do_one_cmd(char_u **cmdlinep, int flags, cstack_T *cstack, LineGe */ if (ea.cmdidx == CMD_bdelete || ea.cmdidx == CMD_bwipeout || ea.cmdidx == CMD_bunload) { - p = skiptowhite_esc(ea.arg); + p = (char *)skiptowhite_esc(ea.arg); } else { - p = ea.arg + STRLEN(ea.arg); - while (p > ea.arg && ascii_iswhite(p[-1])) { - --p; + p = (char *)ea.arg + STRLEN(ea.arg); + while ((char_u *)p > ea.arg && ascii_iswhite(p[-1])) { + p--; } } - ea.line2 = buflist_findpat(ea.arg, p, (ea.argt & EX_BUFUNL) != 0, + ea.line2 = buflist_findpat(ea.arg, (char_u *)p, (ea.argt & EX_BUFUNL) != 0, false, false); if (ea.line2 < 0) { // failed goto doend; } ea.addr_count = 1; - ea.arg = skipwhite(p); + ea.arg = skipwhite((char_u *)p); } // The :try command saves the emsg_silent flag, reset it here when @@ -2032,15 +2180,15 @@ doend: --ex_nesting_level; - return ea.nextcmd; -} + return (char *)ea.nextcmd; +} // NOLINT(readability/fn_size) static char ex_error_buf[MSG_BUF_LEN]; /// @return an error message with argument included. /// Uses a static buffer, only the last error will be kept. /// "msg" will be translated, caller should use N_(). -char *ex_errmsg(const char *const msg, const char_u *const arg) +char *ex_errmsg(const char *const msg, const char *const arg) FUNC_ATTR_NONNULL_ALL { vim_snprintf(ex_error_buf, MSG_BUF_LEN, _(msg), arg); @@ -2063,7 +2211,7 @@ char *ex_errmsg(const char *const msg, const char_u *const arg) /// @return FAIL when the command is not to be executed. int parse_command_modifiers(exarg_T *eap, char **errormsg, bool skip_only) { - char_u *p; + char *p; memset(&cmdmod, 0, sizeof(cmdmod)); eap->verbose_save = -1; @@ -2081,7 +2229,7 @@ int parse_command_modifiers(exarg_T *eap, char **errormsg, bool skip_only) if (*eap->cmd == NUL && exmode_active && getline_equal(eap->getline, eap->cookie, getexline) && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { - eap->cmd = (char_u *)"+"; + eap->cmd = "+"; if (!skip_only) { ex_pressedreturn = true; } @@ -2150,14 +2298,14 @@ int parse_command_modifiers(exarg_T *eap, char **errormsg, bool skip_only) continue; case 'f': { // only accept ":filter {pat} cmd" - char_u *reg_pat; + char *reg_pat; if (!checkforcmd(&p, "filter", 4) || *p == NUL || ends_excmd(*p)) { break; } if (*p == '!') { cmdmod.filter_force = true; - p = skipwhite(p + 1); + p = (char *)skipwhite((char_u *)p + 1); if (*p == NUL || ends_excmd(*p)) { break; } @@ -2172,7 +2320,7 @@ int parse_command_modifiers(exarg_T *eap, char **errormsg, bool skip_only) break; } if (!skip_only) { - cmdmod.filter_regmatch.regprog = vim_regcomp(reg_pat, RE_MAGIC); + cmdmod.filter_regmatch.regprog = vim_regcomp((char_u *)reg_pat, RE_MAGIC); if (cmdmod.filter_regmatch.regprog == NULL) { break; } @@ -2248,7 +2396,7 @@ int parse_command_modifiers(exarg_T *eap, char **errormsg, bool skip_only) } if (*eap->cmd == '!' && !ascii_iswhite(eap->cmd[-1])) { // ":silent!", but not "silent !cmd" - eap->cmd = skipwhite(eap->cmd + 1); + eap->cmd = (char *)skipwhite((char_u *)eap->cmd + 1); if (!skip_only) { emsg_silent++; eap->did_esilent++; @@ -2259,7 +2407,8 @@ int parse_command_modifiers(exarg_T *eap, char **errormsg, bool skip_only) case 't': if (checkforcmd(&p, "tab", 3)) { if (!skip_only) { - int tabnr = (int)get_address(eap, &eap->cmd, ADDR_TABS, eap->skip, skip_only, false, 1); + int tabnr = (int)get_address(eap, &eap->cmd, ADDR_TABS, eap->skip, skip_only, + false, 1); if (tabnr == MAXLNUM) { cmdmod.tab = tabpage_index(curtab) + 1; @@ -2305,7 +2454,7 @@ int parse_command_modifiers(exarg_T *eap, char **errormsg, bool skip_only) eap->verbose_save = p_verbose; } if (ascii_isdigit(*eap->cmd)) { - p_verbose = atoi((char *)eap->cmd); + p_verbose = atoi(eap->cmd); } else { p_verbose = 1; } @@ -2412,7 +2561,7 @@ int parse_cmd_address(exarg_T *eap, char **errormsg, bool silent) // Will give an error later if a range is found. break; } - eap->cmd = skipwhite(eap->cmd); + eap->cmd = (char *)skipwhite((char_u *)eap->cmd); lnum = get_address(eap, &eap->cmd, eap->addr_type, eap->skip, silent, eap->addr_count == 0, address_count++); if (eap->cmd == NULL) { // error detected @@ -2542,18 +2691,18 @@ int parse_cmd_address(exarg_T *eap, char **errormsg, bool silent) /// @param pp start of command /// @param cmd name of command /// @param len required length -int checkforcmd(char_u **pp, char *cmd, int len) +int checkforcmd(char **pp, char *cmd, int len) { int i; - for (i = 0; cmd[i] != NUL; ++i) { - if (((char_u *)cmd)[i] != (*pp)[i]) { + for (i = 0; cmd[i] != NUL; i++) { + if ((cmd)[i] != (*pp)[i]) { break; } } if (i >= len && !isalpha((*pp)[i])) { - *pp = skipwhite(*pp + i); - return TRUE; + *pp = (char *)skipwhite((char_u *)(*pp) + i); + return true; } return FALSE; } @@ -2561,20 +2710,20 @@ int checkforcmd(char_u **pp, char *cmd, int len) /// Append "cmd" to the error message in IObuff. /// Takes care of limiting the length and handling 0xa0, which would be /// invisible otherwise. -static void append_command(char_u *cmd) +static void append_command(char *cmd) { - char_u *s = cmd; - char_u *d; + char *s = cmd; + char *d; STRCAT(IObuff, ": "); - d = IObuff + STRLEN(IObuff); - while (*s != NUL && d - IObuff < IOSIZE - 7) { - if (s[0] == 0xc2 && s[1] == 0xa0) { + d = (char *)IObuff + STRLEN(IObuff); + while (*s != NUL && (char_u *)d - IObuff < IOSIZE - 7) { + if ((char_u)s[0] == 0xc2 && (char_u)s[1] == 0xa0) { s += 2; STRCPY(d, "<a0>"); d += 4; } else { - mb_copy_char((const char_u **)&s, &d); + mb_copy_char((const char_u **)&s, (char_u **)&d); } } *d = NUL; @@ -2586,11 +2735,11 @@ static void append_command(char_u *cmd) /// "full" is set to TRUE if the whole command name matched. /// /// @return NULL for an ambiguous user command. -static char_u *find_command(exarg_T *eap, int *full) +static char *find_command(exarg_T *eap, int *full) FUNC_ATTR_NONNULL_ARG(1) { int len; - char_u *p; + char *p; int i; /* @@ -2631,14 +2780,14 @@ static char_u *find_command(exarg_T *eap, int *full) // check for non-alpha command if (p == eap->cmd && vim_strchr((char_u *)"@!=><&~#", *p) != NULL) { - ++p; + p++; } len = (int)(p - eap->cmd); if (*eap->cmd == 'd' && (p[-1] == 'l' || p[-1] == 'p')) { // Check for ":dl", ":dell", etc. to ":deletel": that's // :delete with the 'l' flag. Same for 'p'. for (i = 0; i < len; i++) { - if (eap->cmd[i] != ((char_u *)"delete")[i]) { + if (eap->cmd[i] != ("delete")[i]) { break; } } @@ -2653,7 +2802,7 @@ static char_u *find_command(exarg_T *eap, int *full) } if (ASCII_ISLOWER(eap->cmd[0])) { - const int c1 = eap->cmd[0]; + const int c1 = (char_u)eap->cmd[0]; const int c2 = len == 1 ? NUL : eap->cmd[1]; if (command_count != CMD_SIZE) { @@ -2709,14 +2858,14 @@ static char_u *find_command(exarg_T *eap, int *full) /// @param full set to TRUE for a full match /// @param xp used for completion, NULL otherwise /// @param complp completion flags or NULL -static char_u *find_ucmd(exarg_T *eap, char_u *p, int *full, expand_T *xp, int *complp) +static char *find_ucmd(exarg_T *eap, char *p, int *full, expand_T *xp, int *complp) { int len = (int)(p - eap->cmd); int j, k, matchlen = 0; ucmd_T *uc; bool found = false; bool possible = false; - char_u *cp, *np; // Point into typed cmd and test name + char *cp, *np; // Point into typed cmd and test name garray_T *gap; bool amb_local = false; // Found ambiguous buffer-local command, // only full match global is accepted. @@ -2727,7 +2876,7 @@ static char_u *find_ucmd(exarg_T *eap, char_u *p, int *full, expand_T *xp, int * for (j = 0; j < gap->ga_len; j++) { uc = USER_CMD_GA(gap, j); cp = eap->cmd; - np = uc->uc_name; + np = (char *)uc->uc_name; k = 0; while (k < len && *np != NUL && *cp++ == *np++) { k++; @@ -2841,17 +2990,17 @@ static struct cmdmod { /// @return length of a command modifier (including optional count) or, /// zero when it's not a modifier. -int modifier_len(char_u *cmd) +int modifier_len(char *cmd) { - char_u *p = cmd; + char *p = cmd; if (ascii_isdigit(*cmd)) { - p = skipwhite(skipdigits(cmd + 1)); + p = (char *)skipwhite(skipdigits((char_u *)cmd + 1)); } for (int i = 0; i < (int)ARRAY_SIZE(cmdmods); i++) { int j; for (j = 0; p[j] != NUL; j++) { - if (p[j] != (char_u)cmdmods[i].name[j]) { + if (p[j] != cmdmods[i].name[j]) { break; } } @@ -2870,7 +3019,7 @@ int modifier_len(char_u *cmd) int cmd_exists(const char *const name) { exarg_T ea; - char_u *p; + char *p; // Check command modifiers. for (int i = 0; i < (int)ARRAY_SIZE(cmdmods); i++) { @@ -2887,7 +3036,7 @@ int cmd_exists(const char *const name) // Check built-in commands and user defined commands. // For ":2match" and ":3match" we need to skip the number. - ea.cmd = (char_u *)((*name == '2' || *name == '3') ? name + 1 : name); + ea.cmd = (char *)((*name == '2' || *name == '3') ? name + 1 : name); ea.cmdidx = (cmdidx_T)0; int full = false; p = find_command(&ea, &full); @@ -2897,7 +3046,7 @@ int cmd_exists(const char *const name) if (ascii_isdigit(*name) && ea.cmdidx != CMD_match) { return 0; } - if (*skipwhite(p) != NUL) { + if (*skipwhite((char_u *)p) != NUL) { return 0; // trailing garbage } return ea.cmdidx == CMD_SIZE ? 0 : (full ? 2 : 1); @@ -2907,7 +3056,7 @@ int cmd_exists(const char *const name) void f_fullcommand(typval_T *argvars, typval_T *rettv, FunPtr fptr) { exarg_T ea; - char_u *name = argvars[0].vval.v_string; + char *name = (char *)argvars[0].vval.v_string; rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; @@ -2922,13 +3071,13 @@ void f_fullcommand(typval_T *argvars, typval_T *rettv, FunPtr fptr) ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name; ea.cmdidx = (cmdidx_T)0; - char_u *p = find_command(&ea, NULL); + char *p = find_command(&ea, NULL); if (p == NULL || ea.cmdidx == CMD_SIZE) { return; } rettv->vval.v_string = vim_strsave(IS_USER_CMDIDX(ea.cmdidx) - ? get_user_command_name(ea.useridx, ea.cmdidx) + ? (char_u *)get_user_command_name(ea.useridx, ea.cmdidx) : cmdnames[ea.cmdidx].cmd_name); } @@ -2955,8 +3104,7 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff) // 2. skip comment lines and leading space, colons or bars const char *cmd; - for (cmd = buff; vim_strchr((const char_u *)" \t:|", *cmd) != NULL; cmd++) { - } + for (cmd = buff; vim_strchr((const char_u *)" \t:|", *cmd) != NULL; cmd++) {} xp->xp_pattern = (char_u *)cmd; if (*cmd == NUL) { @@ -2970,7 +3118,7 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff) /* * 3. parse a range specifier of the form: addr [,addr] [;addr] .. */ - cmd = (const char *)skip_range((const char_u *)cmd, &xp->xp_context); + cmd = (const char *)skip_range(cmd, &xp->xp_context); /* * 4. parse command @@ -3053,8 +3201,8 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff) ea.cmdidx = CMD_substitute; p = cmd + 1; } else if (cmd[0] >= 'A' && cmd[0] <= 'Z') { - ea.cmd = (char_u *)cmd; - p = (const char *)find_ucmd(&ea, (char_u *)p, NULL, xp, &context); + ea.cmd = (char *)cmd; + p = (const char *)find_ucmd(&ea, (char *)p, NULL, xp, &context); if (p == NULL) { ea.cmdidx = CMD_SIZE; // Ambiguous user command. } @@ -3122,7 +3270,7 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff) if ((ea.argt & EX_CMDARG) && !usefilter && *arg == '+') { // Check if we're in the +command p = arg + 1; - arg = (const char *)skip_cmd_arg((char_u *)arg, false); + arg = (const char *)skip_cmd_arg((char *)arg, false); // Still touching the command after '+'? if (*arg == NUL) { @@ -3268,8 +3416,7 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff) } // Check for user names. if (*xp->xp_pattern == '~') { - for (p = (const char *)xp->xp_pattern + 1; *p != NUL && *p != '/'; p++) { - } + for (p = (const char *)xp->xp_pattern + 1; *p != NUL && *p != '/'; p++) {} // Complete ~user only if it partially matches a user name. // A full match ~user<Tab> will be replaced by user's home // directory i.e. something like ~user<Tab> -> /home/user/ @@ -3345,7 +3492,7 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff) case CMD_filter: if (*arg != NUL) { - arg = (const char *)skip_vimgrep_pat((char_u *)arg, NULL, NULL); + arg = (const char *)skip_vimgrep_pat((char *)arg, NULL, NULL); } if (arg == NULL || *arg == NUL) { xp->xp_context = EXPAND_NOTHING; @@ -3822,7 +3969,7 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff) /// @param ctx pointer to xp_context or NULL /// /// @return the "cmd" pointer advanced to beyond the range. -char_u *skip_range(const char_u *cmd, int *ctx) +char *skip_range(const char *cmd, int *ctx) { unsigned delim; @@ -3838,8 +3985,8 @@ char_u *skip_range(const char_u *cmd, int *ctx) *ctx = EXPAND_NOTHING; } } else if (*cmd == '/' || *cmd == '?') { - delim = *cmd++; - while (*cmd != NUL && *cmd != delim) { + delim = (unsigned)(*cmd++); + while (*cmd != NUL && *cmd != (char)delim) { if (*cmd++ == '\\' && *cmd != NUL) { ++cmd; } @@ -3854,9 +4001,9 @@ char_u *skip_range(const char_u *cmd, int *ctx) } // Skip ":" and white space. - cmd = skip_colon_white(cmd, false); + cmd = skip_colon_white((char *)cmd, false); - return (char_u *)cmd; + return (char *)cmd; } static void addr_error(cmd_addr_T addr_type) @@ -3880,20 +4027,20 @@ static void addr_error(cmd_addr_T addr_type) /// @param address_count 1 for first, >1 after comma /// /// @return MAXLNUM when no Ex address was found. -static linenr_T get_address(exarg_T *eap, char_u **ptr, cmd_addr_T addr_type, int skip, bool silent, +static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int skip, bool silent, int to_other_file, int address_count) FUNC_ATTR_NONNULL_ALL { int c; int i; long n; - char_u *cmd; + char *cmd; pos_T pos; pos_T *fp; linenr_T lnum; buf_T *buf; - cmd = skipwhite(*ptr); + cmd = (char *)skipwhite((char_u *)(*ptr)); lnum = MAXLNUM; do { switch (*cmd) { @@ -4016,14 +4163,14 @@ static linenr_T get_address(exarg_T *eap, char_u **ptr, cmd_addr_T addr_type, in case '/': case '?': // '/' or '?' - search - c = *cmd++; + c = (char_u)(*cmd++); if (addr_type != ADDR_LINES) { addr_error(addr_type); cmd = NULL; goto error; } if (skip) { // skip "/pat/" - cmd = skip_regexp(cmd, c, p_magic, NULL); + cmd = (char *)skip_regexp((char_u *)cmd, c, p_magic, NULL); if (*cmd == c) { ++cmd; } @@ -4052,7 +4199,7 @@ static linenr_T get_address(exarg_T *eap, char_u **ptr, cmd_addr_T addr_type, in } searchcmdlen = 0; flags = silent ? 0 : SEARCH_HIS | SEARCH_MSG; - if (!do_search(NULL, c, c, cmd, 1L, flags, NULL)) { + if (!do_search(NULL, c, c, (char_u *)cmd, 1L, flags, NULL)) { curwin->w_cursor = pos; cmd = NULL; goto error; @@ -4101,12 +4248,12 @@ static linenr_T get_address(exarg_T *eap, char_u **ptr, cmd_addr_T addr_type, in default: if (ascii_isdigit(*cmd)) { // absolute line number - lnum = getdigits_long(&cmd, false, 0); + lnum = getdigits_long((char_u **)&cmd, false, 0); } } for (;;) { - cmd = skipwhite(cmd); + cmd = (char *)skipwhite((char_u *)cmd); if (*cmd != '-' && *cmd != '+' && !ascii_isdigit(*cmd)) { break; } @@ -4150,12 +4297,12 @@ static linenr_T get_address(exarg_T *eap, char_u **ptr, cmd_addr_T addr_type, in if (ascii_isdigit(*cmd)) { i = '+'; // "number" is same as "+number" } else { - i = *cmd++; + i = (char_u)(*cmd++); } if (!ascii_isdigit(*cmd)) { // '+' is '+1', but '+0' is not '+1' n = 1; } else { - n = getdigits(&cmd, false, MAXLNUM); + n = getdigits((char_u **)&cmd, false, MAXLNUM); if (n == MAXLNUM) { emsg(_(e_line_number_out_of_range)); goto error; @@ -4332,9 +4479,9 @@ static void correct_range(exarg_T *eap) /// For a ":vimgrep" or ":vimgrepadd" command return a pointer past the /// pattern. Otherwise return eap->arg. -static char_u *skip_grep_pat(exarg_T *eap) +static char *skip_grep_pat(exarg_T *eap) { - char_u *p = eap->arg; + char *p = (char *)eap->arg; if (*p != NUL && (eap->cmdidx == CMD_vimgrep || eap->cmdidx == CMD_lvimgrep || eap->cmdidx == CMD_vimgrepadd @@ -4342,7 +4489,7 @@ static char_u *skip_grep_pat(exarg_T *eap) || grep_internal(eap->cmdidx))) { p = skip_vimgrep_pat(p, NULL, NULL); if (p == NULL) { - p = eap->arg; + p = (char *)eap->arg; } } return p; @@ -4350,12 +4497,12 @@ static char_u *skip_grep_pat(exarg_T *eap) /// For the ":make" and ":grep" commands insert the 'makeprg'/'grepprg' option /// in the command line, so that things like % get expanded. -static char_u *replace_makeprg(exarg_T *eap, char_u *p, char_u **cmdlinep) +static char *replace_makeprg(exarg_T *eap, char *p, char **cmdlinep) { - char_u *new_cmdline; - char_u *program; - char_u *pos; - char_u *ptr; + char *new_cmdline; + char *program; + char *pos; + char *ptr; int len; size_t i; @@ -4370,30 +4517,30 @@ static char_u *replace_makeprg(exarg_T *eap, char_u *p, char_u **cmdlinep) if (eap->cmdidx == CMD_grep || eap->cmdidx == CMD_lgrep || eap->cmdidx == CMD_grepadd || eap->cmdidx == CMD_lgrepadd) { if (*curbuf->b_p_gp == NUL) { - program = p_gp; + program = (char *)p_gp; } else { - program = curbuf->b_p_gp; + program = (char *)curbuf->b_p_gp; } } else { if (*curbuf->b_p_mp == NUL) { - program = p_mp; + program = (char *)p_mp; } else { - program = curbuf->b_p_mp; + program = (char *)curbuf->b_p_mp; } } - p = skipwhite(p); + p = (char *)skipwhite((char_u *)p); - if ((pos = (char_u *)strstr((char *)program, "$*")) != NULL) { + if ((pos = strstr(program, "$*")) != NULL) { // replace $* by given arguments i = 1; - while ((pos = (char_u *)strstr((char *)pos + 2, "$*")) != NULL) { - ++i; + while ((pos = strstr(pos + 2, "$*")) != NULL) { + i++; } len = (int)STRLEN(p); new_cmdline = xmalloc(STRLEN(program) + i * (size_t)(len - 2) + 1); ptr = new_cmdline; - while ((pos = (char_u *)strstr((char *)program, "$*")) != NULL) { + while ((pos = strstr(program, "$*")) != NULL) { i = (size_t)(pos - program); memcpy(ptr, program, i); STRCPY(ptr += i, p); @@ -4407,7 +4554,7 @@ static char_u *replace_makeprg(exarg_T *eap, char_u *p, char_u **cmdlinep) STRCAT(new_cmdline, " "); STRCAT(new_cmdline, p); } - msg_make(p); + msg_make((char_u *)p); // 'eap->cmd' is not set here, because it is not used at CMD_make xfree(*cmdlinep); @@ -4424,9 +4571,9 @@ static char_u *replace_makeprg(exarg_T *eap, char_u *p, char_u **cmdlinep) int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp) { int has_wildcards; // need to expand wildcards - char_u *repl; + char *repl; size_t srclen; - char_u *p; + char *p; int escaped; // Skip a regexp pattern for ":vimgrep[add] pat file..." @@ -4437,12 +4584,12 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp) * the file name contains a wildcard it should not cause expanding. * (it will be expanded anyway if there is a wildcard before replacing). */ - has_wildcards = path_has_wildcard(p); + has_wildcards = path_has_wildcard((char_u *)p); while (*p != NUL) { // Skip over `=expr`, wildcards in it are not expanded. if (p[0] == '`' && p[1] == '=') { p += 2; - (void)skip_expr(&p); + (void)skip_expr((char_u **)&p); if (*p == '`') { ++p; } @@ -4460,8 +4607,8 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp) /* * Try to find a match at this position. */ - repl = eval_vars(p, eap->arg, &srclen, &(eap->do_ecmd_lnum), - errormsgp, &escaped); + repl = (char *)eval_vars((char_u *)p, eap->arg, &srclen, &(eap->do_ecmd_lnum), + errormsgp, &escaped); if (*errormsgp != NULL) { // error detected return FAIL; } @@ -4472,10 +4619,10 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp) // Wildcards won't be expanded below, the replacement is taken // literally. But do expand "~/file", "~user/file" and "$HOME/file". - if (vim_strchr(repl, '$') != NULL || vim_strchr(repl, '~') != NULL) { - char_u *l = repl; + if (vim_strchr((char_u *)repl, '$') != NULL || vim_strchr((char_u *)repl, '~') != NULL) { + char *l = repl; - repl = expand_env_save(repl); + repl = (char *)expand_env_save((char_u *)repl); xfree(l); } @@ -4495,11 +4642,11 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp) && eap->cmdidx != CMD_make && eap->cmdidx != CMD_terminal && !(eap->argt & EX_NOSPC)) { - char_u *l; + char *l; #ifdef BACKSLASH_IN_FILENAME // Don't escape a backslash here, because rem_backslash() doesn't // remove it later. - static char_u *nobslash = (char_u *)" \t\"|"; + static char *nobslash = " \t\"|"; # define ESCAPE_CHARS nobslash #else # define ESCAPE_CHARS escape_chars @@ -4507,7 +4654,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp) for (l = repl; *l; ++l) { if (vim_strchr(ESCAPE_CHARS, *l) != NULL) { - l = vim_strsave_escaped(repl, ESCAPE_CHARS); + l = (char *)vim_strsave_escaped((char_u *)repl, ESCAPE_CHARS); xfree(repl); repl = l; break; @@ -4519,15 +4666,15 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp) if ((eap->usefilter || eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal) - && strpbrk((char *)repl, "!") != NULL) { - char_u *l; + && strpbrk(repl, "!") != NULL) { + char *l; - l = vim_strsave_escaped(repl, (char_u *)"!"); + l = (char *)vim_strsave_escaped((char_u *)repl, (char_u *)"!"); xfree(repl); repl = l; } - p = repl_cmdline(eap, p, srclen, repl, cmdlinep); + p = repl_cmdline(eap, p, srclen, repl, (char **)cmdlinep); xfree(repl); } @@ -4549,12 +4696,12 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp) || vim_strchr(eap->arg, '~') != NULL) { expand_env_esc(eap->arg, NameBuff, MAXPATHL, true, true, NULL); has_wildcards = path_has_wildcard(NameBuff); - p = NameBuff; + p = (char *)NameBuff; } else { p = NULL; } if (p != NULL) { - (void)repl_cmdline(eap, eap->arg, STRLEN(eap->arg), p, cmdlinep); + (void)repl_cmdline(eap, (char *)eap->arg, STRLEN(eap->arg), p, (char **)cmdlinep); } } @@ -4577,11 +4724,11 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp) if (p_wic) { options += WILD_ICASE; } - p = ExpandOne(&xpc, eap->arg, NULL, options, WILD_EXPAND_FREE); + p = (char *)ExpandOne(&xpc, eap->arg, NULL, options, WILD_EXPAND_FREE); if (p == NULL) { return FAIL; } - (void)repl_cmdline(eap, eap->arg, STRLEN(eap->arg), p, cmdlinep); + (void)repl_cmdline(eap, (char *)eap->arg, STRLEN(eap->arg), p, (char **)cmdlinep); xfree(p); } } @@ -4594,8 +4741,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp) /// "repl" is the replacement string. /// /// @return a pointer to the character after the replaced string. -static char_u *repl_cmdline(exarg_T *eap, char_u *src, size_t srclen, char_u *repl, - char_u **cmdlinep) +static char *repl_cmdline(exarg_T *eap, char *src, size_t srclen, char *repl, char **cmdlinep) { /* * The new command line is build in new_cmdline[]. @@ -4607,7 +4753,7 @@ static char_u *repl_cmdline(exarg_T *eap, char_u *src, size_t srclen, char_u *re if (eap->nextcmd != NULL) { i += STRLEN(eap->nextcmd); // add space for next command } - char_u *new_cmdline = xmalloc(i); + char *new_cmdline = xmalloc(i); /* * Copy the stuff before the expanded part. @@ -4626,12 +4772,12 @@ static char_u *repl_cmdline(exarg_T *eap, char_u *src, size_t srclen, char_u *re if (eap->nextcmd != NULL) { // append next command i = STRLEN(new_cmdline) + 1; STRCPY(new_cmdline + i, eap->nextcmd); - eap->nextcmd = new_cmdline + i; + eap->nextcmd = (char_u *)new_cmdline + i; } eap->cmd = new_cmdline + (eap->cmd - *cmdlinep); - eap->arg = new_cmdline + (eap->arg - *cmdlinep); - if (eap->do_ecmd_cmd != NULL && eap->do_ecmd_cmd != dollar_command) { - eap->do_ecmd_cmd = new_cmdline + (eap->do_ecmd_cmd - *cmdlinep); + eap->arg = (char_u *)new_cmdline + ((char *)eap->arg - *cmdlinep); + if (eap->do_ecmd_cmd != NULL && eap->do_ecmd_cmd != (char_u *)dollar_command) { + eap->do_ecmd_cmd = (char_u *)new_cmdline + ((char *)eap->do_ecmd_cmd - *cmdlinep); } xfree(*cmdlinep); *cmdlinep = new_cmdline; @@ -4642,9 +4788,7 @@ static char_u *repl_cmdline(exarg_T *eap, char_u *src, size_t srclen, char_u *re /// Check for '|' to separate commands and '"' to start comments. void separate_nextcmd(exarg_T *eap) { - char_u *p; - - p = skip_grep_pat(eap); + char *p = skip_grep_pat(eap); for (; *p; MB_PTR_ADV(p)) { if (*p == Ctrl_V) { @@ -4660,7 +4804,7 @@ void separate_nextcmd(exarg_T *eap) } else if (p[0] == '`' && p[1] == '=' && (eap->argt & EX_XFILE)) { // Skip over `=expr` when wildcards are expanded. p += 2; - (void)skip_expr(&p); + (void)skip_expr((char_u **)&p); if (*p == NUL) { // stop at NUL after CTRL-V break; } @@ -4670,11 +4814,9 @@ void separate_nextcmd(exarg_T *eap) // :redir @" doesn't either. (*p == '"' && !(eap->argt & EX_NOTRLCOM) - && (eap->cmdidx != CMD_at || p != eap->arg) + && (eap->cmdidx != CMD_at || (char_u *)p != eap->arg) && (eap->cmdidx != CMD_redir - || p != eap->arg + 1 || p[-1] != '@')) - || *p == '|' - || *p == '\n') { + || (char_u *)p != eap->arg + 1 || p[-1] != '@')) || *p == '|' || *p == '\n') { // We remove the '\' before the '|', unless EX_CTRLV is used // AND 'b' is present in 'cpoptions'. if ((vim_strchr(p_cpo, CPO_BAR) == NULL @@ -4682,7 +4824,7 @@ void separate_nextcmd(exarg_T *eap) STRMOVE(p - 1, p); // remove the '\' p--; } else { - eap->nextcmd = check_nextcmd(p); + eap->nextcmd = check_nextcmd((char_u *)p); *p = NUL; break; } @@ -4695,15 +4837,15 @@ void separate_nextcmd(exarg_T *eap) } /// get + command from ex argument -static char_u *getargcmd(char_u **argp) +static char *getargcmd(char **argp) { - char_u *arg = *argp; - char_u *command = NULL; + char *arg = *argp; + char *command = NULL; if (*arg == '+') { // +[command] ++arg; if (ascii_isspace(*arg) || *arg == '\0') { - command = dollar_command; + command = (char *)dollar_command; } else { command = arg; arg = skip_cmd_arg(command, TRUE); @@ -4712,7 +4854,7 @@ static char_u *getargcmd(char_u **argp) } } - arg = skipwhite(arg); // skip over spaces + arg = (char *)skipwhite((char_u *)arg); // skip over spaces *argp = arg; } return command; @@ -4721,7 +4863,7 @@ static char_u *getargcmd(char_u **argp) /// Find end of "+command" argument. Skip over "\ " and "\\". /// /// @param rembs TRUE to halve the number of backslashes -static char_u *skip_cmd_arg(char_u *p, int rembs) +static char *skip_cmd_arg(char *p, int rembs) { while (*p && !ascii_isspace(*p)) { if (*p == '\\' && p[1] != NUL) { @@ -4756,10 +4898,10 @@ int get_bad_opt(const char_u *p, exarg_T *eap) /// @return FAIL or OK. static int getargopt(exarg_T *eap) { - char_u *arg = eap->arg + 2; + char *arg = (char *)eap->arg + 2; int *pp = NULL; int bad_char_idx; - char_u *p; + char *p; // ":edit ++[no]bin[ary] file" if (STRNCMP(arg, "bin", 3) == 0 || STRNCMP(arg, "nobin", 5) == 0) { @@ -4772,14 +4914,14 @@ static int getargopt(exarg_T *eap) if (!checkforcmd(&arg, "binary", 3)) { return FAIL; } - eap->arg = skipwhite(arg); + eap->arg = skipwhite((char_u *)arg); return OK; } // ":read ++edit file" if (STRNCMP(arg, "edit", 4) == 0) { - eap->read_edit = TRUE; - eap->arg = skipwhite(arg + 4); + eap->read_edit = true; + eap->arg = skipwhite((char_u *)arg + 4); return OK; } @@ -4805,26 +4947,26 @@ static int getargopt(exarg_T *eap) return FAIL; } - ++arg; + arg++; *pp = (int)(arg - eap->cmd); - arg = skip_cmd_arg(arg, FALSE); - eap->arg = skipwhite(arg); + arg = skip_cmd_arg(arg, false); + eap->arg = skipwhite((char_u *)arg); *arg = NUL; if (pp == &eap->force_ff) { - if (check_ff_value(eap->cmd + eap->force_ff) == FAIL) { + if (check_ff_value((char_u *)eap->cmd + eap->force_ff) == FAIL) { return FAIL; } - eap->force_ff = eap->cmd[eap->force_ff]; + eap->force_ff = (char_u)eap->cmd[eap->force_ff]; } else if (pp == &eap->force_enc) { // Make 'fileencoding' lower case. for (p = eap->cmd + eap->force_enc; *p != NUL; p++) { - *p = (char_u)TOLOWER_ASC(*p); + *p = (char)TOLOWER_ASC(*p); } } else { // Check ++bad= argument. Must be a single-byte character, "keep" or // "drop". - if (get_bad_opt(eap->cmd + bad_char_idx, eap) == FAIL) { + if (get_bad_opt((char_u *)eap->cmd + bad_char_idx, eap) == FAIL) { return FAIL; } } @@ -4842,8 +4984,8 @@ static int get_tabpage_arg(exarg_T *eap) int unaccept_arg0 = (eap->cmdidx == CMD_tabmove) ? 0 : 1; if (eap->arg && *eap->arg != NUL) { - char_u *p = eap->arg; - char_u *p_save; + char *p = (char *)eap->arg; + char *p_save; int relative = 0; // argument +N/-N means: go to N places to the // right/left relative to the current position. @@ -4856,7 +4998,7 @@ static int get_tabpage_arg(exarg_T *eap) } p_save = p; - tab_number = (int)getdigits(&p, false, tab_number); + tab_number = (int)getdigits((char_u **)&p, false, tab_number); if (relative == 0) { if (STRCMP(p, "$") == 0) { @@ -4865,7 +5007,7 @@ static int get_tabpage_arg(exarg_T *eap) if (valid_tabpage(lastused_tabpage)) { tab_number = tabpage_index(lastused_tabpage); } else { - eap->errmsg = ex_errmsg(e_invargval, eap->arg); + eap->errmsg = ex_errmsg(e_invargval, (char *)eap->arg); tab_number = 0; goto theend; } @@ -4939,7 +5081,7 @@ static void ex_map(exarg_T *eap) */ if (secure) { secure = 2; - msg_outtrans(eap->cmd); + msg_outtrans((char_u *)eap->cmd); msg_putchar('\n'); } do_exmap(eap, FALSE); @@ -4954,13 +5096,13 @@ static void ex_unmap(exarg_T *eap) /// ":mapclear" and friends. static void ex_mapclear(exarg_T *eap) { - map_clear_mode(eap->cmd, eap->arg, eap->forceit, false); + map_clear_mode((char_u *)eap->cmd, eap->arg, eap->forceit, false); } /// ":abclear" and friends. static void ex_abclear(exarg_T *eap) { - map_clear_mode(eap->cmd, eap->arg, true, true); + map_clear_mode((char_u *)eap->cmd, eap->arg, true, true); } static void ex_autocmd(exarg_T *eap) @@ -4980,11 +5122,11 @@ static void ex_autocmd(exarg_T *eap) /// ":doautocmd": Apply the automatic commands to the current buffer. static void ex_doautocmd(exarg_T *eap) { - char_u *arg = eap->arg; - int call_do_modelines = check_nomodeline(&arg); + char *arg = (char *)eap->arg; + int call_do_modelines = check_nomodeline((char_u **)&arg); bool did_aucmd; - (void)do_doautocmd(arg, false, &did_aucmd); + (void)do_doautocmd((char_u *)arg, false, &did_aucmd); // Only when there is no <nomodeline>. if (call_do_modelines && did_aucmd) { do_modelines(0); @@ -5098,10 +5240,10 @@ char_u *find_nextcmd(const char_u *p) /// @return NULL if it isn't, the following character if it is. char_u *check_nextcmd(char_u *p) { - char_u *s = skipwhite(p); + char *s = (char *)skipwhite(p); if (*s == '|' || *s == '\n') { - return (s + 1); + return (char_u *)(s + 1); } else { return NULL; } @@ -5123,12 +5265,12 @@ static int check_more(int message, bool forceit) && ARGCOUNT > 1 && !arg_had_last && n > 0 && quitmore == 0) { if (message) { if ((p_confirm || cmdmod.confirm) && curbuf->b_fname != NULL) { - char_u buff[DIALOG_MSG_SIZE]; + char buff[DIALOG_MSG_SIZE]; vim_snprintf((char *)buff, DIALOG_MSG_SIZE, NGETTEXT("%d more file to edit. Quit anyway?", "%d more files to edit. Quit anyway?", (unsigned long)n), n); - if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 1) == VIM_YES) { + if (vim_dialog_yesno(VIM_QUESTION, NULL, (char_u *)buff, 1) == VIM_YES) { return OK; } return FAIL; @@ -5146,7 +5288,7 @@ static int check_more(int message, bool forceit) char_u *get_command_name(expand_T *xp, int idx) { if (idx >= CMD_SIZE) { - return expand_user_command_name(idx); + return (char_u *)expand_user_command_name(idx); } return cmdnames[idx].cmd_name; } @@ -5169,22 +5311,21 @@ char *uc_validate_name(char *name) return name; } -int uc_add_command(char_u *name, size_t name_len, char_u *rep, uint32_t argt, long def, int flags, - int compl, char_u *compl_arg, LuaRef compl_luaref, cmd_addr_T addr_type, +int uc_add_command(char *name, size_t name_len, char *rep, uint32_t argt, long def, int flags, + int compl, char *compl_arg, LuaRef compl_luaref, cmd_addr_T addr_type, LuaRef luaref, bool force) FUNC_ATTR_NONNULL_ARG(1, 3) { ucmd_T *cmd = NULL; int i; int cmp = 1; - char_u *rep_buf = NULL; + char *rep_buf = NULL; garray_T *gap; - replace_termcodes(rep, STRLEN(rep), &rep_buf, false, false, true, - CPO_TO_CPO_FLAGS); + replace_termcodes((char_u *)rep, STRLEN(rep), (char_u **)&rep_buf, 0, NULL, CPO_TO_CPO_FLAGS); if (rep_buf == NULL) { // Can't replace termcodes - try using the string as is - rep_buf = vim_strsave(rep); + rep_buf = xstrdup(rep); } // get address of growarray: global or in curbuf @@ -5240,24 +5381,24 @@ int uc_add_command(char_u *name, size_t name_len, char_u *rep, uint32_t argt, lo if (cmp != 0) { ga_grow(gap, 1); - char_u *const p = vim_strnsave(name, name_len); + char *const p = xstrnsave(name, name_len); cmd = USER_CMD_GA(gap, i); memmove(cmd + 1, cmd, (size_t)(gap->ga_len - i) * sizeof(ucmd_T)); ++gap->ga_len; - cmd->uc_name = p; + cmd->uc_name = (char_u *)p; } - cmd->uc_rep = rep_buf; + cmd->uc_rep = (char_u *)rep_buf; cmd->uc_argt = argt; cmd->uc_def = def; cmd->uc_compl = compl; cmd->uc_script_ctx = current_sctx; cmd->uc_script_ctx.sc_lnum += sourcing_lnum; nlua_set_sctx(&cmd->uc_script_ctx); - cmd->uc_compl_arg = compl_arg; + cmd->uc_compl_arg = (char_u *)compl_arg; cmd->uc_compl_luaref = compl_luaref; cmd->uc_addr_type = addr_type; cmd->uc_luaref = luaref; @@ -5349,7 +5490,7 @@ static char *get_command_complete(int arg) } } -static void uc_list(char_u *name, size_t name_len) +static void uc_list(char *name, size_t name_len) { int i, j; bool found = false; @@ -5511,11 +5652,11 @@ static void uc_list(char_u *name, size_t name_len) } } -static int uc_scan_attr(char_u *attr, size_t len, uint32_t *argt, long *def, int *flags, - int *complp, char_u **compl_arg, cmd_addr_T *addr_type_arg) +static int uc_scan_attr(char *attr, size_t len, uint32_t *argt, long *def, int *flags, int *complp, + char_u **compl_arg, cmd_addr_T *addr_type_arg) FUNC_ATTR_NONNULL_ALL { - char_u *p; + char *p; if (len == 0) { emsg(_("E175: No attribute specified")); @@ -5535,7 +5676,7 @@ static int uc_scan_attr(char_u *attr, size_t len, uint32_t *argt, long *def, int *argt |= EX_TRLBAR; } else { int i; - char_u *val = NULL; + char *val = NULL; size_t vallen = 0; size_t attrlen = len; @@ -5581,7 +5722,7 @@ two_count: return FAIL; } - *def = getdigits_long(&p, true, 0); + *def = getdigits_long((char_u **)&p, true, 0); *argt |= EX_ZEROR; if (p != val + vallen || vallen == 0) { @@ -5607,7 +5748,7 @@ invalid_count: goto two_count; } - *def = getdigits_long(&p, true, 0); + *def = getdigits_long((char_u **)&p, true, 0); if (p != val + vallen) { goto invalid_count; @@ -5623,7 +5764,7 @@ invalid_count: return FAIL; } - if (parse_compl_arg(val, (int)vallen, complp, argt, compl_arg) + if (parse_compl_arg(val, (int)vallen, complp, argt, (char **)compl_arg) == FAIL) { return FAIL; } @@ -5640,7 +5781,7 @@ invalid_count: *argt |= EX_ZEROR; } } else { - char_u ch = attr[len]; + char ch = attr[len]; attr[len] = '\0'; semsg(_("E181: Invalid attribute: %s"), attr); attr[len] = ch; @@ -5656,34 +5797,34 @@ static char e_complete_used_without_nargs[] = N_("E1208: -complete used without /// ":command ..." static void ex_command(exarg_T *eap) { - char_u *name; - char_u *end; - char_u *p; + char *name; + char *end; + char *p; uint32_t argt = 0; long def = -1; int flags = 0; int compl = EXPAND_NOTHING; - char_u *compl_arg = NULL; + char *compl_arg = NULL; cmd_addr_T addr_type_arg = ADDR_NONE; int has_attr = (eap->arg[0] == '-'); size_t name_len; - p = eap->arg; + p = (char *)eap->arg; // Check for attributes while (*p == '-') { - ++p; - end = skiptowhite(p); - if (uc_scan_attr(p, (size_t)(end - p), &argt, &def, &flags, &compl, &compl_arg, + p++; + end = (char *)skiptowhite((char_u *)p); + if (uc_scan_attr(p, (size_t)(end - p), &argt, &def, &flags, &compl, (char_u **)&compl_arg, &addr_type_arg) == FAIL) { return; } - p = skipwhite(end); + p = (char *)skipwhite((char_u *)end); } // Get the name (if any) and skip to the following argument. name = p; - end = (char_u *)uc_validate_name((char *)name); + end = uc_validate_name(name); if (!end) { emsg(_("E182: Invalid command name")); return; @@ -5692,7 +5833,7 @@ static void ex_command(exarg_T *eap) // If there is nothing after the name, and no attributes were specified, // we are listing commands - p = skipwhite(end); + p = (char *)skipwhite((char_u *)end); if (!has_attr && ends_excmd(*p)) { uc_list(name, name_len); } else if (!ASCII_ISUPPER(*name)) { @@ -5702,7 +5843,8 @@ static void ex_command(exarg_T *eap) } else if (compl > 0 && (argt & EX_EXTRA) == 0) { emsg(_(e_complete_used_without_nargs)); } else { - uc_add_command(name, name_len, p, argt, def, flags, compl, compl_arg, LUA_NOREF, + uc_add_command(name, name_len, p, argt, def, flags, compl, + compl_arg, LUA_NOREF, addr_type_arg, LUA_NOREF, eap->forceit); } } @@ -5736,12 +5878,12 @@ static void ex_delcommand(exarg_T *eap) ucmd_T *cmd = NULL; int res = -1; garray_T *gap; - const char_u *arg = eap->arg; + const char *arg = (char *)eap->arg; bool buffer_only = false; if (STRNCMP(arg, "-buffer", 7) == 0 && ascii_iswhite(arg[7])) { buffer_only = true; - arg = skipwhite(arg + 7); + arg = (char *)skipwhite((char_u *)arg + 7); } gap = &curbuf->b_ucmds; @@ -5820,11 +5962,11 @@ bool uc_split_args_iter(const char_u *arg, size_t arglen, size_t *end, char *buf } /// split and quote args for <f-args> -static char_u *uc_split_args(char_u *arg, size_t *lenp) +static char *uc_split_args(char *arg, size_t *lenp) { - char_u *buf; - char_u *p; - char_u *q; + char *buf; + char *p; + char *q; int len; // Precalculate length @@ -5842,13 +5984,13 @@ static char_u *uc_split_args(char_u *arg, size_t *lenp) len += 2; p += 1; } else if (ascii_iswhite(*p)) { - p = skipwhite(p); + p = (char *)skipwhite((char_u *)p); if (*p == NUL) { break; } len += 3; // "," } else { - const int charlen = utfc_ptr2len(p); + const int charlen = utfc_ptr2len((char_u *)p); len += charlen; p += charlen; @@ -5872,7 +6014,7 @@ static char_u *uc_split_args(char_u *arg, size_t *lenp) *q++ = '\\'; *q++ = *p++; } else if (ascii_iswhite(*p)) { - p = skipwhite(p); + p = (char *)skipwhite((char_u *)p); if (*p == NUL) { break; } @@ -5880,7 +6022,7 @@ static char_u *uc_split_args(char_u *arg, size_t *lenp) *q++ = ','; *q++ = '"'; } else { - mb_copy_char((const char_u **)&p, &q); + mb_copy_char((const char_u **)&p, (char_u **)&q); } } *q++ = '"'; @@ -5919,11 +6061,11 @@ static size_t add_cmd_modifier(char *buf, char *mod_str, bool *multi_mods) /// /// @return the length of the replacement, which has been added to "buf". /// Return -1 if there was no match, and only the "<" has been copied. -static size_t uc_check_code(char_u *code, size_t len, char_u *buf, ucmd_T *cmd, exarg_T *eap, - char_u **split_buf, size_t *split_len) +static size_t uc_check_code(char *code, size_t len, char *buf, ucmd_T *cmd, exarg_T *eap, + char **split_buf, size_t *split_len) { size_t result = 0; - char_u *p = code + 1; + char *p = code + 1; size_t l = len - 2; int quote = 0; enum { @@ -5998,7 +6140,7 @@ static size_t uc_check_code(char_u *code, size_t len, char_u *buf, ucmd_T *cmd, break; case 1: // Quote, but don't split result = STRLEN(eap->arg) + 2; - for (p = eap->arg; *p; p++) { + for (p = (char *)eap->arg; *p; p++) { if (*p == '\\' || *p == '"') { result++; } @@ -6006,7 +6148,7 @@ static size_t uc_check_code(char_u *code, size_t len, char_u *buf, ucmd_T *cmd, if (buf != NULL) { *buf++ = '"'; - for (p = eap->arg; *p; p++) { + for (p = (char *)eap->arg; *p; p++) { if (*p == '\\' || *p == '"') { *buf++ = '\\'; } @@ -6019,7 +6161,7 @@ static size_t uc_check_code(char_u *code, size_t len, char_u *buf, ucmd_T *cmd, case 2: // Quote and split (<f-args>) // This is hard, so only do it once, and cache the result if (*split_buf == NULL) { - *split_buf = uc_split_args(eap->arg, split_len); + *split_buf = uc_split_args((char *)eap->arg, split_len); } result = *split_len; @@ -6091,7 +6233,7 @@ static size_t uc_check_code(char_u *code, size_t len, char_u *buf, ucmd_T *cmd, *buf = '\0'; } - result += uc_mods((char *)buf); + result += uc_mods(buf); if (quote && buf != NULL) { buf += result - 2; @@ -6109,7 +6251,7 @@ static size_t uc_check_code(char_u *code, size_t len, char_u *buf, ucmd_T *cmd, *buf++ = '\''; } if (eap->regname) { - *buf++ = (char_u)eap->regname; + *buf++ = (char)eap->regname; } if (quote) { *buf = '\''; @@ -6208,17 +6350,17 @@ size_t uc_mods(char *buf) static void do_ucmd(exarg_T *eap) { - char_u *buf; - char_u *p; - char_u *q; + char *buf; + char *p; + char *q; - char_u *start; - char_u *end = NULL; - char_u *ksp; + char *start; + char *end = NULL; + char *ksp; size_t len, totlen; size_t split_len = 0; - char_u *split_buf = NULL; + char *split_buf = NULL; ucmd_T *cmd; if (eap->cmdidx == CMD_USER) { @@ -6239,21 +6381,20 @@ static void do_ucmd(exarg_T *eap) */ buf = NULL; for (;;) { - p = cmd->uc_rep; // source + p = (char *)cmd->uc_rep; // source q = buf; // destination totlen = 0; for (;;) { - start = vim_strchr(p, '<'); + start = (char *)vim_strchr((char_u *)p, '<'); if (start != NULL) { - end = vim_strchr(start + 1, '>'); + end = (char *)vim_strchr((char_u *)start + 1, '>'); } if (buf != NULL) { - for (ksp = p; *ksp != NUL && *ksp != K_SPECIAL; ksp++) { - } - if (*ksp == K_SPECIAL + for (ksp = p; *ksp != NUL && (char_u)(*ksp) != K_SPECIAL; ksp++) {} + if ((char_u)(*ksp) == K_SPECIAL && (start == NULL || ksp < start || end == NULL) - && (ksp[1] == KS_SPECIAL && ksp[2] == KE_FILLER)) { + && ((char_u)ksp[1] == KS_SPECIAL && ksp[2] == KE_FILLER)) { // K_SPECIAL has been put in the buffer as K_SPECIAL // KS_SPECIAL KE_FILLER, like for mappings, but // do_cmdline() doesn't handle that, so convert it back. @@ -6262,7 +6403,7 @@ static void do_ucmd(exarg_T *eap) memmove(q, p, len); q += len; } - *q++ = K_SPECIAL; + *q++ = (char)K_SPECIAL; p = ksp + 3; continue; } @@ -6285,8 +6426,7 @@ static void do_ucmd(exarg_T *eap) q += len; } - len = uc_check_code(start, (size_t)(end - start), q, cmd, eap, - &split_buf, &split_len); + len = uc_check_code(start, (size_t)(end - start), q, cmd, eap, &split_buf, &split_len); if (len == (size_t)-1) { // no match, continue after '<' p = start + 1; @@ -6328,9 +6468,9 @@ static void do_ucmd(exarg_T *eap) xfree(split_buf); } -static char_u *expand_user_command_name(int idx) +static char *expand_user_command_name(int idx) { - return get_user_commands(NULL, idx - CMD_SIZE); + return (char *)get_user_commands(NULL, idx - CMD_SIZE); } /// Function given to ExpandGeneric() to obtain the list of user address type names. @@ -6360,17 +6500,17 @@ char_u *get_user_commands(expand_T *xp FUNC_ATTR_UNUSED, int idx) /// CMD_USER_BUF. /// /// @return NULL if the command is not found. -static char_u *get_user_command_name(int idx, int cmdidx) +static char *get_user_command_name(int idx, int cmdidx) { if (cmdidx == CMD_USER && idx < ucmds.ga_len) { - return USER_CMD(idx)->uc_name; + return (char *)USER_CMD(idx)->uc_name; } if (cmdidx == CMD_USER_BUF) { // In cmdwin, the alternative buffer should be used. const buf_T *const buf = prevwin_curwin()->w_buffer; if (idx < buf->b_ucmds.ga_len) { - return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name; + return (char *)USER_CMD_GA(&buf->b_ucmds, idx)->uc_name; } } return NULL; @@ -6416,7 +6556,7 @@ char_u *get_user_cmd_complete(expand_T *xp, int idx) } /// Parse address type argument -int parse_addr_type_arg(char_u *value, int vallen, cmd_addr_T *addr_type_arg) +int parse_addr_type_arg(char *value, int vallen, cmd_addr_T *addr_type_arg) FUNC_ATTR_NONNULL_ALL { int i, a, b; @@ -6431,7 +6571,7 @@ int parse_addr_type_arg(char_u *value, int vallen, cmd_addr_T *addr_type_arg) } if (addr_type_complete[i].expand == ADDR_NONE) { - char_u *err = value; + char *err = value; for (i = 0; err[i] != NUL && !ascii_iswhite(err[i]); i++) {} err[i] = NUL; @@ -6448,11 +6588,10 @@ int parse_addr_type_arg(char_u *value, int vallen, cmd_addr_T *addr_type_arg) /// copied to allocated memory and stored in "*compl_arg". /// /// @return FAIL if something is wrong. -int parse_compl_arg(const char_u *value, int vallen, int *complp, uint32_t *argt, - char_u **compl_arg) +int parse_compl_arg(const char *value, int vallen, int *complp, uint32_t *argt, char **compl_arg) FUNC_ATTR_NONNULL_ALL { - const char_u *arg = NULL; + const char *arg = NULL; size_t arglen = 0; int i; int valend = vallen; @@ -6460,7 +6599,7 @@ int parse_compl_arg(const char_u *value, int vallen, int *complp, uint32_t *argt // Look for any argument part - which is the part after any ',' for (i = 0; i < vallen; ++i) { if (value[i] == ',') { - arg = &value[i + 1]; + arg = (char *)&value[i + 1]; arglen = (size_t)(vallen - i - 1); valend = i; break; @@ -6501,7 +6640,7 @@ int parse_compl_arg(const char_u *value, int vallen, int *complp, uint32_t *argt } if (arg != NULL) { - *compl_arg = vim_strnsave(arg, arglen); + *compl_arg = xstrnsave(arg, arglen); } return OK; } @@ -6524,16 +6663,16 @@ int cmdcomplete_str_to_type(const char *complete_str) static void ex_colorscheme(exarg_T *eap) { if (*eap->arg == NUL) { - char_u *expr = vim_strsave((char_u *)"g:colors_name"); - char_u *p = NULL; + char *expr = xstrdup("g:colors_name"); + char *p = NULL; emsg_off++; - p = eval_to_string(expr, NULL, false); + p = (char *)eval_to_string((char_u *)expr, NULL, false); emsg_off--; xfree(expr); if (p != NULL) { - msg((char *)p); + msg(p); xfree(p); } else { msg("default"); @@ -6854,7 +6993,7 @@ void tabpage_close_other(tabpage_T *tp, int forceit) int done = 0; win_T *wp; int h = tabline_height(); - char_u prev_idx[NUMBUFLEN]; + char prev_idx[NUMBUFLEN]; // Limit to 1000 windows, autocommands may add a window while we close // one. OK, so I'm paranoid... @@ -7063,11 +7202,11 @@ void alist_new(void) /// numbers to be re-used. void alist_expand(int *fnum_list, int fnum_len) { - char_u **old_arg_files; + char **old_arg_files; int old_arg_count; - char_u **new_arg_files; + char **new_arg_files; int new_arg_file_count; - char_u *save_p_su = p_su; + char *save_p_su = p_su; int i; /* Don't use 'suffixes' here. This should work like the shell did the @@ -7093,7 +7232,7 @@ void alist_expand(int *fnum_list, int fnum_len) /// Set the argument list for the current window. /// Takes over the allocated files[] and the allocated fnames in it. -void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum_list, int fnum_len) +void alist_set(alist_T *al, int count, char **files, int use_curbuf, int *fnum_list, int fnum_len) { int i; static int recursive = 0; @@ -7120,7 +7259,7 @@ void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum /* May set buffer name of a buffer previously used for the * argument list, so that it's re-used by alist_add. */ if (fnum_list != NULL && i < fnum_len) { - buf_set_name(fnum_list[i], files[i]); + buf_set_name(fnum_list[i], (char_u *)files[i]); } alist_add(al, files[i], use_curbuf ? 2 : 1); @@ -7139,7 +7278,7 @@ void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum /// "fname" must have been allocated and "al" must have been checked for room. /// /// @param set_fnum 1: set buffer number; 2: re-use curbuf -void alist_add(alist_T *al, char_u *fname, int set_fnum) +void alist_add(alist_T *al, char *fname, int set_fnum) { if (fname == NULL) { // don't add NULL file names return; @@ -7147,10 +7286,10 @@ void alist_add(alist_T *al, char_u *fname, int set_fnum) #ifdef BACKSLASH_IN_FILENAME slash_adjust(fname); #endif - AARGLIST(al)[al->al_ga.ga_len].ae_fname = fname; + AARGLIST(al)[al->al_ga.ga_len].ae_fname = (char_u *)fname; if (set_fnum > 0) { AARGLIST(al)[al->al_ga.ga_len].ae_fnum = - buflist_add(fname, BLN_LISTED | (set_fnum == 2 ? BLN_CURBUF : 0)); + buflist_add((char_u *)fname, BLN_LISTED | (set_fnum == 2 ? BLN_CURBUF : 0)); } ++al->al_ga.ga_len; } @@ -7222,7 +7361,7 @@ static void ex_wrongmodifier(exarg_T *eap) void ex_splitview(exarg_T *eap) { win_T *old_curwin = curwin; - char_u *fname = NULL; + char *fname = NULL; const bool use_tab = eap->cmdidx == CMD_tabedit || eap->cmdidx == CMD_tabfind || eap->cmdidx == CMD_tabnew; @@ -7239,12 +7378,12 @@ void ex_splitview(exarg_T *eap) } if (eap->cmdidx == CMD_sfind || eap->cmdidx == CMD_tabfind) { - fname = find_file_in_path(eap->arg, STRLEN(eap->arg), - FNAME_MESS, TRUE, curbuf->b_ffname); + fname = (char *)find_file_in_path(eap->arg, STRLEN(eap->arg), + FNAME_MESS, true, curbuf->b_ffname); if (fname == NULL) { goto theend; } - eap->arg = fname; + eap->arg = (char_u *)fname; } /* @@ -7288,7 +7427,7 @@ void tabpage_new(void) memset(&ea, 0, sizeof(ea)); ea.cmdidx = CMD_tabnew; - ea.cmd = (char_u *)"tabn"; + ea.cmd = "tabn"; ea.arg = (char_u *)""; ex_splitview(&ea); } @@ -7309,9 +7448,9 @@ static void ex_tabnext(exarg_T *eap) case CMD_tabprevious: case CMD_tabNext: if (eap->arg && *eap->arg != NUL) { - char_u *p = eap->arg; - char_u *p_save = p; - tab_number = (int)getdigits(&p, false, 0); + char *p = (char *)eap->arg; + char *p_save = p; + tab_number = (int)getdigits((char_u **)&p, false, 0); if (p == p_save || *p_save == '-' || *p_save == '+' || *p != NUL || tab_number == 0) { // No numbers as argument. @@ -7416,8 +7555,7 @@ static void ex_resize(exarg_T *eap) if (eap->addr_count > 0) { n = (int)eap->line2; - for (wp = firstwin; wp->w_next != NULL && --n > 0; wp = wp->w_next) { - } + for (wp = firstwin; wp->w_next != NULL && --n > 0; wp = wp->w_next) {} } n = (int)atol((char *)eap->arg); @@ -7432,7 +7570,7 @@ static void ex_resize(exarg_T *eap) if (*eap->arg == '-' || *eap->arg == '+') { n += wp->w_height; } else if (n == 0 && eap->arg[0] == NUL) { // default is very high - n = Rows-1; + n = Rows - 1; } win_setheight_win(n, wp); } @@ -7441,23 +7579,23 @@ static void ex_resize(exarg_T *eap) /// ":find [+command] <file>" command. static void ex_find(exarg_T *eap) { - char_u *fname; + char *fname; linenr_T count; - fname = find_file_in_path(eap->arg, STRLEN(eap->arg), - FNAME_MESS, TRUE, curbuf->b_ffname); + fname = (char *)find_file_in_path(eap->arg, STRLEN(eap->arg), + FNAME_MESS, true, curbuf->b_ffname); if (eap->addr_count > 0) { // Repeat finding the file "count" times. This matters when it // appears several times in the path. count = eap->line2; while (fname != NULL && --count > 0) { xfree(fname); - fname = find_file_in_path(NULL, 0, FNAME_MESS, FALSE, curbuf->b_ffname); + fname = (char *)find_file_in_path(NULL, 0, FNAME_MESS, false, curbuf->b_ffname); } } if (fname != NULL) { - eap->arg = fname; + eap->arg = (char_u *)fname; do_exedit(eap, NULL); xfree(fname); } @@ -7538,7 +7676,7 @@ void do_exedit(exarg_T *eap, win_T *old_curwin) if (eap->cmdidx != CMD_balt && eap->cmdidx != CMD_badd) { setpcmark(); } - if (do_ecmd(0, (eap->cmdidx == CMD_enew ? NULL : eap->arg), + if (do_ecmd(0, eap->cmdidx == CMD_enew ? NULL : (char *)eap->arg, NULL, eap, eap->do_ecmd_lnum, (buf_hide(curbuf) ? ECMD_HIDE : 0) + (eap->forceit ? ECMD_FORCEIT : 0) @@ -7674,11 +7812,11 @@ static void ex_syncbind(exarg_T *eap) did_syncbind = true; checkpcmark(); if (old_linenr != curwin->w_cursor.lnum) { - char_u ctrl_o[2]; + char ctrl_o[2]; ctrl_o[0] = Ctrl_O; ctrl_o[1] = 0; - ins_typebuf(ctrl_o, REMAP_NONE, 0, true, false); + ins_typebuf((char_u *)ctrl_o, REMAP_NONE, 0, true, false); } } } @@ -7737,7 +7875,7 @@ static void ex_read(exarg_T *eap) } } -static char_u *prev_dir = NULL; +static char *prev_dir = NULL; #if defined(EXITFREE) void free_cd_dir(void) @@ -7749,14 +7887,14 @@ void free_cd_dir(void) #endif /// Get the previous directory for the given chdir scope. -static char_u *get_prevdir(CdScope scope) +static char *get_prevdir(CdScope scope) { switch (scope) { case kCdScopeTabpage: - return curtab->tp_prevdir; + return (char *)curtab->tp_prevdir; break; case kCdScopeWindow: - return curwin->w_prevdir; + return (char *)curwin->w_prevdir; break; default: return prev_dir; @@ -7777,10 +7915,10 @@ static void post_chdir(CdScope scope, bool trigger_dirchanged) } if (scope < kCdScopeGlobal) { - char_u *pdir = get_prevdir(scope); + char *pdir = get_prevdir(scope); // If still in global directory, set CWD as the global directory. if (globaldir == NULL && pdir != NULL) { - globaldir = vim_strsave(pdir); + globaldir = vim_strsave((char_u *)pdir); } } @@ -7815,13 +7953,13 @@ static void post_chdir(CdScope scope, bool trigger_dirchanged) /// @param new_dir The directory to change to. /// @param scope Scope of the function call (global, tab or window). /// @return true if the directory is successfully changed. -bool changedir_func(char_u *new_dir, CdScope scope) +bool changedir_func(char *new_dir, CdScope scope) { if (new_dir == NULL || allbuf_locked()) { return false; } - char_u *pdir = NULL; + char *pdir = NULL; // ":cd -": Change to previous directory if (STRCMP(new_dir, "-") == 0) { pdir = get_prevdir(scope); @@ -7833,7 +7971,7 @@ bool changedir_func(char_u *new_dir, CdScope scope) } if (os_dirname(NameBuff, MAXPATHL) == OK) { - pdir = vim_strsave(NameBuff); + pdir = (char *)vim_strsave(NameBuff); } else { pdir = NULL; } @@ -7847,26 +7985,26 @@ bool changedir_func(char_u *new_dir, CdScope scope) #endif // Use NameBuff for home directory name. expand_env((char_u *)"$HOME", NameBuff, MAXPATHL); - new_dir = NameBuff; + new_dir = (char *)NameBuff; } - bool dir_differs = pdir == NULL || pathcmp((char *)pdir, (char *)new_dir, -1) != 0; + bool dir_differs = pdir == NULL || pathcmp(pdir, new_dir, -1) != 0; if (dir_differs) { - do_autocmd_dirchanged((char *)new_dir, scope, kCdCauseManual, true); - if (vim_chdir(new_dir) != 0) { + do_autocmd_dirchanged(new_dir, scope, kCdCauseManual, true); + if (vim_chdir((char_u *)new_dir) != 0) { emsg(_(e_failed)); xfree(pdir); return false; } } - char_u **pp; + char **pp; switch (scope) { case kCdScopeTabpage: - pp = &curtab->tp_prevdir; + pp = (char **)&curtab->tp_prevdir; break; case kCdScopeWindow: - pp = &curwin->w_prevdir; + pp = (char **)&curwin->w_prevdir; break; default: pp = &prev_dir; @@ -7882,8 +8020,7 @@ bool changedir_func(char_u *new_dir, CdScope scope) /// ":cd", ":tcd", ":lcd", ":chdir", "tchdir" and ":lchdir". void ex_cd(exarg_T *eap) { - char_u *new_dir; - new_dir = eap->arg; + char *new_dir = (char *)eap->arg; #if !defined(UNIX) // for non-UNIX ":cd" means: print current directory unless 'cdhome' is set if (*new_dir == NUL && !p_cdh) { @@ -7989,10 +8126,8 @@ void do_sleep(long msec) static void do_exmap(exarg_T *eap, int isabbrev) { int mode; - char_u *cmdp; - - cmdp = eap->cmd; - mode = get_map_mode(&cmdp, eap->forceit || isabbrev); + char *cmdp = eap->cmd; + mode = get_map_mode((char_u **)&cmdp, eap->forceit || isabbrev); switch (do_map((*cmdp == 'n') ? 2 : (*cmdp == 'u'), eap->arg, mode, isabbrev)) { @@ -8008,16 +8143,16 @@ static void do_exmap(exarg_T *eap, int isabbrev) /// ":winsize" command (obsolete). static void ex_winsize(exarg_T *eap) { - char_u *arg = eap->arg; + char *arg = (char *)eap->arg; if (!ascii_isdigit(*arg)) { semsg(_(e_invarg2), arg); return; } - int w = getdigits_int(&arg, false, 10); - arg = skipwhite(arg); - char_u *p = arg; - int h = getdigits_int(&arg, false, 10); + int w = getdigits_int((char_u **)&arg, false, 10); + arg = (char *)skipwhite((char_u *)arg); + char *p = arg; + int h = getdigits_int((char_u **)&arg, false, 10); if (*p != NUL && *arg == NUL) { screen_resize(w, h); } else { @@ -8028,7 +8163,7 @@ static void ex_winsize(exarg_T *eap) static void ex_wincmd(exarg_T *eap) { int xchar = NUL; - char_u *p; + char *p; if (*eap->arg == 'g' || *eap->arg == Ctrl_G) { // CTRL-W g and CTRL-W CTRL-G have an extra command character @@ -8037,13 +8172,13 @@ static void ex_wincmd(exarg_T *eap) return; } xchar = eap->arg[1]; - p = eap->arg + 2; + p = (char *)eap->arg + 2; } else { - p = eap->arg + 1; + p = (char *)eap->arg + 1; } - eap->nextcmd = check_nextcmd(p); - p = skipwhite(p); + eap->nextcmd = check_nextcmd((char_u *)p); + p = (char *)skipwhite((char_u *)p); if (*p != NUL && *p != '"' && eap->nextcmd == NULL) { emsg(_(e_invarg)); } else if (!eap->skip) { @@ -8120,7 +8255,7 @@ static void ex_put(exarg_T *eap) /// Handle ":copy" and ":move". static void ex_copymove(exarg_T *eap) { - long n = get_address(eap, &eap->arg, eap->addr_type, false, false, false, 1); + long n = get_address(eap, (char **)&eap->arg, eap->addr_type, false, false, false, 1); if (eap->arg == NULL) { // error detected eap->nextcmd = NULL; return; @@ -8255,8 +8390,7 @@ static void ex_undo(exarg_T *eap) for (uhp = curbuf->b_u_curhead ? curbuf->b_u_curhead : curbuf->b_u_newhead; uhp != NULL && uhp->uh_seq > step; - uhp = uhp->uh_next.ptr, ++count) { - } + uhp = uhp->uh_next.ptr, ++count) {} if (step != 0 && (uhp == NULL || uhp->uh_seq < step)) { emsg(_(e_undobang_cannot_redo_or_move_branch)); return; @@ -8269,18 +8403,18 @@ static void ex_undo(exarg_T *eap) static void ex_wundo(exarg_T *eap) { - char_u hash[UNDO_HASH_SIZE]; + char hash[UNDO_HASH_SIZE]; - u_compute_hash(curbuf, hash); - u_write_undo((char *)eap->arg, eap->forceit, curbuf, hash); + u_compute_hash(curbuf, (char_u *)hash); + u_write_undo((char *)eap->arg, eap->forceit, curbuf, (char_u *)hash); } static void ex_rundo(exarg_T *eap) { - char_u hash[UNDO_HASH_SIZE]; + char hash[UNDO_HASH_SIZE]; - u_compute_hash(curbuf, hash); - u_read_undo((char *)eap->arg, hash, NULL); + u_compute_hash(curbuf, (char_u *)hash); + u_read_undo((char *)eap->arg, (char_u *)hash, NULL); } /// ":redo". @@ -8295,12 +8429,12 @@ static void ex_later(exarg_T *eap) long count = 0; bool sec = false; bool file = false; - char_u *p = eap->arg; + char *p = (char *)eap->arg; if (*p == NUL) { count = 1; } else if (isdigit(*p)) { - count = getdigits_long(&p, false, 0); + count = getdigits_long((char_u **)&p, false, 0); switch (*p) { case 's': ++p; sec = true; break; @@ -8327,8 +8461,8 @@ static void ex_later(exarg_T *eap) static void ex_redir(exarg_T *eap) { char *mode; - char_u *fname; - char_u *arg = eap->arg; + char *fname; + char *arg = (char *)eap->arg; if (STRICMP(eap->arg, "END") == 0) { close_redir(); @@ -8341,24 +8475,24 @@ static void ex_redir(exarg_T *eap) } else { mode = "w"; } - arg = skipwhite(arg); + arg = (char *)skipwhite((char_u *)arg); close_redir(); // Expand environment variables and "~/". - fname = expand_env_save(arg); + fname = (char *)expand_env_save((char_u *)arg); if (fname == NULL) { return; } - redir_fd = open_exfile(fname, eap->forceit, mode); + redir_fd = open_exfile((char_u *)fname, eap->forceit, mode); xfree(fname); } else if (*arg == '@') { // redirect to a register a-z (resp. A-Z for appending) close_redir(); ++arg; if (valid_yank_reg(*arg, true) && *arg != '_') { - redir_reg = *arg++; + redir_reg = (char_u)(*arg++); if (*arg == '>' && arg[1] == '>') { // append arg += 2; } else { @@ -8391,7 +8525,7 @@ static void ex_redir(exarg_T *eap) append = FALSE; } - if (var_redir_start(skipwhite(arg), append) == OK) { + if (var_redir_start(skipwhite((char_u *)arg), append) == OK) { redir_vname = 1; } } else { // TODO(vim): redirect to a buffer @@ -8633,9 +8767,9 @@ static void ex_normal(exarg_T *eap) return; } save_state_T save_state; - char_u *arg = NULL; + char *arg = NULL; int l; - char_u *p; + char *p; if (ex_normal_lock > 0) { emsg(_(e_secure)); @@ -8653,9 +8787,9 @@ static void ex_normal(exarg_T *eap) int len = 0; // Count the number of characters to be escaped. - for (p = eap->arg; *p != NUL; p++) { - for (l = utfc_ptr2len(p) - 1; l > 0; l--) { - if (*++p == K_SPECIAL) { // trailbyte K_SPECIAL + for (p = (char *)eap->arg; *p != NUL; p++) { + for (l = utfc_ptr2len((char_u *)p) - 1; l > 0; l--) { + if (*++p == (char)K_SPECIAL) { // trailbyte K_SPECIAL len += 2; } } @@ -8663,12 +8797,12 @@ static void ex_normal(exarg_T *eap) if (len > 0) { arg = xmalloc(STRLEN(eap->arg) + (size_t)len + 1); len = 0; - for (p = eap->arg; *p != NUL; ++p) { + for (p = (char *)eap->arg; *p != NUL; p++) { arg[len++] = *p; - for (l = utfc_ptr2len(p) - 1; l > 0; l--) { + for (l = utfc_ptr2len((char_u *)p) - 1; l > 0; l--) { arg[len++] = *++p; - if (*p == K_SPECIAL) { - arg[len++] = KS_SPECIAL; + if (*p == (char)K_SPECIAL) { + arg[len++] = (char)KS_SPECIAL; arg[len++] = KE_FILLER; } } @@ -8689,7 +8823,7 @@ static void ex_normal(exarg_T *eap) check_cursor_moved(curwin); } - exec_normal_cmd(arg != NULL ? arg : eap->arg, + exec_normal_cmd(arg != NULL ? (char_u *)arg : eap->arg, eap->forceit ? REMAP_NONE : REMAP_YES, false); } while (eap->addr_count > 0 && eap->line1 <= eap->line2 && !got_int); } @@ -8797,7 +8931,7 @@ static void ex_findpat(exarg_T *eap) { bool whole = true; long n; - char_u *p; + char *p; int action; switch (cmdnames[eap->cmdidx].cmd_name[2]) { @@ -8827,16 +8961,16 @@ static void ex_findpat(exarg_T *eap) if (*eap->arg == '/') { // Match regexp, not just whole words whole = false; eap->arg++; - p = skip_regexp(eap->arg, '/', p_magic, NULL); + p = (char *)skip_regexp(eap->arg, '/', p_magic, NULL); if (*p) { *p++ = NUL; - p = skipwhite(p); + p = (char *)skipwhite((char_u *)p); // Check for trailing illegal characters. if (!ends_excmd(*p)) { eap->errmsg = e_trailing; } else { - eap->nextcmd = check_nextcmd(p); + eap->nextcmd = check_nextcmd((char_u *)p); } } } @@ -8852,7 +8986,7 @@ static void ex_findpat(exarg_T *eap) static void ex_ptag(exarg_T *eap) { g_do_tagpreview = (int)p_pvh; // will be reset to 0 in ex_tag_cmd() - ex_tag_cmd(eap, cmdnames[eap->cmdidx].cmd_name + 1); + ex_tag_cmd(eap, (char *)cmdnames[eap->cmdidx].cmd_name + 1); } /// ":pedit" @@ -8882,7 +9016,7 @@ static void ex_stag(exarg_T *eap) postponed_split = -1; postponed_split_flags = cmdmod.split; postponed_split_tab = cmdmod.tab; - ex_tag_cmd(eap, cmdnames[eap->cmdidx].cmd_name + 1); + ex_tag_cmd(eap, (char *)cmdnames[eap->cmdidx].cmd_name + 1); postponed_split_flags = 0; postponed_split_tab = 0; } @@ -8890,10 +9024,10 @@ static void ex_stag(exarg_T *eap) /// ":tag", ":tselect", ":tjump", ":tnext", etc. static void ex_tag(exarg_T *eap) { - ex_tag_cmd(eap, cmdnames[eap->cmdidx].cmd_name); + ex_tag_cmd(eap, (char *)cmdnames[eap->cmdidx].cmd_name); } -static void ex_tag_cmd(exarg_T *eap, char_u *name) +static void ex_tag_cmd(exarg_T *eap, char *name) { int cmd; @@ -9023,9 +9157,9 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum int *escaped) { int i; - char_u *s; - char_u *result; - char_u *resultbuf = NULL; + char *s; + char *result; + char *resultbuf = NULL; size_t resultlen; buf_T *buf; int valid = VALID_HEAD | VALID_PATH; // Assume valid result. @@ -9063,7 +9197,7 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum if (spec_idx == SPEC_CWORD || spec_idx == SPEC_CCWORD || spec_idx == SPEC_CEXPR) { - resultlen = find_ident_under_cursor(&result, + resultlen = find_ident_under_cursor((char_u **)&result, spec_idx == SPEC_CWORD ? (FIND_IDENT | FIND_STRING) : (spec_idx == SPEC_CEXPR @@ -9084,10 +9218,10 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum switch (spec_idx) { case SPEC_PERC: // '%': current file if (curbuf->b_fname == NULL) { - result = (char_u *)""; + result = ""; valid = 0; // Must have ":p:h" to be valid } else { - result = curbuf->b_fname; + result = (char *)curbuf->b_fname; tilde_file = STRCMP(result, "~") == 0; } break; @@ -9103,16 +9237,16 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum skip_mod = true; break; } - s = src + 1; + s = (char *)src + 1; if (*s == '<') { // "#<99" uses v:oldfiles. s++; } - i = getdigits_int(&s, false, 0); - if (s == src + 2 && src[1] == '-') { + i = getdigits_int((char_u **)&s, false, 0); + if ((char_u *)s == src + 2 && src[1] == '-') { // just a minus sign, don't skip over it s--; } - *usedlen = (size_t)(s - src); // length of what we expand + *usedlen = (size_t)((char_u *)s - src); // length of what we expand if (src[1] == '<' && i != 0) { if (*usedlen < 2) { @@ -9120,8 +9254,7 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum *usedlen = 1; return NULL; } - result = (char_u *)tv_list_find_str(get_vim_var_list(VV_OLDFILES), - i - 1); + result = (char *)tv_list_find_str(get_vim_var_list(VV_OLDFILES), i - 1); if (result == NULL) { *errormsg = ""; return NULL; @@ -9139,17 +9272,17 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum *lnump = ECMD_LAST; } if (buf->b_fname == NULL) { - result = (char_u *)""; + result = ""; valid = 0; // Must have ":p:h" to be valid } else { - result = buf->b_fname; + result = (char *)buf->b_fname; tilde_file = STRCMP(result, "~") == 0; } } break; case SPEC_CFILE: // file name under cursor - result = file_name_at_cursor(FNAME_MESS|FNAME_HYP, 1L, NULL); + result = (char *)file_name_at_cursor(FNAME_MESS|FNAME_HYP, 1L, NULL); if (result == NULL) { *errormsg = ""; return NULL; @@ -9164,17 +9297,17 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum && !strequal("/", (char *)autocmd_fname)) { // Still need to turn the fname into a full path. It was // postponed to avoid a delay when <afile> is not used. - result = (char_u *)FullName_save((char *)autocmd_fname, false); + result = FullName_save((char *)autocmd_fname, false); // Copy into `autocmd_fname`, don't reassign it. #8165 STRLCPY(autocmd_fname, result, MAXPATHL); xfree(result); } - result = autocmd_fname; + result = (char *)autocmd_fname; if (result == NULL) { *errormsg = _("E495: no autocommand file name to substitute for \"<afile>\""); return NULL; } - result = path_try_shorten_fname(result); + result = (char *)path_try_shorten_fname((char_u *)result); break; case SPEC_ABUF: // buffer number for autocommand @@ -9183,11 +9316,11 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum return NULL; } snprintf(strbuf, sizeof(strbuf), "%d", autocmd_bufnr); - result = (char_u *)strbuf; + result = strbuf; break; case SPEC_AMATCH: // match name for autocommand - result = autocmd_match; + result = (char *)autocmd_match; if (result == NULL) { *errormsg = _("E497: no autocommand match name to substitute for \"<amatch>\""); return NULL; @@ -9195,7 +9328,7 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum break; case SPEC_SFILE: // file name for ":so" command - result = sourcing_name; + result = (char *)sourcing_name; if (result == NULL) { *errormsg = _("E498: no :source file name to substitute for \"<sfile>\""); return NULL; @@ -9208,7 +9341,7 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum return NULL; } snprintf(strbuf, sizeof(strbuf), "%" PRIdLINENR, sourcing_lnum); - result = (char_u *)strbuf; + result = strbuf; break; case SPEC_SFLNUM: // line in script file @@ -9218,7 +9351,7 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum } snprintf((char *)strbuf, sizeof(strbuf), "%" PRIdLINENR, current_sctx.sc_lnum + sourcing_lnum); - result = (char_u *)strbuf; + result = strbuf; break; case SPEC_SID: @@ -9228,13 +9361,13 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum } snprintf(strbuf, sizeof(strbuf), "<SNR>%" PRIdSCID "_", current_sctx.sc_sid); - result = (char_u *)strbuf; + result = strbuf; break; default: // should not happen *errormsg = ""; - result = (char_u *)""; // avoid gcc warning + result = ""; // avoid gcc warning break; } @@ -9243,12 +9376,13 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum // Remove the file name extension. if (src[*usedlen] == '<') { (*usedlen)++; - if ((s = STRRCHR(result, '.')) != NULL && s >= path_tail(result)) { + if ((s = (char *)STRRCHR(result, '.')) != NULL + && (char_u *)s >= path_tail((char_u *)result)) { resultlen = (size_t)(s - result); } } else if (!skip_mod) { - valid |= modify_fname(src, tilde_file, usedlen, &result, - &resultbuf, &resultlen); + valid |= modify_fname(src, tilde_file, usedlen, (char_u **)&result, + (char_u **)&resultbuf, &resultlen); if (result == NULL) { *errormsg = ""; return NULL; @@ -9265,21 +9399,21 @@ char_u *eval_vars(char_u *src, char_u *srcstart, size_t *usedlen, linenr_T *lnum } result = NULL; } else { - result = vim_strnsave(result, resultlen); + result = xstrnsave(result, resultlen); } xfree(resultbuf); - return result; + return (char_u *)result; } /// Concatenate all files in the argument list, separated by spaces, and return /// it in one allocated string. /// Spaces and backslashes in the file names are escaped with a backslash. -static char_u *arg_all(void) +static char *arg_all(void) { int len; int idx; - char_u *retval = NULL; - char_u *p; + char *retval = NULL; + char *p; /* * Do this loop two times: @@ -9288,8 +9422,8 @@ static char_u *arg_all(void) */ for (;;) { len = 0; - for (idx = 0; idx < ARGCOUNT; ++idx) { - p = alist_name(&ARGLIST[idx]); + for (idx = 0; idx < ARGCOUNT; idx++) { + p = (char *)alist_name(&ARGLIST[idx]); if (p == NULL) { continue; } @@ -9335,24 +9469,24 @@ static char_u *arg_all(void) /// Expand the <sfile> string in "arg". /// /// @return an allocated string, or NULL for any error. -char_u *expand_sfile(char_u *arg) +char *expand_sfile(char *arg) { char *errormsg; size_t len; - char_u *result; - char_u *newres; - char_u *repl; + char *result; + char *newres; + char *repl; size_t srclen; - char_u *p; + char *p; - result = vim_strsave(arg); + result = xstrdup(arg); for (p = result; *p;) { if (STRNCMP(p, "<sfile>", 7) != 0) { ++p; } else { // replace "<sfile>" with the sourced file name, and do ":" stuff - repl = eval_vars(p, result, &srclen, NULL, &errormsg, NULL); + repl = (char *)eval_vars((char_u *)p, (char_u *)result, &srclen, NULL, &errormsg, NULL); if (errormsg != NULL) { if (*errormsg) { emsg(errormsg); @@ -9383,9 +9517,9 @@ char_u *expand_sfile(char_u *arg) /// ":rshada" and ":wshada". static void ex_shada(exarg_T *eap) { - char_u *save_shada; + char *save_shada; - save_shada = p_shada; + save_shada = (char *)p_shada; if (*p_shada == NUL) { p_shada = (char_u *)"'100"; } @@ -9394,17 +9528,17 @@ static void ex_shada(exarg_T *eap) } else { shada_write_file((char *)eap->arg, eap->forceit); } - p_shada = save_shada; + p_shada = (char_u *)save_shada; } /// Make a dialog message in "buff[DIALOG_MSG_SIZE]". /// "format" must contain "%s". -void dialog_msg(char_u *buff, char *format, char_u *fname) +void dialog_msg(char *buff, char *format, char *fname) { if (fname == NULL) { - fname = (char_u *)_("Untitled"); + fname = _("Untitled"); } - vim_snprintf((char *)buff, DIALOG_MSG_SIZE, format, fname); + vim_snprintf(buff, DIALOG_MSG_SIZE, format, fname); } /// ":behave {mswin,xterm}" @@ -9469,7 +9603,7 @@ static TriState filetype_indent = kNone; /// indent off: load indoff.vim static void ex_filetype(exarg_T *eap) { - char_u *arg = eap->arg; + char *arg = (char *)eap->arg; bool plugin = false; bool indent = false; @@ -9486,12 +9620,12 @@ static void ex_filetype(exarg_T *eap) for (;;) { if (STRNCMP(arg, "plugin", 6) == 0) { plugin = true; - arg = skipwhite(arg + 6); + arg = (char *)skipwhite((char_u *)arg + 6); continue; } if (STRNCMP(arg, "indent", 6) == 0) { indent = true; - arg = skipwhite(arg + 6); + arg = (char *)skipwhite((char_u *)arg + 6); continue; } break; @@ -9564,14 +9698,14 @@ void filetype_maybe_enable(void) static void ex_setfiletype(exarg_T *eap) { if (!did_filetype) { - char_u *arg = eap->arg; + char *arg = (char *)eap->arg; if (STRNCMP(arg, "FALLBACK ", 9) == 0) { arg += 9; } - set_option_value("filetype", 0L, (char *)arg, OPT_LOCAL); - if (arg != eap->arg) { + set_option_value("filetype", 0L, arg, OPT_LOCAL); + if ((char_u *)arg != eap->arg) { did_filetype = false; } } @@ -9624,7 +9758,7 @@ static void ex_folddo(exarg_T *eap) } } - global_exe(eap->arg); // Execute the command on the marked lines. + global_exe((char *)eap->arg); // Execute the command on the marked lines. ml_clearmarked(); // clear rest of the marks } @@ -9691,7 +9825,7 @@ static void ex_terminal(exarg_T *eap) /// @param[in] cmd Commandline to check. May start with a range or modifier. /// /// @return true if `cmd` is previewable -bool cmd_can_preview(char_u *cmd) +bool cmd_can_preview(char *cmd) { if (cmd == NULL) { return false; @@ -9711,9 +9845,9 @@ bool cmd_can_preview(char_u *cmd) // parse the command line ea.cmd = skip_range(cmd, NULL); if (*ea.cmd == '*') { - ea.cmd = skipwhite(ea.cmd + 1); + ea.cmd = (char *)skipwhite((char_u *)ea.cmd + 1); } - char_u *end = find_command(&ea, NULL); + char *end = find_command(&ea, NULL); switch (ea.cmdidx) { case CMD_substitute: @@ -9815,9 +9949,9 @@ Dictionary commands_array(buf_T *buf) return rv; } -void verify_command(char_u *cmd) +void verify_command(char *cmd) { - if (strcmp("smile", (char *)cmd)) { + if (strcmp("smile", cmd)) { return; // acceptable non-existing command } msg(" #xxn` #xnxx` ,+x@##@Mz;` .xxx" diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 102d817694..f91371d3ad 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -417,7 +417,7 @@ char *get_exception_string(void *value, except_type_T type, char_u *cmdname, int STRCAT(val, mesg); // 'E123' missing or at beginning } else { // '"filename" E123: message text' - if (mesg[0] != '"' || p-2 < &mesg[1] + if (mesg[0] != '"' || p - 2 < &mesg[1] || p[-2] != '"' || p[-1] != ' ') { // "E123:" is part of the file name. continue; @@ -2045,7 +2045,7 @@ int has_loop_cmd(char_u *p) while (*p == ' ' || *p == '\t' || *p == ':') { ++p; } - len = modifier_len(p); + len = modifier_len((char *)p); if (len == 0) { break; } diff --git a/src/nvim/ex_eval.h b/src/nvim/ex_eval.h index 1cd0a47d7a..98573c7182 100644 --- a/src/nvim/ex_eval.h +++ b/src/nvim/ex_eval.h @@ -47,8 +47,7 @@ struct msglist { }; // The exception types. -typedef enum -{ +typedef enum { ET_USER, // exception caused by ":throw" command ET_ERROR, // error exception ET_INTERRUPT, // interrupt exception triggered by Ctrl-C diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index b7d75855d6..cd8ade33c8 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -390,13 +390,13 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s memset(&ea, 0, sizeof(ea)); ea.line1 = 1; ea.line2 = 1; - ea.cmd = ccline.cmdbuff; + ea.cmd = (char *)ccline.cmdbuff; ea.addr_type = ADDR_LINES; parse_command_modifiers(&ea, &dummy, true); cmdmod = save_cmdmod; - cmd = skip_range(ea.cmd, NULL); + cmd = (char_u *)skip_range(ea.cmd, NULL); if (vim_strchr((char_u *)"sgvl", *cmd) == NULL) { goto theend; } @@ -1335,8 +1335,10 @@ static int command_line_execute(VimState *state, int key) // mode when 'insertmode' is set, CTRL-\ e prompts for an expression. if (s->c == Ctrl_BSL) { no_mapping++; + allow_keys++; s->c = plain_vgetc(); no_mapping--; + allow_keys--; // CTRL-\ e doesn't work when obtaining an expression, unless it // is in a mapping. if (s->c != Ctrl_N @@ -1889,6 +1891,7 @@ static int command_line_handle_key(CommandLineState *s) case Ctrl_R: { // insert register putcmdline('"', true); no_mapping++; + allow_keys++; int i = s->c = plain_vgetc(); // CTRL-R <char> if (i == Ctrl_O) { i = Ctrl_R; // CTRL-R CTRL-O == CTRL-R CTRL-R @@ -1897,7 +1900,8 @@ static int command_line_handle_key(CommandLineState *s) if (i == Ctrl_R) { s->c = plain_vgetc(); // CTRL-R CTRL-R <char> } - --no_mapping; + no_mapping--; + allow_keys--; // Insert the result of an expression. // Need to save the current command line, to be able to enter // a new one... @@ -2208,7 +2212,11 @@ static int command_line_handle_key(CommandLineState *s) case Ctrl_Q: s->ignore_drag_release = true; putcmdline('^', true); - s->c = get_literal(); // get next (two) character(s) + + // Get next (two) characters. + // Do not include modifiers into the key for CTRL-SHIFT-V. + s->c = get_literal(mod_mask & MOD_MASK_SHIFT); + s->do_abbr = false; // don't do abbreviation now ccline.special_char = NUL; // may need to remove ^ when composing char was typed @@ -2341,7 +2349,7 @@ static int command_line_changed(CommandLineState *s) && *p_icm != NUL // 'inccommand' is set && curbuf->b_p_ma // buffer is modifiable && cmdline_star == 0 // not typing a password - && cmd_can_preview(ccline.cmdbuff) + && cmd_can_preview((char *)ccline.cmdbuff) && !vpeekc_any()) { // Show 'inccommand' preview. It works like this: // 1. Do the command. @@ -2351,7 +2359,7 @@ static int command_line_changed(CommandLineState *s) State |= CMDPREVIEW; emsg_silent++; // Block error reporting as the command may be incomplete msg_silent++; // Block messages, namely ones that prompt - do_cmdline(ccline.cmdbuff, NULL, NULL, DOCMD_KEEPLINE|DOCMD_NOWAIT|DOCMD_PREVIEW); + do_cmdline((char *)ccline.cmdbuff, NULL, NULL, DOCMD_KEEPLINE|DOCMD_NOWAIT|DOCMD_PREVIEW); msg_silent--; // Unblock messages emsg_silent--; // Unblock error reporting @@ -3121,7 +3129,7 @@ static void ui_ext_cmdline_show(CmdlineInfo *line) assert(chunk.end >= chunk.start); ADD(item, STRING_OBJ(cbuf_to_string((char *)line->cmdbuff + chunk.start, - (size_t)(chunk.end-chunk.start)))); + (size_t)(chunk.end - chunk.start)))); ADD(content, ARRAY_OBJ(item)); } } else { @@ -3180,7 +3188,7 @@ void cmdline_screen_cleared(void) ui_call_cmdline_block_show(copy_array(cmdline_block)); } - int prev_level = ccline.level-1; + int prev_level = ccline.level - 1; CmdlineInfo *line = ccline.prev_ccline; while (prev_level > 0 && line) { if (line->level == prev_level) { @@ -3637,7 +3645,7 @@ static void cursorcmd(void) } if (cmdmsg_rl) { - msg_row = cmdline_row + (ccline.cmdspos / (Columns - 1)); + msg_row = cmdline_row + (ccline.cmdspos / (Columns - 1)); msg_col = Columns - (ccline.cmdspos % (Columns - 1)) - 1; if (msg_row <= 0) { msg_row = Rows - 1; @@ -4452,7 +4460,7 @@ char_u *sm_gettail(char_u *s, bool eager) #endif ) { if (eager) { - t = p+1; + t = p + 1; } else { had_sep = true; } @@ -4924,8 +4932,8 @@ static int ExpandFromContext(expand_T *xp, char_u *pat, int *num_file, char_u ** if (xp->xp_context == EXPAND_HELP) { /* With an empty argument we would get all the help tags, which is * very slow. Get matches for "help" instead. */ - if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat, - num_file, file, false) == OK) { + if (find_help_tags(*pat == NUL ? "help" : (char *)pat, + num_file, (char ***)file, false) == OK) { cleanup_help_tags(*num_file, *file); return OK; } @@ -5563,7 +5571,7 @@ static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file) for (int i = 0; i < ga.ga_len; i++) { char_u *match = ((char_u **)ga.ga_data)[i]; s = path_tail(match); - memmove(match, s, STRLEN(s)+1); + memmove(match, s, STRLEN(s) + 1); } if (GA_EMPTY(&ga)) { @@ -6248,7 +6256,7 @@ void ex_history(exarg_T *eap) if (histype1 == HIST_INVALID) { if (STRNICMP(arg, "all", end - arg) == 0) { histype1 = 0; - histype2 = HIST_COUNT-1; + histype2 = HIST_COUNT - 1; } else { emsg(_(e_trailing)); return; @@ -6274,10 +6282,10 @@ void ex_history(exarg_T *eap) j = hisidx1; k = hisidx2; if (j < 0) { - j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; + j = (-j > hislen) ? 0 : hist[(hislen + j + idx + 1) % hislen].hisnum; } if (k < 0) { - k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; + k = (-k > hislen) ? 0 : hist[(hislen + k + idx + 1) % hislen].hisnum; } if (idx >= 0 && j <= k) { for (i = idx + 1; !got_int; ++i) { diff --git a/src/nvim/ex_session.h b/src/nvim/ex_session.h index 8d3ea5b91a..7ee2894c6e 100644 --- a/src/nvim/ex_session.h +++ b/src/nvim/ex_session.h @@ -10,4 +10,3 @@ #endif #endif // NVIM_EX_SESSION_H - diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c index a3fcc7d784..ffd68926f1 100644 --- a/src/nvim/extmark.c +++ b/src/nvim/extmark.c @@ -512,7 +512,7 @@ void extmark_adjust(buf_T *buf, linenr_T line1, linenr_T line2, long amount, lon bcount_t old_byte = 0, new_byte = 0; int old_row, new_row; if (amount == MAXLNUM) { - old_row = (int)(line2 - line1+1); + old_row = (int)(line2 - line1 + 1); // TODO(bfredl): ej kasta? old_byte = (bcount_t)buf->deleted_bytes2; @@ -526,11 +526,11 @@ void extmark_adjust(buf_T *buf, linenr_T line1, linenr_T line2, long amount, lon new_row = (int)amount; } if (new_row > 0) { - new_byte = ml_find_line_or_offset(buf, line1+new_row, NULL, true) + new_byte = ml_find_line_or_offset(buf, line1 + new_row, NULL, true) - start_byte; } extmark_splice_impl(buf, - (int)line1-1, 0, start_byte, + (int)line1 - 1, 0, start_byte, old_row, 0, old_byte, new_row, 0, new_byte, undo); } @@ -609,18 +609,18 @@ void extmark_splice_impl(buf_T *buf, int start_row, colnr_T start_col, bcount_t // merge algorithm later. if (old_row == 0 && new_row == 0 && kv_size(uhp->uh_extmark)) { ExtmarkUndoObject *item = &kv_A(uhp->uh_extmark, - kv_size(uhp->uh_extmark)-1); + kv_size(uhp->uh_extmark) - 1); if (item->type == kExtmarkSplice) { ExtmarkSplice *splice = &item->data.splice; if (splice->start_row == start_row && splice->old_row == 0 && splice->new_row == 0) { if (old_col == 0 && start_col >= splice->start_col - && start_col <= splice->start_col+splice->new_col) { + && start_col <= splice->start_col + splice->new_col) { splice->new_col += new_col; splice->new_byte += new_byte; merged = true; } else if (new_col == 0 - && start_col == splice->start_col+splice->new_col) { + && start_col == splice->start_col + splice->new_col) { splice->old_col += old_col; splice->old_byte += old_byte; merged = true; diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 8a09c10908..1113459feb 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -374,20 +374,20 @@ void *vim_findfile_init(char_u *path, char_u *filename, char_u *stopdirs, int le walker = vim_strchr(walker, ';'); if (walker) { assert(walker - helper >= 0); - search_ctx->ffsc_stopdirs_v[dircount-1] = + search_ctx->ffsc_stopdirs_v[dircount - 1] = vim_strnsave(helper, (size_t)(walker - helper)); walker++; } else { /* this might be "", which means ascent till top * of directory tree. */ - search_ctx->ffsc_stopdirs_v[dircount-1] = + search_ctx->ffsc_stopdirs_v[dircount - 1] = vim_strsave(helper); } dircount++; } while (walker != NULL); - search_ctx->ffsc_stopdirs_v[dircount-1] = NULL; + search_ctx->ffsc_stopdirs_v[dircount - 1] = NULL; } search_ctx->ffsc_level = level; @@ -1698,4 +1698,3 @@ int vim_chdir(char_u *new_dir) xfree(dir_name); return r; } - diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 25c99af41b..7ca7abccdc 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -3,8 +3,6 @@ // fileio.c: read from and write to a file -// uncrustify:off - #include <assert.h> #include <errno.h> #include <fcntl.h> @@ -21,8 +19,8 @@ #include "nvim/cursor.h" #include "nvim/diff.h" #include "nvim/edit.h" -#include "nvim/eval/userfunc.h" #include "nvim/eval/typval.h" +#include "nvim/eval/userfunc.h" #include "nvim/ex_cmds.h" #include "nvim/ex_docmd.h" #include "nvim/ex_eval.h" @@ -359,7 +357,9 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski // because reading the file may actually work, but then creating the // swap file may destroy it! Reported on MS-DOS and Win 95. if (after_pathsep((const char *)fname, (const char *)(fname + namelen))) { - filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0); + if (!silent) { + filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0); + } msg_end(); msg_scroll = msg_save; return NOTDONE; @@ -379,7 +379,9 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski #endif ) { if (S_ISDIR(perm)) { - filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0); + if (!silent) { + filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0); + } } else { filemess(curbuf, fname, (char_u *)_("is not a file"), 0); } @@ -688,7 +690,7 @@ int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_ski * Decide which 'encoding' to use or use first. */ if (eap != NULL && eap->force_enc != 0) { - fenc = enc_canonize(eap->cmd + eap->force_enc); + fenc = enc_canonize((char_u *)eap->cmd + eap->force_enc); fenc_alloced = true; keep_dest_enc = true; } else if (curbuf->b_p_bin) { @@ -1526,8 +1528,7 @@ rewind_retry: // Need to reset the counters when retrying fenc. try_mac = 1; try_unix = 1; - for (; p >= ptr && *p != CAR; p--) { - } + for (; p >= ptr && *p != CAR; p--) {} if (p >= ptr) { for (p = ptr; p < ptr + size; ++p) { if (*p == NL) { @@ -2026,7 +2027,7 @@ void prep_exarg(exarg_T *eap, const buf_T *buf) const size_t cmd_len = 15 + STRLEN(buf->b_p_fenc); eap->cmd = xmalloc(cmd_len); - snprintf((char *)eap->cmd, cmd_len, "e ++enc=%s", buf->b_p_fenc); + snprintf(eap->cmd, cmd_len, "e ++enc=%s", buf->b_p_fenc); eap->force_enc = 8; eap->bad_char = buf->b_bad_char; eap->force_ff = *buf->b_p_ff; @@ -2061,7 +2062,7 @@ void set_file_options(int set_options, exarg_T *eap) void set_forced_fenc(exarg_T *eap) { if (eap->force_enc != 0) { - char_u *fenc = enc_canonize(eap->cmd + eap->force_enc); + char_u *fenc = enc_canonize((char_u *)eap->cmd + eap->force_enc); set_string_option_direct("fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0); xfree(fenc); } @@ -3065,7 +3066,7 @@ nobackup: // Check for forced 'fileencoding' from "++opt=val" argument. if (eap != NULL && eap->force_enc != 0) { - fenc = eap->cmd + eap->force_enc; + fenc = (char_u *)eap->cmd + eap->force_enc; fenc = enc_canonize(fenc); fenc_tofree = fenc; } else { @@ -4908,11 +4909,15 @@ int buf_check_timestamp(buf_T *buf) char *mesg = NULL; char *mesg2 = ""; bool helpmesg = false; + + // uncrustify:off enum { RELOAD_NONE, RELOAD_NORMAL, RELOAD_DETECT } reload = RELOAD_NONE; + // uncrustify:on + bool can_reload = false; uint64_t orig_size = buf->b_orig_size; int orig_mode = buf->b_orig_mode; @@ -5064,12 +5069,12 @@ int buf_check_timestamp(buf_T *buf) switch (do_dialog(VIM_WARNING, (char_u *)_("Warning"), (char_u *)tbuf, (char_u *)_("&OK\n&Load File\nLoad File &and Options"), 1, NULL, true)) { - case 2: - reload = RELOAD_NORMAL; - break; - case 3: - reload = RELOAD_DETECT; - break; + case 2: + reload = RELOAD_NORMAL; + break; + case 3: + reload = RELOAD_DETECT; + break; } } else if (State > NORMAL_BUSY || (State & CMDLINE) || already_warned) { if (*mesg2 != NUL) { diff --git a/src/nvim/fold.c b/src/nvim/fold.c index bc31fe42ba..ef2987d1ab 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1640,11 +1640,11 @@ static void foldAddMarker(buf_T *buf, pos_T pos, const char_u *marker, size_t ma STRCPY(newline + line_len, cms); memcpy(newline + line_len + (p - cms), marker, markerlen); STRCPY(newline + line_len + (p - cms) + markerlen, p + 2); - added = markerlen + STRLEN(cms)-2; + added = markerlen + STRLEN(cms) - 2; } ml_replace_buf(buf, lnum, newline, false); if (added) { - extmark_splice_cols(buf, (int)lnum-1, (int)line_len, + extmark_splice_cols(buf, (int)lnum - 1, (int)line_len, 0, (int)added, kExtmarkUndo); } } @@ -1662,7 +1662,7 @@ static void deleteFoldMarkers(win_T *wp, fold_T *fp, int recursive, linenr_T lnu lnum_off + fp->fd_top); } } - foldDelMarker(wp->w_buffer, fp->fd_top+lnum_off, wp->w_p_fmr, + foldDelMarker(wp->w_buffer, fp->fd_top + lnum_off, wp->w_p_fmr, foldstartmarkerlen); foldDelMarker(wp->w_buffer, fp->fd_top + lnum_off + fp->fd_len - 1, foldendmarker, foldendmarkerlen); @@ -1710,7 +1710,7 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char_u *marker, size_t mark memcpy(newline, line, (size_t)(p - line)); STRCPY(newline + (p - line), p + len); ml_replace_buf(buf, lnum, newline, false); - extmark_splice_cols(buf, (int)lnum-1, (int)(p - line), + extmark_splice_cols(buf, (int)lnum - 1, (int)(p - line), (int)len, 0, kExtmarkUndo); } break; @@ -1877,8 +1877,7 @@ void foldtext_cleanup(char_u *str) // May remove 'commentstring' start. Useful when it's a double // quote and we already removed a double quote. - for (p = s; p > str && ascii_iswhite(p[-1]); p--) { - } + for (p = s; p > str && ascii_iswhite(p[-1]); p--) {} if (p >= str + cms_slen && STRNCMP(p - cms_slen, cms_start, cms_slen) == 0) { len += (size_t)(s - p) + cms_slen; @@ -2547,7 +2546,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level, // Make fold that includes lnum start at lnum. foldMarkAdjustRecurse(flp->wp, &fp2->fd_nested, (linenr_T)0, (flp->lnum - fp2->fd_top - 1), - (linenr_T)MAXLNUM, (fp2->fd_top-flp->lnum)); + (linenr_T)MAXLNUM, (fp2->fd_top - flp->lnum)); fp2->fd_len -= flp->lnum - fp2->fd_top; fp2->fd_top = flp->lnum; fold_changed = true; diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index f2df7b49fd..6dd6c51e8f 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -430,8 +430,7 @@ void flush_buffers(flush_buffers_T flush_typeahead) init_typebuf(); start_stuff(); - while (read_readbuffers(TRUE) != NUL) { - } + while (read_readbuffers(true) != NUL) {} if (flush_typeahead == FLUSH_MINIMAL) { // remove mapped characters at the start only @@ -443,8 +442,7 @@ void flush_buffers(flush_buffers_T flush_typeahead) // We have to get all characters, because we may delete the first // part of an escape sequence. In an xterm we get one char at a // time and we have to get them all. - while (inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 10L) != 0) { - } + while (inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 10L) != 0) {} } typebuf.tb_off = MAXMAPLEN; typebuf.tb_len = 0; @@ -494,8 +492,7 @@ void CancelRedo(void) redobuff = old_redobuff; old_redobuff.bh_first.b_next = NULL; start_stuff(); - while (read_readbuffers(TRUE) != NUL) { - } + while (read_readbuffers(true) != NUL) {} } } @@ -872,10 +869,8 @@ void init_default_mappings(void) int ins_typebuf(char_u *str, int noremap, int offset, bool nottyped, bool silent) { char_u *s1, *s2; - int newlen; int addlen; int i; - int newoff; int val; int nrm; @@ -901,13 +896,15 @@ int ins_typebuf(char_u *str, int noremap, int offset, bool nottyped, bool silent // In typebuf.tb_buf there must always be room for 3 * (MAXMAPLEN + 4) // characters. We add some extra room to avoid having to allocate too // often. - newoff = MAXMAPLEN + 4; - newlen = typebuf.tb_len + addlen + newoff + 4 * (MAXMAPLEN + 4); - if (newlen < 0) { // string is getting too long + int newoff = MAXMAPLEN + 4; + int extra = addlen + newoff + 4 * (MAXMAPLEN + 4); + if (typebuf.tb_len > 2147483674 - extra) { + // string is getting too long for 32 bit int emsg(_(e_toocompl)); // also calls flush_buffers setcursor(); return FAIL; } + int newlen = typebuf.tb_len + extra; s1 = xmalloc((size_t)newlen); s2 = xmalloc((size_t)newlen); typebuf.tb_buflen = newlen; @@ -1261,9 +1258,9 @@ static int old_KeyStuffed; // whether old_char was stuffed static bool can_get_old_char(void) { - // If the old character was not stuffed and characters have been added to - // the stuff buffer, need to first get the stuffed characters instead. - return old_char != -1 && (old_KeyStuffed || stuff_empty()); + // If the old character was not stuffed and characters have been added to + // the stuff buffer, need to first get the stuffed characters instead. + return old_char != -1 && (old_KeyStuffed || stuff_empty()); } /* @@ -1442,6 +1439,28 @@ static void updatescript(int c) } } +/// Merge "modifiers" into "c_arg". +int merge_modifiers(int c_arg, int *modifiers) +{ + int c = c_arg; + + if (*modifiers & MOD_MASK_CTRL) { + if ((c >= '`' && c <= 0x7f) || (c >= '@' && c <= '_')) { + c &= 0x1f; + if (c == NUL) { + c = K_ZERO; + } + } else if (c == '6') { + // CTRL-6 is equivalent to CTRL-^ + c = 0x1e; + } + if (c != c_arg) { + *modifiers &= ~MOD_MASK_CTRL; + } + } + return c; +} + /// Get the next input character. /// Can return a special key or a multi-byte character. /// Can return NUL when called recursively, use safe_vgetc() if that's not @@ -1478,6 +1497,8 @@ int vgetc(void) static size_t last_vgetc_recorded_len = 0; mod_mask = 0; + vgetc_mod_mask = 0; + vgetc_char = 0; // last_recorded_len can be larger than last_vgetc_recorded_len // if peeking records more @@ -1487,19 +1508,24 @@ int vgetc(void) bool did_inc = false; if (mod_mask) { // no mapping after modifier has been read no_mapping++; + allow_keys++; did_inc = true; // mod_mask may change value } c = vgetorpeek(true); if (did_inc) { no_mapping--; + allow_keys--; } // Get two extra bytes for special keys if (c == K_SPECIAL) { + int save_allow_keys = allow_keys; no_mapping++; + allow_keys = 0; // make sure BS is not found c2 = vgetorpeek(true); // no mapping for these chars c = vgetorpeek(true); no_mapping--; + allow_keys = save_allow_keys; if (c2 == KS_MODIFIER) { mod_mask = c; continue; @@ -1601,20 +1627,9 @@ int vgetc(void) c = utf_ptr2char(buf); } - // A modifier was not used for a mapping, apply it to ASCII - // keys. Shift would already have been applied. - if (mod_mask & MOD_MASK_CTRL) { - if ((c >= '`' && c <= 0x7f) || (c >= '@' && c <= '_')) { - c &= 0x1f; - mod_mask &= ~MOD_MASK_CTRL; - if (c == 0) { - c = K_ZERO; - } - } else if (c == '6') { - // CTRL-6 is equivalent to CTRL-^ - c = 0x1e; - mod_mask &= ~MOD_MASK_CTRL; - } + if (vgetc_char == 0) { + vgetc_mod_mask = mod_mask; + vgetc_char = c; } // If mappings are enabled (i.e., not Ctrl-v) and the user directly typed @@ -1731,11 +1746,101 @@ typedef enum { map_result_nomatch, // no matching mapping, get char } map_result_T; +/// Put "string[new_slen]" in typebuf. +/// Remove "slen" bytes. +/// @return FAIL for error, OK otherwise. +static int put_string_in_typebuf(int offset, int slen, char_u *string, int new_slen) +{ + int extra = new_slen - slen; + string[new_slen] = NUL; + if (extra < 0) { + // remove matched chars, taking care of noremap + del_typebuf(-extra, offset); + } else if (extra > 0) { + // insert the extra space we need + if (ins_typebuf(string + slen, REMAP_YES, offset, false, false) == FAIL) { + return FAIL; + } + } + // Careful: del_typebuf() and ins_typebuf() may have reallocated + // typebuf.tb_buf[]! + memmove(typebuf.tb_buf + typebuf.tb_off + offset, string, (size_t)new_slen); + return OK; +} + +/// Check if the bytes at the start of the typeahead buffer are a character used +/// in Insert mode completion. This includes the form with a CTRL modifier. +static bool at_ins_compl_key(void) +{ + char_u *p = typebuf.tb_buf + typebuf.tb_off; + int c = *p; + + if (typebuf.tb_len > 3 && c == K_SPECIAL && p[1] == KS_MODIFIER && (p[2] & MOD_MASK_CTRL)) { + c = p[3] & 0x1f; + } + return (ctrl_x_mode_not_default() && vim_is_ctrl_x_key(c)) + || ((compl_cont_status & CONT_LOCAL) && (c == Ctrl_N || c == Ctrl_P)); +} + +/// Check if typebuf.tb_buf[] contains a modifer plus key that can be changed +/// into just a key, apply that. +/// Check from typebuf.tb_buf[typebuf.tb_off] to typebuf.tb_buf[typebuf.tb_off + "max_offset"]. +/// @return the length of the replaced bytes, 0 if nothing changed, -1 for error. +static int check_simplify_modifier(int max_offset) +{ + for (int offset = 0; offset < max_offset; offset++) { + if (offset + 3 >= typebuf.tb_len) { + break; + } + char_u *tp = typebuf.tb_buf + typebuf.tb_off + offset; + if (tp[0] == K_SPECIAL && tp[1] == KS_MODIFIER) { + // A modifier was not used for a mapping, apply it to ASCII + // keys. Shift would already have been applied. + int modifier = tp[2]; + int c = tp[3]; + int new_c = merge_modifiers(c, &modifier); + + if (new_c != c) { + if (offset == 0) { + // At the start: remember the character and mod_mask before + // merging, in some cases, e.g. at the hit-return prompt, + // they are put back in the typeahead buffer. + vgetc_char = c; + vgetc_mod_mask = tp[2]; + } + char_u new_string[MB_MAXBYTES]; + int len; + if (IS_SPECIAL(new_c)) { + new_string[0] = K_SPECIAL; + new_string[1] = (char_u)K_SECOND(new_c); + new_string[2] = (char_u)K_THIRD(new_c); + len = 3; + } else { + len = utf_char2bytes(new_c, new_string); + } + if (modifier == 0) { + if (put_string_in_typebuf(offset, 4, new_string, len) == FAIL) { + return -1; + } + } else { + tp[2] = (char_u)modifier; + if (put_string_in_typebuf(offset + 3, 1, new_string, len) == FAIL) { + return -1; + } + } + return len; + } + } + } + return 0; +} + /// Handle mappings in the typeahead buffer. /// - When something was mapped, return map_result_retry for recursive mappings. /// - When nothing mapped and typeahead has a character: return map_result_get. /// - When there is no match yet, return map_result_nomatch, need to get more /// typeahead. +/// - On failure (out of memory) return map_result_fail. static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) { mapblock_T *mp = NULL; @@ -1779,9 +1884,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) && !(State == HITRETURN && (tb_c1 == CAR || tb_c1 == ' ')) && State != ASKMORE && State != CONFIRM - && !((ctrl_x_mode_not_default() && vim_is_ctrl_x_key(tb_c1)) - || ((compl_cont_status & CONT_LOCAL) - && (tb_c1 == Ctrl_N || tb_c1 == Ctrl_P)))) { + && !at_ins_compl_key()) { if (tb_c1 == K_SPECIAL) { nolmaplen = 2; } else { @@ -1889,7 +1992,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) } // If no partly match found, use the longest full match. - if (keylen != KEYLEN_PART_MAP) { + if (keylen != KEYLEN_PART_MAP && mp_match != NULL) { mp = mp_match; keylen = mp_match_len; } @@ -1928,17 +2031,54 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) } } - if ((mp == NULL || max_mlen >= mp_match_len) && keylen != KEYLEN_PART_MAP) { - // No matching mapping found or found a non-matching mapping that - // matches at least what the matching mapping matched - keylen = 0; - (void)keylen; // suppress clang/dead assignment - // If there was no mapping, use the character from the typeahead - // buffer right here. Otherwise, use the mapping (loop around). - if (mp == NULL) { + if ((mp == NULL || max_mlen > mp_match_len) && keylen != KEYLEN_PART_MAP) { + // When no matching mapping found or found a non-matching mapping that + // matches at least what the matching mapping matched: + // Try to include the modifier into the key when mapping is allowed. + if (no_mapping == 0 || allow_keys != 0) { + if (tb_c1 == K_SPECIAL + && (typebuf.tb_len < 2 + || (typebuf.tb_buf[typebuf.tb_off + 1] == KS_MODIFIER && typebuf.tb_len < 4))) { + // Incomplete modifier sequence: cannot decide whether to simplify yet. + keylen = KEYLEN_PART_KEY; + } else if (keylen == KEYLEN_PART_KEY && !*timedout) { + // If 'pastetoggle' matched partially, don't simplify. + // When the last characters were not typed, don't wait for a typed character to + // complete 'pastetoggle'. + if (typebuf.tb_len == typebuf.tb_maplen) { + keylen = 0; + } + } else { + // Try to include the modifier into the key. + keylen = check_simplify_modifier(max_mlen + 1); + if (keylen < 0) { + // ins_typebuf() failed + return map_result_fail; + } + } + } else { + keylen = 0; + } + if (keylen == 0) { // no simplication has been done + // If there was no mapping at all use the character from the + // typeahead buffer right here. + if (mp == NULL) { + *keylenp = keylen; + return map_result_get; // get character from typeahead + } + } + + if (keylen > 0) { // keys have been simplified *keylenp = keylen; - return map_result_get; // get character from typeahead + return map_result_retry; // try mapping again + } + + if (keylen < 0) { + // Incomplete key sequence: get some more characters. + assert(keylen == KEYLEN_PART_KEY); } else { + assert(mp != NULL); + // When a matching mapping was found use that one. keylen = mp_match_len; } } @@ -2189,6 +2329,10 @@ static int vgetorpeek(bool advance) // try re-mapping. for (;;) { check_end_reg_executing(advance); + // os_breakcheck() can call input_enqueue() + if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) { + ctrl_c_interrupts = false; + } // os_breakcheck() is slow, don't use it too often when // inside a mapping. But call it each time for typed // characters. @@ -2197,6 +2341,7 @@ static int vgetorpeek(bool advance) } else { os_breakcheck(); // check for CTRL-C } + ctrl_c_interrupts = true; int keylen = 0; if (got_int) { // flush all input @@ -2620,7 +2765,7 @@ int inchar(char_u *buf, int maxlen, long wait_time) for (;;) { len = os_inchar(dum, DUM_LEN, 0L, 0, NULL); - if (len == 0 || (len == 1 && dum[0] == 3)) { + if (len == 0 || (len == 1 && dum[0] == Ctrl_C)) { break; } } @@ -2711,11 +2856,12 @@ int fix_input_buffer(char_u *buf, int len) /// @param[in] orig_rhs_len `strlen` of orig_rhs. /// @param[in] cpo_flags See param docs for @ref replace_termcodes. /// @param[out] mapargs MapArguments struct holding the replaced strings. -void set_maparg_lhs_rhs(const char_u *orig_lhs, const size_t orig_lhs_len, const char_u *orig_rhs, - const size_t orig_rhs_len, LuaRef rhs_lua, int cpo_flags, - MapArguments *mapargs) +void set_maparg_lhs_rhs(const char_u *const orig_lhs, const size_t orig_lhs_len, + const char_u *const orig_rhs, const size_t orig_rhs_len, + const LuaRef rhs_lua, const int cpo_flags, MapArguments *const mapargs) { char_u *lhs_buf = NULL; + char_u *alt_lhs_buf = NULL; char_u *rhs_buf = NULL; // If mapping has been given as ^V<C_UP> say, then replace the term codes @@ -2725,10 +2871,22 @@ void set_maparg_lhs_rhs(const char_u *orig_lhs, const size_t orig_lhs_len, const // replace_termcodes() may move the result to allocated memory, which // needs to be freed later (*lhs_buf and *rhs_buf). // replace_termcodes() also removes CTRL-Vs and sometimes backslashes. - char_u *replaced = replace_termcodes(orig_lhs, orig_lhs_len, &lhs_buf, - true, true, true, cpo_flags); + // If something like <C-H> is simplified to 0x08 then mark it as simplified. + bool did_simplify = false; + const int flags = REPTERM_FROM_PART | REPTERM_DO_LT; + char_u *replaced = replace_termcodes(orig_lhs, orig_lhs_len, &lhs_buf, flags, &did_simplify, + cpo_flags); mapargs->lhs_len = STRLEN(replaced); STRLCPY(mapargs->lhs, replaced, sizeof(mapargs->lhs)); + if (did_simplify) { + replaced = replace_termcodes(orig_lhs, orig_lhs_len, &alt_lhs_buf, flags | REPTERM_NO_SIMPLIFY, + NULL, cpo_flags); + mapargs->alt_lhs_len = STRLEN(replaced); + STRLCPY(mapargs->alt_lhs, replaced, sizeof(mapargs->alt_lhs)); + } else { + mapargs->alt_lhs_len = 0; + } + mapargs->rhs_lua = rhs_lua; if (rhs_lua == LUA_NOREF) { @@ -2742,7 +2900,7 @@ void set_maparg_lhs_rhs(const char_u *orig_lhs, const size_t orig_lhs_len, const mapargs->rhs_is_noop = true; } else { replaced = replace_termcodes(orig_rhs, orig_rhs_len, &rhs_buf, - false, true, true, cpo_flags); + REPTERM_DO_LT | REPTERM_NO_SIMPLIFY, NULL, cpo_flags); mapargs->rhs_len = STRLEN(replaced); mapargs->rhs_is_noop = false; mapargs->rhs = xcalloc(mapargs->rhs_len + 1, sizeof(char_u)); @@ -2760,6 +2918,7 @@ void set_maparg_lhs_rhs(const char_u *orig_lhs, const size_t orig_lhs_len, const } xfree(lhs_buf); + xfree(alt_lhs_buf); xfree(rhs_buf); } @@ -2894,15 +3053,9 @@ int str_to_mapargs(const char_u *strargs, bool is_unmap, MapArguments *mapargs) int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T *buf) { mapblock_T *mp, **mpp; - char_u *p; + const char_u *p; int n; - int len = 0; // init for GCC - int did_it = false; - int did_local = false; - int round; int retval = 0; - int hash; - int new_hash; mapblock_T **abbr_table; mapblock_T **map_table; int noremap; @@ -2929,8 +3082,9 @@ int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T validate_maphash(); - bool has_lhs = (args->lhs[0] != NUL); - bool has_rhs = args->rhs_lua != LUA_NOREF || (args->rhs[0] != NUL) || args->rhs_is_noop; + const bool has_lhs = (args->lhs[0] != NUL); + const bool has_rhs = args->rhs_lua != LUA_NOREF || (args->rhs[0] != NUL) || args->rhs_is_noop; + const bool do_print = !has_lhs || (maptype != 1 && !has_rhs); // check for :unmap without argument if (maptype == 1 && !has_lhs) { @@ -2938,298 +3092,343 @@ int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T goto theend; } - char_u *lhs = (char_u *)&args->lhs; - char_u *rhs = args->rhs; - char_u *orig_rhs = args->orig_rhs; + const char_u *lhs = (char_u *)&args->lhs; + const char_u *const rhs = args->rhs; + const char_u *const orig_rhs = args->orig_rhs; + const bool did_simplify = args->alt_lhs_len != 0; - // check arguments and translate function keys - if (has_lhs) { - len = (int)args->lhs_len; - if (len > MAXMAPLEN) { - retval = 1; - goto theend; - } + // The following is done twice if we have two versions of keys + for (int keyround = 1; keyround <= 2; keyround++) { + bool did_it = false; + bool did_local = false; + bool keyround1_simplified = keyround == 1 && did_simplify; + int len = (int)args->lhs_len; - if (is_abbrev && maptype != 1) { - // - // If an abbreviation ends in a keyword character, the - // rest must be all keyword-char or all non-keyword-char. - // Otherwise we won't be able to find the start of it in a - // vi-compatible way. - // - int same = -1; - - const int first = vim_iswordp(lhs); - int last = first; - p = lhs + utfc_ptr2len(lhs); - n = 1; - while (p < lhs + len) { - n++; // nr of (multi-byte) chars - last = vim_iswordp(p); // type of last char - if (same == -1 && last != first) { - same = n - 1; // count of same char type - } - p += utfc_ptr2len(p); + if (keyround == 2) { + if (!did_simplify) { + break; } - if (last && n > 2 && same >= 0 && same < n - 1) { + lhs = (char_u *)&args->alt_lhs; + len = (int)args->alt_lhs_len; + } else if (did_simplify && do_print) { + // when printing always use the not-simplified map + lhs = (char_u *)&args->alt_lhs; + len = (int)args->alt_lhs_len; + } + + // check arguments and translate function keys + if (has_lhs) { + if (len > MAXMAPLEN) { retval = 1; goto theend; } - // An abbreviation cannot contain white space. - for (n = 0; n < len; n++) { - if (ascii_iswhite(lhs[n])) { + + if (is_abbrev && maptype != 1) { + // + // If an abbreviation ends in a keyword character, the + // rest must be all keyword-char or all non-keyword-char. + // Otherwise we won't be able to find the start of it in a + // vi-compatible way. + // + int same = -1; + + const int first = vim_iswordp(lhs); + int last = first; + p = lhs + utfc_ptr2len(lhs); + n = 1; + while (p < lhs + len) { + n++; // nr of (multi-byte) chars + last = vim_iswordp(p); // type of last char + if (same == -1 && last != first) { + same = n - 1; // count of same char type + } + p += utfc_ptr2len(p); + } + if (last && n > 2 && same >= 0 && same < n - 1) { retval = 1; goto theend; } - } // for + // An abbreviation cannot contain white space. + for (n = 0; n < len; n++) { + if (ascii_iswhite(lhs[n])) { + retval = 1; + goto theend; + } + } // for + } } - } - if (has_lhs && has_rhs && is_abbrev) { // if we will add an abbreviation, - no_abbr = false; // reset flag that indicates there are no abbreviations - } + if (has_lhs && has_rhs && is_abbrev) { // if we will add an abbreviation, + no_abbr = false; // reset flag that indicates there are no abbreviations + } - if (!has_lhs || (maptype != 1 && !has_rhs)) { - msg_start(); - } + if (do_print) { + msg_start(); + } - // Check if a new local mapping wasn't already defined globally. - if (map_table == buf->b_maphash && has_lhs && has_rhs && maptype != 1) { - // need to loop over all global hash lists - for (hash = 0; hash < 256 && !got_int; hash++) { - if (is_abbrev) { - if (hash != 0) { // there is only one abbreviation list - break; + // Check if a new local mapping wasn't already defined globally. + if (map_table == buf->b_maphash && has_lhs && has_rhs && maptype != 1) { + // need to loop over all global hash lists + for (int hash = 0; hash < 256 && !got_int; hash++) { + if (is_abbrev) { + if (hash != 0) { // there is only one abbreviation list + break; + } + mp = first_abbr; + } else { + mp = maphash[hash]; } - mp = first_abbr; - } else { - mp = maphash[hash]; - } - for (; mp != NULL && !got_int; mp = mp->m_next) { - // check entries with the same mode - if ((mp->m_mode & mode) != 0 - && mp->m_keylen == len - && args->unique - && STRNCMP(mp->m_keys, lhs, (size_t)len) == 0) { - if (is_abbrev) { - semsg(_("E224: global abbreviation already exists for %s"), - mp->m_keys); - } else { - semsg(_("E225: global mapping already exists for %s"), mp->m_keys); + for (; mp != NULL && !got_int; mp = mp->m_next) { + // check entries with the same mode + if ((mp->m_mode & mode) != 0 + && mp->m_keylen == len + && args->unique + && STRNCMP(mp->m_keys, lhs, (size_t)len) == 0) { + if (is_abbrev) { + semsg(_("E224: global abbreviation already exists for %s"), + mp->m_keys); + } else { + semsg(_("E225: global mapping already exists for %s"), mp->m_keys); + } + retval = 5; + goto theend; } - retval = 5; - goto theend; } } } - } - // When listing global mappings, also list buffer-local ones here. - if (map_table != buf->b_maphash && !has_rhs && maptype != 1) { - // need to loop over all global hash lists - for (hash = 0; hash < 256 && !got_int; hash++) { - if (is_abbrev) { - if (hash != 0) { // there is only one abbreviation list - break; + // When listing global mappings, also list buffer-local ones here. + if (map_table != buf->b_maphash && !has_rhs && maptype != 1) { + // need to loop over all global hash lists + for (int hash = 0; hash < 256 && !got_int; hash++) { + if (is_abbrev) { + if (hash != 0) { // there is only one abbreviation list + break; + } + mp = buf->b_first_abbr; + } else { + mp = buf->b_maphash[hash]; } - mp = buf->b_first_abbr; - } else { - mp = buf->b_maphash[hash]; - } - for (; mp != NULL && !got_int; mp = mp->m_next) { - // check entries with the same mode - if ((mp->m_mode & mode) != 0) { - if (!has_lhs) { // show all entries - showmap(mp, true); - did_local = true; - } else { - n = mp->m_keylen; - if (STRNCMP(mp->m_keys, lhs, (size_t)(n < len ? n : len)) == 0) { + for (; mp != NULL && !got_int; mp = mp->m_next) { + // check entries with the same mode + if (!mp->m_simplified && (mp->m_mode & mode) != 0) { + if (!has_lhs) { // show all entries showmap(mp, true); did_local = true; + } else { + n = mp->m_keylen; + if (STRNCMP(mp->m_keys, lhs, (size_t)(n < len ? n : len)) == 0) { + showmap(mp, true); + did_local = true; + } } } } } } - } - // Find an entry in the maphash[] list that matches. - // For :unmap we may loop two times: once to try to unmap an entry with a - // matching 'from' part, a second time, if the first fails, to unmap an - // entry with a matching 'to' part. This was done to allow ":ab foo bar" - // to be unmapped by typing ":unab foo", where "foo" will be replaced by - // "bar" because of the abbreviation. - for (round = 0; (round == 0 || maptype == 1) && round <= 1 - && !did_it && !got_int; round++) { - // need to loop over all hash lists - for (hash = 0; hash < 256 && !got_int; hash++) { - if (is_abbrev) { - if (hash > 0) { // there is only one abbreviation list - break; - } - mpp = abbr_table; - } else { - mpp = &(map_table[hash]); - } - for (mp = *mpp; mp != NULL && !got_int; mp = *mpp) { - if (!(mp->m_mode & mode)) { // skip entries with wrong mode - mpp = &(mp->m_next); - continue; + // Find an entry in the maphash[] list that matches. + // For :unmap we may loop two times: once to try to unmap an entry with a + // matching 'from' part, a second time, if the first fails, to unmap an + // entry with a matching 'to' part. This was done to allow ":ab foo bar" + // to be unmapped by typing ":unab foo", where "foo" will be replaced by + // "bar" because of the abbreviation. + for (int round = 0; (round == 0 || maptype == 1) && round <= 1 + && !did_it && !got_int; round++) { + // need to loop over all hash lists + for (int hash = 0; hash < 256 && !got_int; hash++) { + if (is_abbrev) { + if (hash > 0) { // there is only one abbreviation list + break; + } + mpp = abbr_table; + } else { + mpp = &(map_table[hash]); } - if (!has_lhs) { // show all entries - showmap(mp, map_table != maphash); - did_it = true; - } else { // do we have a match? - if (round) { // second round: Try unmap "rhs" string - n = (int)STRLEN(mp->m_str); - p = mp->m_str; - } else { - n = mp->m_keylen; - p = mp->m_keys; + for (mp = *mpp; mp != NULL && !got_int; mp = *mpp) { + if ((mp->m_mode & mode) == 0) { + // skip entries with wrong mode + mpp = &(mp->m_next); + continue; } - if (STRNCMP(p, lhs, (size_t)(n < len ? n : len)) == 0) { - if (maptype == 1) { // delete entry - // Only accept a full match. For abbreviations we - // ignore trailing space when matching with the - // "lhs", since an abbreviation can't have - // trailing space. - if (n != len && (!is_abbrev || round || n > len - || *skipwhite(lhs + n) != NUL)) { - mpp = &(mp->m_next); - continue; - } - // We reset the indicated mode bits. If nothing is - // left the entry is deleted below. - mp->m_mode &= ~mode; - did_it = true; // remember we did something - } else if (!has_rhs) { // show matching entry + if (!has_lhs) { // show all entries + if (!mp->m_simplified) { showmap(mp, map_table != maphash); did_it = true; - } else if (n != len) { // new entry is ambiguous - mpp = &(mp->m_next); - continue; - } else if (args->unique) { - if (is_abbrev) { - semsg(_("E226: abbreviation already exists for %s"), p); - } else { - semsg(_("E227: mapping already exists for %s"), p); - } - retval = 5; - goto theend; - } else { // new rhs for existing entry - mp->m_mode &= ~mode; // remove mode bits - if (mp->m_mode == 0 && !did_it) { // reuse entry - XFREE_CLEAR(mp->m_str); - XFREE_CLEAR(mp->m_orig_str); - XFREE_CLEAR(mp->m_desc); - NLUA_CLEAR_REF(mp->m_luaref); - - mp->m_str = vim_strsave(rhs); - mp->m_orig_str = vim_strsave(orig_rhs); - mp->m_luaref = args->rhs_lua; - mp->m_noremap = noremap; - mp->m_nowait = args->nowait; - mp->m_silent = args->silent; - mp->m_mode = mode; - mp->m_expr = args->expr; - mp->m_script_ctx = current_sctx; - mp->m_script_ctx.sc_lnum += sourcing_lnum; - nlua_set_sctx(&mp->m_script_ctx); - if (args->desc != NULL) { - mp->m_desc = xstrdup(args->desc); + } + } else { // do we have a match? + if (round) { // second round: Try unmap "rhs" string + n = (int)STRLEN(mp->m_str); + p = mp->m_str; + } else { + n = mp->m_keylen; + p = mp->m_keys; + } + if (STRNCMP(p, lhs, (size_t)(n < len ? n : len)) == 0) { + if (maptype == 1) { + // Delete entry. + // Only accept a full match. For abbreviations + // we ignore trailing space when matching with + // the "lhs", since an abbreviation can't have + // trailing space. + if (n != len && (!is_abbrev || round || n > len + || *skipwhite(lhs + n) != NUL)) { + mpp = &(mp->m_next); + continue; + } + // In keyround for simplified keys, don't unmap + // a mapping without m_simplified flag. + if (keyround1_simplified && !mp->m_simplified) { + break; } + // We reset the indicated mode bits. If nothing + // is left the entry is deleted below. + mp->m_mode &= ~mode; + did_it = true; // remember we did something + } else if (!has_rhs) { // show matching entry + if (!mp->m_simplified) { + showmap(mp, map_table != maphash); + did_it = true; + } + } else if (n != len) { // new entry is ambiguous + mpp = &(mp->m_next); + continue; + } else if (keyround1_simplified && !mp->m_simplified) { + // In keyround for simplified keys, don't replace + // a mapping without m_simplified flag. did_it = true; + break; + } else if (args->unique) { + if (is_abbrev) { + semsg(_("E226: abbreviation already exists for %s"), p); + } else { + semsg(_("E227: mapping already exists for %s"), p); + } + retval = 5; + goto theend; + } else { + // new rhs for existing entry + mp->m_mode &= ~mode; // remove mode bits + if (mp->m_mode == 0 && !did_it) { // reuse entry + XFREE_CLEAR(mp->m_str); + XFREE_CLEAR(mp->m_orig_str); + XFREE_CLEAR(mp->m_desc); + if (!mp->m_simplified) { + NLUA_CLEAR_REF(mp->m_luaref); + } + + mp->m_str = vim_strsave(rhs); + mp->m_orig_str = vim_strsave(orig_rhs); + mp->m_luaref = args->rhs_lua; + mp->m_noremap = noremap; + mp->m_nowait = args->nowait; + mp->m_silent = args->silent; + mp->m_mode = mode; + mp->m_simplified = keyround1_simplified; + mp->m_expr = args->expr; + mp->m_script_ctx = current_sctx; + mp->m_script_ctx.sc_lnum += sourcing_lnum; + nlua_set_sctx(&mp->m_script_ctx); + if (args->desc != NULL) { + mp->m_desc = xstrdup(args->desc); + } + did_it = true; + } + } + if (mp->m_mode == 0) { // entry can be deleted + mapblock_free(mpp); + continue; // continue with *mpp } - } - if (mp->m_mode == 0) { // entry can be deleted - mapblock_free(mpp); - continue; // continue with *mpp - } - // May need to put this entry into another hash list. - new_hash = MAP_HASH(mp->m_mode, mp->m_keys[0]); - if (!is_abbrev && new_hash != hash) { - *mpp = mp->m_next; - mp->m_next = map_table[new_hash]; - map_table[new_hash] = mp; + // May need to put this entry into another hash list. + int new_hash = MAP_HASH(mp->m_mode, mp->m_keys[0]); + if (!is_abbrev && new_hash != hash) { + *mpp = mp->m_next; + mp->m_next = map_table[new_hash]; + map_table[new_hash] = mp; - continue; // continue with *mpp + continue; // continue with *mpp + } } } + mpp = &(mp->m_next); } - mpp = &(mp->m_next); } } - } - if (maptype == 1) { // delete entry - if (!did_it) { - retval = 2; // no match - } else if (*lhs == Ctrl_C) { - // If CTRL-C has been unmapped, reuse it for Interrupting. - if (map_table == buf->b_maphash) { - buf->b_mapped_ctrl_c &= ~mode; - } else { - mapped_ctrl_c &= ~mode; + if (maptype == 1) { + // delete entry + if (!did_it) { + if (!keyround1_simplified) { + retval = 2; // no match + } + } else if (*lhs == Ctrl_C) { + // If CTRL-C has been unmapped, reuse it for Interrupting. + if (map_table == buf->b_maphash) { + buf->b_mapped_ctrl_c &= ~mode; + } else { + mapped_ctrl_c &= ~mode; + } } + continue; } - goto theend; - } - if (!has_lhs || !has_rhs) { // print entries - if (!did_it && !did_local) { - if (is_abbrev) { - msg(_("No abbreviation found")); - } else { - msg(_("No mapping found")); + if (!has_lhs || !has_rhs) { + // print entries + if (!did_it && !did_local) { + if (is_abbrev) { + msg(_("No abbreviation found")); + } else { + msg(_("No mapping found")); + } } + goto theend; // listing finished } - goto theend; // listing finished - } - if (did_it) { // have added the new entry already - goto theend; - } + if (did_it) { + continue; // have added the new entry already + } - // Get here when adding a new entry to the maphash[] list or abbrlist. - mp = xmalloc(sizeof(mapblock_T)); + // Get here when adding a new entry to the maphash[] list or abbrlist. + mp = xmalloc(sizeof(mapblock_T)); - // If CTRL-C has been mapped, don't always use it for Interrupting. - if (*lhs == Ctrl_C) { - if (map_table == buf->b_maphash) { - buf->b_mapped_ctrl_c |= mode; - } else { - mapped_ctrl_c |= mode; + // If CTRL-C has been mapped, don't always use it for Interrupting. + if (*lhs == Ctrl_C) { + if (map_table == buf->b_maphash) { + buf->b_mapped_ctrl_c |= mode; + } else { + mapped_ctrl_c |= mode; + } } - } - mp->m_keys = vim_strsave(lhs); - mp->m_str = vim_strsave(rhs); - mp->m_orig_str = vim_strsave(orig_rhs); - mp->m_luaref = args->rhs_lua; - mp->m_keylen = (int)STRLEN(mp->m_keys); - mp->m_noremap = noremap; - mp->m_nowait = args->nowait; - mp->m_silent = args->silent; - mp->m_mode = mode; - mp->m_expr = args->expr; - mp->m_script_ctx = current_sctx; - mp->m_script_ctx.sc_lnum += sourcing_lnum; - nlua_set_sctx(&mp->m_script_ctx); - mp->m_desc = NULL; - if (args->desc != NULL) { - mp->m_desc = xstrdup(args->desc); - } - - // add the new entry in front of the abbrlist or maphash[] list - if (is_abbrev) { - mp->m_next = *abbr_table; - *abbr_table = mp; - } else { - n = MAP_HASH(mp->m_mode, mp->m_keys[0]); - mp->m_next = map_table[n]; - map_table[n] = mp; + mp->m_keys = vim_strsave(lhs); + mp->m_str = vim_strsave(rhs); + mp->m_orig_str = vim_strsave(orig_rhs); + mp->m_luaref = args->rhs_lua; + mp->m_keylen = (int)STRLEN(mp->m_keys); + mp->m_noremap = noremap; + mp->m_nowait = args->nowait; + mp->m_silent = args->silent; + mp->m_mode = mode; + mp->m_simplified = keyround1_simplified; // Notice this when porting patch 8.2.0807 + mp->m_expr = args->expr; + mp->m_script_ctx = current_sctx; + mp->m_script_ctx.sc_lnum += sourcing_lnum; + nlua_set_sctx(&mp->m_script_ctx); + mp->m_desc = NULL; + if (args->desc != NULL) { + mp->m_desc = xstrdup(args->desc); + } + + // add the new entry in front of the abbrlist or maphash[] list + if (is_abbrev) { + mp->m_next = *abbr_table; + *abbr_table = mp; + } else { + n = MAP_HASH(mp->m_mode, mp->m_keys[0]); + mp->m_next = map_table[n]; + map_table[n] = mp; + } } theend: @@ -3317,7 +3516,9 @@ static void mapblock_free(mapblock_T **mpp) mp = *mpp; xfree(mp->m_keys); - NLUA_CLEAR_REF(mp->m_luaref); + if (!mp->m_simplified) { + NLUA_CLEAR_REF(mp->m_luaref); + } XFREE_CLEAR(mp->m_str); XFREE_CLEAR(mp->m_orig_str); XFREE_CLEAR(mp->m_desc); @@ -3600,9 +3801,8 @@ bool map_to_exists(const char *const str, const char *const modechars, const boo int retval; char_u *buf; - char_u *const rhs = replace_termcodes((const char_u *)str, strlen(str), &buf, - false, true, true, - CPO_TO_CPO_FLAGS); + const char_u *const rhs = replace_termcodes((const char_u *)str, strlen(str), &buf, REPTERM_DO_LT, + NULL, CPO_TO_CPO_FLAGS); #define MAPMODE(mode, modechars, chr, modeflags) \ do { \ @@ -4675,15 +4875,21 @@ char_u *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) // special case to give nicer error message emsg(e_cmdmap_repeated); aborted = true; - } else if (IS_SPECIAL(c1)) { - if (c1 == K_SNR) { - ga_concat(&line_ga, "<SNR>"); + } else if (c1 == K_SNR) { + ga_concat(&line_ga, "<SNR>"); + } else { + if (cmod != 0) { + ga_append(&line_ga, (char)K_SPECIAL); + ga_append(&line_ga, (char)KS_MODIFIER); + ga_append(&line_ga, (char)cmod); + } + if (IS_SPECIAL(c1)) { + ga_append(&line_ga, (char)K_SPECIAL); + ga_append(&line_ga, (char)K_SECOND(c1)); + ga_append(&line_ga, (char)K_THIRD(c1)); } else { - semsg(e_cmdmap_key, get_special_key_name(c1, cmod)); - aborted = true; + ga_append(&line_ga, (char)c1); } - } else { - ga_append(&line_ga, (char)c1); } cmod = 0; diff --git a/src/nvim/getchar.h b/src/nvim/getchar.h index 9b8605f1df..237f0632bd 100644 --- a/src/nvim/getchar.h +++ b/src/nvim/getchar.h @@ -48,6 +48,10 @@ struct map_arguments { char_u lhs[MAXMAPLEN + 1]; size_t lhs_len; + /// Unsimplifed {lhs} of the mapping. If no simplification has been done then alt_lhs_len is 0. + char_u alt_lhs[MAXMAPLEN + 1]; + size_t alt_lhs_len; + char_u *rhs; /// The {rhs} of the mapping. size_t rhs_len; LuaRef rhs_lua; /// lua function as rhs @@ -59,7 +63,7 @@ struct map_arguments { }; typedef struct map_arguments MapArguments; #define MAP_ARGUMENTS_INIT { false, false, false, false, false, false, false, \ - { 0 }, 0, NULL, 0, LUA_NOREF, false, NULL, 0, NULL } + { 0 }, 0, { 0 }, 0, NULL, 0, LUA_NOREF, false, NULL, 0, NULL } #define KEYLEN_PART_KEY (-1) // keylen value for incomplete key-code #define KEYLEN_PART_MAP (-2) // keylen value for incomplete mapping diff --git a/src/nvim/globals.h b/src/nvim/globals.h index e07a0e22ca..6443759a39 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -15,7 +15,7 @@ #include "nvim/syntax_defs.h" #include "nvim/types.h" -#define IOSIZE (1024+1) // file I/O and sprintf buffer size +#define IOSIZE (1024 + 1) // file I/O and sprintf buffer size #define MSG_BUF_LEN 480 // length of buffer for small messages #define MSG_BUF_CLEN (MSG_BUF_LEN / 6) // cell length (worst case: utf-8 @@ -129,6 +129,9 @@ typedef off_t off_T; // held down based on the MOD_MASK_* symbols that are read first. EXTERN int mod_mask INIT(= 0); // current key modifiers +// The value of "mod_mask" and the unmodified character before calling merge_modifiers(). +EXTERN int vgetc_mod_mask INIT(= 0); +EXTERN int vgetc_char INIT(= 0); // Cmdline_row is the row where the command line starts, just below the // last window. @@ -649,6 +652,7 @@ EXTERN int reg_recorded INIT(= 0); // last recorded register or zero EXTERN int no_mapping INIT(= false); // currently no mapping allowed EXTERN int no_zero_mapping INIT(= 0); // mapping zero not allowed +EXTERN int allow_keys INIT(= false); // allow key codes when no_mapping is set EXTERN int no_u_sync INIT(= 0); // Don't call u_sync() EXTERN int u_sync_once INIT(= 0); // Call u_sync() once when evaluating // an expression. @@ -666,6 +670,7 @@ EXTERN bool ins_at_eol INIT(= false); // put cursor after eol when EXTERN bool no_abbr INIT(= true); // true when no abbreviations loaded EXTERN int mapped_ctrl_c INIT(= 0); // Modes where CTRL-C is mapped. +EXTERN bool ctrl_c_interrupts INIT(= true); // CTRL-C sets got_int EXTERN cmdmod_T cmdmod; // Ex command modifiers @@ -993,8 +998,8 @@ EXTERN char e_float_as_string[] INIT(= N_("E806: using Float as a String")); EXTERN char e_autocmd_err[] INIT(= N_("E5500: autocmd has thrown an exception: %s")); EXTERN char e_cmdmap_err[] INIT(= N_("E5520: <Cmd> mapping must end with <CR>")); -EXTERN char e_cmdmap_repeated[] INIT(= N_("E5521: <Cmd> mapping must end with <CR> before second <Cmd>")); -EXTERN char e_cmdmap_key[] INIT(= N_("E5522: <Cmd> mapping must not include %s key")); +EXTERN char e_cmdmap_repeated[] +INIT(= N_("E5521: <Cmd> mapping must end with <CR> before second <Cmd>")); EXTERN char e_api_error[] INIT(= N_("E5555: API call: %s")); diff --git a/src/nvim/grid_defs.h b/src/nvim/grid_defs.h index bf0a5d63a8..69eca5d123 100644 --- a/src/nvim/grid_defs.h +++ b/src/nvim/grid_defs.h @@ -10,7 +10,7 @@ #define MAX_MCO 6 // fixed value for 'maxcombine' // The characters and attributes drawn on grids. -typedef char_u schar_T[(MAX_MCO+1) * 4 + 1]; +typedef char_u schar_T[(MAX_MCO + 1) * 4 + 1]; typedef int sattr_T; enum { diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 8e03a8827c..a6e7ba9fc1 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -374,8 +374,8 @@ static char *parse_list_options(char_u *option_str, option_table_T *table, size_ static uint32_t darken_rgb(uint32_t rgb) { return ((rgb >> 17) << 16) - + (((rgb & 0xff00) >> 9) << 8) - + ((rgb & 0xff) >> 1); + + (((rgb & 0xff00) >> 9) << 8) + + ((rgb & 0xff) >> 1); } static uint32_t prt_get_term_color(int colorindex) @@ -3195,4 +3195,3 @@ void mch_print_set_fg(uint32_t fgcol) prt_need_fgcol = true; } } - diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index 7d91f38d56..90ca0047bd 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -213,7 +213,7 @@ int ns_get_hl(NS ns_id, int hl_id, bool link, bool nodefault) } it.attr_id = fallback ? -1 : hl_get_syn_attr((int)ns_id, hl_id, attrs); - it.version = p->hl_valid-tmp; + it.version = p->hl_valid - tmp; it.is_default = attrs.rgb_ae_attr & HL_DEFAULT; map_put(ColorKey, ColorItem)(&ns_hl, ColorKey(ns_id, hl_id), it); } @@ -602,7 +602,7 @@ int hl_blend_attrs(int back_attr, int front_attr, bool *through) static int rgb_blend(int ratio, int rgb1, int rgb2) { - int a = ratio, b = 100-ratio; + int a = ratio, b = 100 - ratio; int r1 = (rgb1 & 0xFF0000) >> 16; int g1 = (rgb1 & 0x00FF00) >> 8; int b1 = (rgb1 & 0x0000FF) >> 0; diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index a9ced84280..45c7863d00 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -4,8 +4,9 @@ // highlight_group.c: code for managing highlight groups #include <stdbool.h> -#include "nvim/autocmd.h" + #include "nvim/api/private/helpers.h" +#include "nvim/autocmd.h" #include "nvim/charset.h" #include "nvim/cursor_shape.h" #include "nvim/fold.h" @@ -34,11 +35,11 @@ Map(cstr_t, int) highlight_unames = MAP_INIT; /// The "term", "cterm" and "gui" arguments can be any combination of the /// following names, separated by commas (but no spaces!). static char *(hl_name_table[]) = - { "bold", "standout", "underline", "underlineline", "undercurl", "underdot", - "underdash", "italic", "reverse", "inverse", "strikethrough", "nocombine", "NONE" }; +{ "bold", "standout", "underline", "underlineline", "undercurl", "underdot", + "underdash", "italic", "reverse", "inverse", "strikethrough", "nocombine", "NONE" }; static int hl_attr_table[] = - { HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERLINELINE, HL_UNDERCURL, HL_UNDERDOT, HL_UNDERDASH, - HL_ITALIC, HL_INVERSE, HL_INVERSE, HL_STRIKETHROUGH, HL_NOCOMBINE, 0 }; +{ HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERLINELINE, HL_UNDERCURL, HL_UNDERDOT, HL_UNDERDASH, + HL_ITALIC, HL_INVERSE, HL_INVERSE, HL_STRIKETHROUGH, HL_NOCOMBINE, 0 }; /// Structure that stores information about a highlight group. /// The ID of a highlight group is also called group ID. It is the index in @@ -618,10 +619,10 @@ static int color_numbers_256[28] = { 0, 4, 2, 6, static int color_numbers_8[28] = { 0, 4, 2, 6, 1, 5, 3, 3, 7, 7, 7, 7, - 0+8, 0+8, - 4+8, 4+8, 2+8, 2+8, - 6+8, 6+8, 1+8, 1+8, 5+8, - 5+8, 3+8, 3+8, 7+8, -1 }; + 0 + 8, 0 + 8, + 4 + 8, 4 + 8, 2 + 8, 2 + 8, + 6 + 8, 6 + 8, 1 + 8, 1 + 8, 5 + 8, + 5 + 8, 3 + 8, 3 + 8, 7 + 8, -1 }; // Lookup the "cterm" value to be used for color with index "idx" in // color_names[]. @@ -963,7 +964,7 @@ void do_highlight(const char *line, const bool forceit, const bool init) if (strcmp(key, "NONE") == 0) { if (!init || HL_TABLE()[idx].sg_set == 0) { if (!init) { - HL_TABLE()[idx].sg_set |= SG_CTERM+SG_GUI; + HL_TABLE()[idx].sg_set |= SG_CTERM + SG_GUI; } highlight_clear(idx); } @@ -1384,7 +1385,7 @@ static void highlight_list_one(const int id) 0, sgp->sg_rgb_sp_name, "guisp"); didh = highlight_list_arg(id, didh, LIST_INT, - sgp->sg_blend+1, NULL, "blend"); + sgp->sg_blend + 1, NULL, "blend"); if (sgp->sg_link && !got_int) { (void)syn_list_header(didh, 0, id, true); @@ -1572,8 +1573,7 @@ const char *highlight_color(const int id, const char *const what, const int mode /// @param id highlight group id /// @param force_newline always start a new line /// @return true when started a new line. -bool syn_list_header(const bool did_header, const int outlen, const int id, - bool force_newline) +bool syn_list_header(const bool did_header, const int outlen, const int id, bool force_newline) { int endcol = 19; bool newline = true; @@ -1643,10 +1643,10 @@ static void set_hl_attr(int idx) at_en.rgb_sp_color = sgp->sg_rgb_sp_name ? sgp->sg_rgb_sp : -1; at_en.hl_blend = sgp->sg_blend; - sgp->sg_attr = hl_get_syn_attr(0, idx+1, at_en); + sgp->sg_attr = hl_get_syn_attr(0, idx + 1, at_en); // a cursor style uses this syn_id, make sure its attribute is updated. - if (cursor_mode_uses_syn_id(idx+1)) { + if (cursor_mode_uses_syn_id(idx + 1)) { ui_mode_info_set(); } } @@ -2787,7 +2787,7 @@ int name_to_ctermcolor(const char *name) int off = TOUPPER_ASC(*name); for (i = ARRAY_SIZE(color_names); --i >= 0;) { if (off == color_names[i][0] - && STRICMP(name+1, color_names[i]+1) == 0) { + && STRICMP(name + 1, color_names[i] + 1) == 0) { break; } } diff --git a/src/nvim/highlight_group.h b/src/nvim/highlight_group.h index 325113a4ab..1474588889 100644 --- a/src/nvim/highlight_group.h +++ b/src/nvim/highlight_group.h @@ -1,8 +1,8 @@ #ifndef NVIM_HIGHLIGHT_GROUP_H #define NVIM_HIGHLIGHT_GROUP_H -#include "nvim/types.h" #include "nvim/eval.h" +#include "nvim/types.h" #define MAX_HL_ID 20000 // maximum value for a highlight ID. diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 56517c1741..2f34c8f27b 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -460,9 +460,9 @@ staterr: if (S_ISDIR(file_info.stat.st_mode)) { fname2 = (char *)xmalloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2); - while (fname[strlen(fname)-1] == '/' + while (fname[strlen(fname) - 1] == '/' ) { - fname[strlen(fname)-1] = '\0'; + fname[strlen(fname) - 1] = '\0'; if (fname[0] == '\0') { break; } @@ -1444,8 +1444,7 @@ retry: // If the line's too long for the buffer, discard it. if ((p = strchr(buf, '\n')) == NULL) { - while ((ch = getc(csinfo[cnumber].fr_fp)) != EOF && ch != '\n') { - } + while ((ch = getc(csinfo[cnumber].fr_fp)) != EOF && ch != '\n') {} return NULL; } *p = '\0'; @@ -1594,8 +1593,7 @@ static char *cs_pathcomponents(char *path) char *s = path + strlen(path) - 1; for (int i = 0; i < p_cspc; i++) { - while (s > path && *--s != '/') { - } + while (s > path && *--s != '/') {} } if ((s > path && *s == '/')) { s++; diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 59ba2c92f7..2659c2c175 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -356,7 +356,7 @@ int set_indent(int size, int flags) ml_replace(curwin->w_cursor.lnum, newline, false); if (!(flags & SIN_NOMARK)) { extmark_splice_cols(curbuf, - (int)curwin->w_cursor.lnum-1, + (int)curwin->w_cursor.lnum - 1, skipcols, old_offset - skipcols, new_offset - skipcols, diff --git a/src/nvim/input.c b/src/nvim/input.c index ff6b559710..6827dcae87 100644 --- a/src/nvim/input.c +++ b/src/nvim/input.c @@ -42,6 +42,7 @@ int ask_yesno(const char *const str, const bool direct) State = CONFIRM; // Mouse behaves like with :confirm. setmouse(); // Disable mouse in xterm. no_mapping++; + allow_keys++; // no mapping here, but recognize keys int r = ' '; while (r != 'y' && r != 'n') { @@ -62,6 +63,7 @@ int ask_yesno(const char *const str, const bool direct) State = save_State; setmouse(); no_mapping--; + allow_keys--; return r; } @@ -172,6 +174,7 @@ int get_number(int colon, int *mouse_used) } no_mapping++; + allow_keys++; // no mapping here, but recognize keys for (;;) { ui_cursor_goto(msg_row, msg_col); c = safe_vgetc(); @@ -205,6 +208,7 @@ int get_number(int colon, int *mouse_used) } } no_mapping--; + allow_keys--; return n; } diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index 3fdc140ebd..db51237771 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -568,23 +568,21 @@ char_u *get_special_key_name(int c, int modifiers) /// @param[in] src_len Length of the srcp. /// @param[out] dst Location where translation result will be kept. It must // be at least 19 bytes per "<x>" form. -/// @param[in] keycode Prefer key code, e.g. K_DEL in place of DEL. -/// @param[in] in_string Inside a double quoted string +/// @param[in] flags FSK_ values +/// @param[out] did_simplify found <C-H>, etc. /// /// @return Number of characters added to dst, zero for no match. -unsigned int trans_special(const char_u **srcp, const size_t src_len, char_u *const dst, - const bool keycode, const bool in_string) - FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT +unsigned int trans_special(const char_u **const srcp, const size_t src_len, char_u *const dst, + const int flags, bool *const did_simplify) + FUNC_ATTR_NONNULL_ARG(1, 3) FUNC_ATTR_WARN_UNUSED_RESULT { int modifiers = 0; - int key; - - key = find_special_key(srcp, src_len, &modifiers, keycode, false, in_string); + int key = find_special_key(srcp, src_len, &modifiers, flags, did_simplify); if (key == 0) { return 0; } - return special_to_buf(key, modifiers, keycode, dst); + return special_to_buf(key, modifiers, flags & FSK_KEYCODE, dst); } /// Put the character sequence for "key" with "modifiers" into "dst" and return @@ -623,20 +621,20 @@ unsigned int special_to_buf(int key, int modifiers, bool keycode, char_u *dst) /// @param[in,out] srcp Translated <> name. Is advanced to after the <> name. /// @param[in] src_len srcp length. /// @param[out] modp Location where information about modifiers is saved. -/// @param[in] keycode Prefer key code, e.g. K_DEL in place of DEL. -/// @param[in] keep_x_key Don’t translate xHome to Home key. -/// @param[in] in_string In string, double quote is escaped +/// @param[in] flags FSK_ values +/// @param[out] did_simplify FSK_SIMPLIFY and found <C-H>, etc. /// /// @return Key and modifiers or 0 if there is no match. -int find_special_key(const char_u **srcp, const size_t src_len, int *const modp, const bool keycode, - const bool keep_x_key, const bool in_string) - FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL +int find_special_key(const char_u **const srcp, const size_t src_len, int *const modp, + const int flags, bool *const did_simplify) + FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1, 3) { const char_u *last_dash; const char_u *end_of_name; const char_u *src; const char_u *bp; const char_u *const end = *srcp + src_len - 1; + const bool in_string = flags & FSK_IN_STRING; int modifiers; int bit; int key; @@ -651,6 +649,9 @@ int find_special_key(const char_u **srcp, const size_t src_len, int *const modp, if (src[0] != '<') { return 0; } + if (src[1] == '*') { // <*xxx>: do not simplify + src++; + } // Find end of modifier list last_dash = src; @@ -662,7 +663,7 @@ int find_special_key(const char_u **srcp, const size_t src_len, int *const modp, // Anything accepted, like <C-?>. // <C-"> or <M-"> are not special in strings as " is // the string delimiter. With a backslash it works: <M-\"> - if (end - bp > l && !(in_string && bp[1] == '"') && bp[l+1] == '>') { + if (end - bp > l && !(in_string && bp[1] == '"') && bp[l + 1] == '>') { bp += l; } else if (end - bp > 2 && in_string && bp[1] == '\\' && bp[2] == '"' && bp[3] == '>') { @@ -723,7 +724,7 @@ int find_special_key(const char_u **srcp, const size_t src_len, int *const modp, key = utf_ptr2char(last_dash + off); } else { key = get_special_key_code(last_dash + off); - if (!keep_x_key) { + if (!(flags & FSK_KEEP_X_KEY)) { key = handle_x_keys(key); } } @@ -736,7 +737,7 @@ int find_special_key(const char_u **srcp, const size_t src_len, int *const modp, // includes the modifier. key = simplify_key(key, &modifiers); - if (!keycode) { + if (!(flags & FSK_KEYCODE)) { // don't want keycode, use single byte code if (key == K_BS) { key = BS; @@ -748,7 +749,7 @@ int find_special_key(const char_u **srcp, const size_t src_len, int *const modp, // Normal Key with modifier: // Try to make a single byte code (except for Alt/Meta modifiers). if (!IS_SPECIAL(key)) { - key = extract_modifiers(key, &modifiers); + key = extract_modifiers(key, &modifiers, flags & FSK_SIMPLIFY, did_simplify); } *modp = modifiers; @@ -762,7 +763,10 @@ int find_special_key(const char_u **srcp, const size_t src_len, int *const modp, /// Try to include modifiers (except alt/meta) in the key. /// Changes "Shift-a" to 'A', "Ctrl-@" to <Nul>, etc. -static int extract_modifiers(int key, int *modp) +/// @param[in] simplify if false, don't do Ctrl +/// @param[out] did_simplify set when it is not NULL and "simplify" is true and +/// Ctrl is removed from modifiers +static int extract_modifiers(int key, int *modp, const bool simplify, bool *const did_simplify) { int modifiers = *modp; @@ -773,15 +777,19 @@ static int extract_modifiers(int key, int *modp) modifiers &= ~MOD_MASK_SHIFT; } } - if ((modifiers & MOD_MASK_CTRL) && ((key >= '?' && key <= '_') || ASCII_ISALPHA(key))) { + // <C-H> and <C-h> mean the same thing, always use "H" + if ((modifiers & MOD_MASK_CTRL) && ASCII_ISALPHA(key)) { key = TOUPPER_ASC(key); - int new_key = CTRL_CHR(key); - if (new_key != TAB && new_key != CAR && new_key != ESC) { - key = new_key; - modifiers &= ~MOD_MASK_CTRL; - if (key == 0) { // <C-@> is <Nul> - key = K_ZERO; - } + } + if (simplify && (modifiers & MOD_MASK_CTRL) + && ((key >= '?' && key <= '_') || ASCII_ISALPHA(key))) { + key = CTRL_CHR(key); + modifiers &= ~MOD_MASK_CTRL; + if (key == NUL) { // <C-@> is <Nul> + key = K_ZERO; + } + if (did_simplify != NULL) { + *did_simplify = true; } } @@ -853,34 +861,31 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag) return 0; // Shouldn't get here } -/// Replace any terminal code strings with the equivalent internal -/// representation +/// Replace any terminal code strings with the equivalent internal representation. +/// +/// Used for the "from" and "to" part of a mapping, and the "to" part of a menu command. +/// Any strings like "<C-UP>" are also replaced, unless `special` is false. +/// K_SPECIAL by itself is replaced by K_SPECIAL KS_SPECIAL KE_FILLER. /// -/// Used for the "from" and "to" part of a mapping, and the "to" part of -/// a menu command. Any strings like "<C-UP>" are also replaced, unless -/// `special` is false. K_SPECIAL by itself is replaced by K_SPECIAL -/// KS_SPECIAL KE_FILLER. +/// When "flags" has REPTERM_FROM_PART, trailing <C-v> is included, otherwise it is removed (to make +/// ":map xx ^V" map xx to nothing). When cpo_flags contains FLAG_CPO_BSLASH, a backslash can be +/// used in place of <C-v>. All other <C-v> characters are removed. /// /// @param[in] from What characters to replace. /// @param[in] from_len Length of the "from" argument. -/// @param[out] bufp Location where results were saved in case of success -/// (allocated). Will be set to NULL in case of failure. -/// @param[in] do_lt If true, also translate <lt>. -/// @param[in] from_part If true, trailing <C-v> is included, otherwise it is -/// removed (to make ":map xx ^V" map xx to nothing). -/// When cpo_flags contains #FLAG_CPO_BSLASH, a backslash -/// can be used in place of <C-v>. All other <C-v> -/// characters are removed. -/// @param[in] special Replace keycodes, e.g. <CR> becomes a "\n" char. -/// @param[in] cpo_flags Relevant flags derived from p_cpo, see -/// #CPO_TO_CPO_FLAGS. +/// @param[out] bufp Location where results were saved in case of success (allocated). +/// Will be set to NULL in case of failure. +/// @param[in] flags REPTERM_FROM_PART see above +/// REPTERM_DO_LT also translate <lt> +/// REPTERM_NO_SPECIAL do not accept <key> notation +/// REPTERM_NO_SIMPLIFY do not simplify <C-H> into 0x08, etc. +/// @param[out] did_simplify set when some <C-H> code was simplied, unless it is NULL. +/// @param[in] cpo_flags Relevant flags derived from p_cpo, see CPO_TO_CPO_FLAGS. /// -/// @return Pointer to an allocated memory in case of success, "from" in case of -/// failure. In case of success returned pointer is also saved to -/// "bufp". -char_u *replace_termcodes(const char_u *from, const size_t from_len, char_u **bufp, - const bool from_part, const bool do_lt, const bool special, int cpo_flags) - FUNC_ATTR_NONNULL_ALL +/// @return Pointer to an allocated memory, which is also saved to "bufp". +char_u *replace_termcodes(const char_u *const from, const size_t from_len, char_u **const bufp, + const int flags, bool *const did_simplify, const int cpo_flags) + FUNC_ATTR_NONNULL_ARG(1, 3) { ssize_t i; size_t slen; @@ -888,10 +893,10 @@ char_u *replace_termcodes(const char_u *from, const size_t from_len, char_u **bu size_t dlen = 0; const char_u *src; const char_u *const end = from + from_len - 1; - int do_backslash; // backslash is a special character char_u *result; // buffer for resulting string - do_backslash = !(cpo_flags&FLAG_CPO_BSLASH); + const bool do_backslash = !(cpo_flags & FLAG_CPO_BSLASH); // backslash is a special character + const bool do_special = !(flags & REPTERM_NO_SPECIAL); // Allocate space for the translation. Worst case a single character is // replaced by 6 bytes (shifted special key), plus a NUL at the end. @@ -901,7 +906,7 @@ char_u *replace_termcodes(const char_u *from, const size_t from_len, char_u **bu src = from; // Check for #n at start only: function key n - if (from_part && from_len > 1 && src[0] == '#' + if ((flags & REPTERM_FROM_PART) && from_len > 1 && src[0] == '#' && ascii_isdigit(src[1])) { // function key result[dlen++] = K_SPECIAL; result[dlen++] = 'k'; @@ -916,8 +921,8 @@ char_u *replace_termcodes(const char_u *from, const size_t from_len, char_u **bu // Copy each byte from *from to result[dlen] while (src <= end) { // Check for special <> keycodes, like "<C-S-LeftMouse>" - if (special && (do_lt || ((end - src) >= 3 - && STRNCMP(src, "<lt>", 4) != 0))) { + if (do_special && ((flags & REPTERM_DO_LT) || ((end - src) >= 3 + && STRNCMP(src, "<lt>", 4) != 0))) { // Replace <SID> by K_SNR <script-nr> _. // (room: 5 * 6 = 30 bytes; needed: 3 + <nr> + 1 <= 14) if (end - src >= 4 && STRNICMP(src, "<SID>", 5) == 0) { @@ -936,15 +941,16 @@ char_u *replace_termcodes(const char_u *from, const size_t from_len, char_u **bu } } - slen = trans_special(&src, (size_t)(end - src) + 1, result + dlen, true, - false); + slen = trans_special(&src, (size_t)(end - src) + 1, result + dlen, + FSK_KEYCODE | ((flags & REPTERM_NO_SIMPLIFY) ? 0 : FSK_SIMPLIFY), + did_simplify); if (slen) { dlen += slen; continue; } } - if (special) { + if (do_special) { char_u *p, *s, len; // Replace <Leader> by the value of "mapleader". @@ -984,7 +990,7 @@ char_u *replace_termcodes(const char_u *from, const size_t from_len, char_u **bu if (key == Ctrl_V || (do_backslash && key == '\\')) { src++; // skip CTRL-V or backslash if (src > end) { - if (from_part) { + if (flags & REPTERM_FROM_PART) { result[dlen++] = key; } break; diff --git a/src/nvim/keymap.h b/src/nvim/keymap.h index 9dff8ba333..9febd472f9 100644 --- a/src/nvim/keymap.h +++ b/src/nvim/keymap.h @@ -507,6 +507,22 @@ enum key_extra { ? 0 \ : FLAG_CPO_BSLASH) +// Flags for replace_termcodes() +enum { + REPTERM_FROM_PART = 1, + REPTERM_DO_LT = 2, + REPTERM_NO_SPECIAL = 4, + REPTERM_NO_SIMPLIFY = 8, +}; + +// Flags for find_special_key() +enum { + FSK_KEYCODE = 0x01, ///< prefer key code, e.g. K_DEL in place of DEL + FSK_KEEP_X_KEY = 0x02, ///< don’t translate xHome to Home key + FSK_IN_STRING = 0x04, ///< in string, double quote is escaped + FSK_SIMPLIFY = 0x08, ///< simplify <C-H>, etc. +}; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "keymap.h.generated.h" #endif diff --git a/src/nvim/lib/kbtree.h b/src/nvim/lib/kbtree.h index 617773a79a..aca96c9a7a 100644 --- a/src/nvim/lib/kbtree.h +++ b/src/nvim/lib/kbtree.h @@ -51,7 +51,7 @@ struct kbnode_##name##_s { \ int32_t n; \ bool is_internal; \ - key_t key[2*T-1]; \ + key_t key[2*T - 1]; \ kbnode_##name##_t *ptr[]; \ }; \ typedef struct { \ @@ -435,7 +435,7 @@ #define KBTREE_INIT(name, key_t, __cmp, T) \ KBTREE_INIT_IMPL(name, key_t, kbnode_##name##_t, __cmp, T, \ - (sizeof(kbnode_##name##_t)+(2*T)*sizeof(void *))) + (sizeof(kbnode_##name##_t) + (2*T)*sizeof(void *))) #define KBTREE_INIT_IMPL(name, key_t, kbnode_t, __cmp, T, ILEN) \ __KB_TREE_T(name, key_t, T) \ diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c index ef49a03660..daf3a32a98 100644 --- a/src/nvim/lua/converter.c +++ b/src/nvim/lua/converter.c @@ -1236,7 +1236,7 @@ LuaRef nlua_pop_LuaRef(lua_State *const lstate, Error *err) type ret; \ if (lua_type(lstate, -1) != LUA_TNUMBER) { \ api_set_error(err, kErrorTypeValidation, "Expected Lua number"); \ - ret = (type)-1; \ + ret = (type) - 1; \ } else { \ ret = (type)lua_tonumber(lstate, -1); \ } \ diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 81396f1715..2c4d527fdf 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -332,8 +332,7 @@ static int nlua_schedule(lua_State *const lstate) // Dummy timer callback. Used by f_wait(). static void dummy_timer_due_cb(TimeWatcher *tw, void *data) -{ -} +{} // Dummy timer close callback. Used by f_wait(). static void dummy_timer_close_cb(TimeWatcher *tw, void *data) @@ -543,9 +542,9 @@ static int nlua_module_preloader(lua_State *lstate) ModuleDef def = builtin_modules[i]; char name[256]; name[0] = '@'; - size_t off = xstrlcpy(name+1, def.name, (sizeof name) - 2); - strchrsub(name+1, '.', '/'); - xstrlcpy(name+1+off, ".lua", (sizeof name)-2-off); + size_t off = xstrlcpy(name + 1, def.name, (sizeof name) - 2); + strchrsub(name + 1, '.', '/'); + xstrlcpy(name + 1 + off, ".lua", (sizeof name) - 2 - off); if (luaL_loadbuffer(lstate, (const char *)def.data, def.size - 1, name)) { return lua_error(lstate); @@ -769,7 +768,7 @@ static void nlua_common_free_all_mem(lua_State *lstate) static void nlua_print_event(void **argv) { char *str = argv[0]; - const size_t len = (size_t)(intptr_t)argv[1]-1; // exclude final NUL + const size_t len = (size_t)(intptr_t)argv[1] - 1; // exclude final NUL for (size_t i = 0; i < len;) { if (got_int) { @@ -926,7 +925,7 @@ int nlua_call(lua_State *lstate) return luaL_error(lstate, e_luv_api_disabled, "vimL function"); } - int nargs = lua_gettop(lstate)-1; + int nargs = lua_gettop(lstate) - 1; if (nargs > MAX_FUNC_ARGS) { return luaL_error(lstate, "Function called with too many arguments"); } @@ -934,10 +933,10 @@ int nlua_call(lua_State *lstate) typval_T vim_args[MAX_FUNC_ARGS + 1]; int i = 0; // also used for freeing the variables for (; i < nargs; i++) { - lua_pushvalue(lstate, i+2); + lua_pushvalue(lstate, i + 2); if (!nlua_pop_typval(lstate, &vim_args[i])) { api_set_error(&err, kErrorTypeException, - "error converting argument %d", i+1); + "error converting argument %d", i + 1); goto free_vim_args; } } @@ -994,12 +993,12 @@ static int nlua_rpc(lua_State *lstate, bool request) size_t name_len; uint64_t chan_id = (uint64_t)luaL_checkinteger(lstate, 1); const char *name = luaL_checklstring(lstate, 2, &name_len); - int nargs = lua_gettop(lstate)-2; + int nargs = lua_gettop(lstate) - 2; Error err = ERROR_INIT; Array args = ARRAY_DICT_INIT; for (int i = 0; i < nargs; i++) { - lua_pushvalue(lstate, i+3); + lua_pushvalue(lstate, i + 3); ADD(args, nlua_pop_Object(lstate, false, &err)); if (ERROR_SET(&err)) { api_free_array(args); @@ -1415,7 +1414,7 @@ void ex_lua(exarg_T *const eap) // lua nlua_typval_exec doesn't expect null terminated string so len // needs to end before null byte. char *code_buf = xmallocz(len); - vim_snprintf(code_buf, len+1, "vim.pretty_print(%s)", code+1); + vim_snprintf(code_buf, len + 1, "vim.pretty_print(%s)", code + 1); xfree(code); code = code_buf; } @@ -1820,7 +1819,7 @@ void nlua_set_sctx(sctx_T *current) is_ignored = true; } else { for (int i = 0; i < ignorelist_size; i++) { - if (strncmp(ignorelist[i], info->source+1, strlen(ignorelist[i])) == 0) { + if (strncmp(ignorelist[i], info->source + 1, strlen(ignorelist[i])) == 0) { is_ignored = true; break; } @@ -1912,4 +1911,3 @@ void nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap) nlua_error(lstate, _("Error executing Lua callback: %.*s")); } } - diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index e94c61b37c..52a9a1a84f 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -59,8 +59,8 @@ static int regex_match(lua_State *lstate, regprog_T **prog, char_u *str) *prog = rm.regprog; if (match) { - lua_pushinteger(lstate, (lua_Integer)(rm.startp[0]-str)); - lua_pushinteger(lstate, (lua_Integer)(rm.endp[0]-str)); + lua_pushinteger(lstate, (lua_Integer)(rm.startp[0] - str)); + lua_pushinteger(lstate, (lua_Integer)(rm.endp[0] - str)); return 2; } return 0; @@ -110,7 +110,7 @@ static int regex_match_line(lua_State *lstate) return luaL_error(lstate, "invalid row"); } - char_u *line = ml_get_buf(buf, rownr+1, false); + char_u *line = ml_get_buf(buf, rownr + 1, false); size_t len = STRLEN(line); if (start < 0 || (size_t)start > len) { @@ -126,7 +126,7 @@ static int regex_match_line(lua_State *lstate) line[end] = NUL; } - int nret = regex_match(lstate, prog, line+start); + int nret = regex_match(lstate, prog, line + start); if (end >= 0) { line[end] = save; @@ -208,7 +208,7 @@ static int nlua_str_utf_pos(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL size_t idx = 1; size_t clen; for (size_t i = 0; i < s1_len && s1[i] != NUL; i += clen) { - clen = (size_t)utf_ptr2len_len((const char_u *)(s1)+i, (int)(s1_len-i)); + clen = (size_t)utf_ptr2len_len((const char_u *)(s1) + i, (int)(s1_len - i)); lua_pushinteger(lstate, (long)i + 1); lua_rawseti(lstate, -2, (int)idx); idx++; diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index f4067ad02f..a871cd29ce 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -208,7 +208,7 @@ int tslua_inspect_lang(lua_State *L) size_t nsymbols = (size_t)ts_language_symbol_count(lang); - lua_createtable(L, nsymbols-1, 1); // [retval, symbols] + lua_createtable(L, nsymbols - 1, 1); // [retval, symbols] for (size_t i = 0; i < nsymbols; i++) { TSSymbolType t = ts_language_symbol_type(lang, i); if (t == TSSymbolTypeAuxiliary) { @@ -298,15 +298,15 @@ static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position *bytes_read = 0; return ""; } - char_u *line = ml_get_buf(bp, position.row+1, false); + char_u *line = ml_get_buf(bp, position.row + 1, false); size_t len = STRLEN(line); if (position.column > len) { *bytes_read = 0; return ""; } - size_t tocopy = MIN(len-position.column, BUFSIZE); + size_t tocopy = MIN(len - position.column, BUFSIZE); - memcpy(buf, line+position.column, tocopy); + memcpy(buf, line + position.column, tocopy); // Translate embedded \n to NUL memchrsub(buf, '\n', '\0', tocopy); *bytes_read = (uint32_t)tocopy; @@ -334,7 +334,7 @@ static void push_ranges(lua_State *L, const TSRange *ranges, const unsigned int lua_pushinteger(L, ranges[i].end_point.column); lua_rawseti(L, -2, 4); - lua_rawseti(L, -2, i+1); + lua_rawseti(L, -2, i + 1); } } @@ -1037,7 +1037,7 @@ static void set_match(lua_State *L, TSQueryMatch *match, int nodeidx) { for (int i = 0; i < match->capture_count; i++) { push_node(L, match->captures[i].node, nodeidx); - lua_rawseti(L, -2, match->captures[i].index+1); + lua_rawseti(L, -2, match->captures[i].index + 1); } } @@ -1049,7 +1049,7 @@ static int query_next_match(lua_State *L) TSQuery *query = query_check(L, lua_upvalueindex(3)); TSQueryMatch match; if (ts_query_cursor_next_match(cursor, &match)) { - lua_pushinteger(L, match.pattern_index+1); // [index] + lua_pushinteger(L, match.pattern_index + 1); // [index] lua_createtable(L, ts_query_capture_count(query), 2); // [index, match] set_match(L, &match, lua_upvalueindex(2)); return 2; @@ -1082,7 +1082,7 @@ static int query_next_capture(lua_State *L) if (ts_query_cursor_next_capture(cursor, &match, &capture_index)) { TSQueryCapture capture = match.captures[capture_index]; - lua_pushinteger(L, capture.index+1); // [index] + lua_pushinteger(L, capture.index + 1); // [index] push_node(L, capture.node, lua_upvalueindex(2)); // [index, node] // Now check if we need to run the predicates @@ -1094,7 +1094,7 @@ static int query_next_capture(lua_State *L) lua_pushvalue(L, lua_upvalueindex(4)); // [index, node, match] set_match(L, &match, lua_upvalueindex(2)); - lua_pushinteger(L, match.pattern_index+1); + lua_pushinteger(L, match.pattern_index + 1); lua_setfield(L, -2, "pattern"); if (match.capture_count > 1) { @@ -1273,7 +1273,7 @@ static int query_inspect(lua_State *L) &strlen); lua_pushlstring(L, str, strlen); // [retval, patterns, pat, pred, item] } else if (step[k].type == TSQueryPredicateStepTypeCapture) { - lua_pushnumber(L, step[k].value_id+1); // [..., pat, pred, item] + lua_pushnumber(L, step[k].value_id + 1); // [..., pat, pred, item] } else { abort(); } @@ -1281,7 +1281,7 @@ static int query_inspect(lua_State *L) } // last predicate should have ended with TypeDone lua_pop(L, 1); // [retval, patters, pat] - lua_rawseti(L, -2, i+1); // [retval, patterns] + lua_rawseti(L, -2, i + 1); // [retval, patterns] } lua_setfield(L, -2, "patterns"); // [retval] @@ -1291,7 +1291,7 @@ static int query_inspect(lua_State *L) uint32_t strlen; const char *str = ts_query_capture_name_for_id(query, i, &strlen); lua_pushlstring(L, str, strlen); // [retval, captures, capture] - lua_rawseti(L, -2, i+1); + lua_rawseti(L, -2, i + 1); } lua_setfield(L, -2, "captures"); // [retval] diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index 37855630d1..71f85385b6 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -74,7 +74,7 @@ static int hunk_locations_cb(long start_a, long count_a, long start_b, long coun lua_pushinteger(lstate, count_b); lua_rawseti(lstate, -2, 4); - lua_rawseti(lstate, -2, (signed)lua_objlen(lstate, -2)+1); + lua_rawseti(lstate, -2, (signed)lua_objlen(lstate, -2) + 1); return 0; } diff --git a/src/nvim/main.c b/src/nvim/main.c index 35d01f2407..952064ab73 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -835,8 +835,8 @@ static uint64_t server_connect(char *server_addr, const char **errmsg) } /// Handle remote subcommands -static void remote_request(mparm_T *params, int remote_args, - char *server_addr, int argc, char **argv) +static void remote_request(mparm_T *params, int remote_args, char *server_addr, int argc, + char **argv) { const char *connect_error = NULL; uint64_t chan = server_connect(server_addr, &connect_error); @@ -884,7 +884,7 @@ static void remote_request(mparm_T *params, int remote_args, TriState should_exit = kNone; TriState tabbed = kNone; - for (size_t i = 0; i < rvobj.data.dictionary.size ; i++) { + for (size_t i = 0; i < rvobj.data.dictionary.size; i++) { if (strcmp(rvobj.data.dictionary.items[i].key.data, "errmsg") == 0) { if (rvobj.data.dictionary.items[i].value.type != kObjectTypeString) { mch_errmsg("vim._cs_remote returned an unexpected type for 'errmsg'\n"); @@ -1376,7 +1376,7 @@ scripterror: int alist_fnum_flag = edit_stdin(had_stdin_file, parmp) ? 1 // add buffer nr after exp. : 2; // add buffer number now and use curbuf - alist_add(&global_alist, p, alist_fnum_flag); + alist_add(&global_alist, (char *)p, alist_fnum_flag); } // If there are no more letters after the current "-", go to next argument. @@ -1748,8 +1748,8 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd) // at the ATTENTION prompt close the window. swap_exists_did_quit = false; (void)do_ecmd(0, arg_idx < GARGCOUNT - ? alist_name(&GARGLIST[arg_idx]) : NULL, - NULL, NULL, ECMD_LASTL, ECMD_HIDE, curwin); + ? (char *)alist_name(&GARGLIST[arg_idx]) + : NULL, NULL, NULL, ECMD_LASTL, ECMD_HIDE, curwin); if (swap_exists_did_quit) { // abort or quit selected if (got_int || only_one_window()) { diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 0dbfb0c49f..4f4eea554a 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -1139,7 +1139,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo { \ posp->lnum += lnum_amount; \ assert(col_amount > INT_MIN && col_amount <= INT_MAX); \ - if (col_amount < 0 && posp->col <= (colnr_T)-col_amount) { \ + if (col_amount < 0 && posp->col <= (colnr_T) - col_amount) { \ posp->col = 0; \ } else if (posp->col < spaces_removed) { \ posp->col = (int)col_amount + spaces_removed; \ diff --git a/src/nvim/marktree.c b/src/nvim/marktree.c index 937582572b..ff31567bf5 100644 --- a/src/nvim/marktree.c +++ b/src/nvim/marktree.c @@ -54,7 +54,7 @@ #include "nvim/marktree.h" #define T MT_BRANCH_FACTOR -#define ILEN (sizeof(mtnode_t)+(2 * T) * sizeof(void *)) +#define ILEN (sizeof(mtnode_t) + (2 * T) * sizeof(void *)) #define ID_INCR (((uint64_t)1) << 2) @@ -158,7 +158,7 @@ static inline void split_node(MarkTree *b, mtnode_t *x, const int i) z->level = y->level; z->n = T - 1; memcpy(z->key, &y->key[T], sizeof(mtkey_t) * (T - 1)); - for (int j = 0; j < T-1; j++) { + for (int j = 0; j < T - 1; j++) { refkey(b, z, j); } if (y->level) { @@ -179,11 +179,11 @@ static inline void split_node(MarkTree *b, mtnode_t *x, const int i) refkey(b, x, i); x->n++; - for (int j = 0; j < T-1; j++) { + for (int j = 0; j < T - 1; j++) { relative(x->key[i].pos, &z->key[j].pos); } if (i > 0) { - unrelative(x->key[i-1].pos, &x->key[i].pos); + unrelative(x->key[i - 1].pos, &x->key[i].pos); } } @@ -198,7 +198,7 @@ static inline void marktree_putp_aux(MarkTree *b, mtnode_t *x, mtkey_t k) (size_t)(x->n - i - 1) * sizeof(mtkey_t)); } x->key[i + 1] = k; - refkey(b, x, i+1); + refkey(b, x, i + 1); x->n++; } else { i = marktree_getp_aux(x, k, 0) + 1; @@ -209,7 +209,7 @@ static inline void marktree_putp_aux(MarkTree *b, mtnode_t *x, mtkey_t k) } } if (i > 0) { - relative(x->key[i-1].pos, &k.pos); + relative(x->key[i - 1].pos, &k.pos); } marktree_putp_aux(b, x->ptr[i], k); } @@ -247,7 +247,7 @@ void marktree_put_key(MarkTree *b, mtkey_t k) if (r->n == 2 * T - 1) { b->n_nodes++; s = (mtnode_t *)xcalloc(1, ILEN); - b->root = s; s->level = r->level+1; s->n = 0; + b->root = s; s->level = r->level + 1; s->n = 0; s->ptr[0] = r; r->parent = s; split_node(b, s, 0); @@ -304,9 +304,9 @@ void marktree_del_itr(MarkTree *b, MarkTreeIter *itr, bool rev) mtnode_t *x = itr->node; assert(x->level == 0); mtkey_t intkey = x->key[itr->i]; - if (x->n > itr->i+1) { - memmove(&x->key[itr->i], &x->key[itr->i+1], - sizeof(mtkey_t) * (size_t)(x->n - itr->i-1)); + if (x->n > itr->i + 1) { + memmove(&x->key[itr->i], &x->key[itr->i + 1], + sizeof(mtkey_t) * (size_t)(x->n - itr->i - 1)); } x->n--; @@ -315,7 +315,7 @@ void marktree_del_itr(MarkTree *b, MarkTreeIter *itr, bool rev) // abort(); // } if (adjustment == -1) { - int ilvl = itr->lvl-1; + int ilvl = itr->lvl - 1; const mtnode_t *lnode = x; do { const mtnode_t *const p = lnode->parent; @@ -325,7 +325,7 @@ void marktree_del_itr(MarkTree *b, MarkTreeIter *itr, bool rev) const int i = itr->s[ilvl].i; assert(p->ptr[i] == lnode); if (i > 0) { - unrelative(p->key[i-1].pos, &intkey.pos); + unrelative(p->key[i - 1].pos, &intkey.pos); } lnode = p; ilvl--; @@ -335,7 +335,7 @@ void marktree_del_itr(MarkTree *b, MarkTreeIter *itr, bool rev) cur->key[curi] = intkey; refkey(b, cur, curi); relative(intkey.pos, &deleted.pos); - mtnode_t *y = cur->ptr[curi+1]; + mtnode_t *y = cur->ptr[curi + 1]; if (deleted.pos.row || deleted.pos.col) { while (y) { for (int k = 0; k < y->n; k++) { @@ -352,33 +352,33 @@ void marktree_del_itr(MarkTree *b, MarkTreeIter *itr, bool rev) // 5. bool itr_dirty = false; - int rlvl = itr->lvl-1; + int rlvl = itr->lvl - 1; int *lasti = &itr->i; while (x != b->root) { assert(rlvl >= 0); mtnode_t *p = x->parent; - if (x->n >= T-1) { + if (x->n >= T - 1) { // we are done, if this node is fine the rest of the tree will be break; } int pi = itr->s[rlvl].i; assert(p->ptr[pi] == x); - if (pi > 0 && p->ptr[pi-1]->n > T-1) { + if (pi > 0 && p->ptr[pi - 1]->n > T - 1) { *lasti += 1; itr_dirty = true; // steal one key from the left neighbour - pivot_right(b, p, pi-1); + pivot_right(b, p, pi - 1); break; - } else if (pi < p->n && p->ptr[pi+1]->n > T-1) { + } else if (pi < p->n && p->ptr[pi + 1]->n > T - 1) { // steal one key from right neighbour pivot_left(b, p, pi); break; } else if (pi > 0) { // fprintf(stderr, "LEFT "); - assert(p->ptr[pi-1]->n == T-1); + assert(p->ptr[pi - 1]->n == T - 1); // merge with left neighbour *lasti += T; - x = merge_node(b, p, pi-1); + x = merge_node(b, p, pi - 1); if (lasti == &itr->i) { // TRICKY: we merged the node the iterator was on itr->node = x; @@ -387,7 +387,7 @@ void marktree_del_itr(MarkTree *b, MarkTreeIter *itr, bool rev) itr_dirty = true; } else { // fprintf(stderr, "RIGHT "); - assert(pi < p->n && p->ptr[pi+1]->n == T-1); + assert(pi < p->n && p->ptr[pi + 1]->n == T - 1); merge_node(b, p, pi); // no iter adjustment needed } @@ -399,7 +399,7 @@ void marktree_del_itr(MarkTree *b, MarkTreeIter *itr, bool rev) // 6. if (b->root->n == 0) { if (itr->lvl > 0) { - memmove(itr->s, itr->s+1, (size_t)(itr->lvl-1) * sizeof(*itr->s)); + memmove(itr->s, itr->s + 1, (size_t)(itr->lvl - 1) * sizeof(*itr->s)); itr->lvl--; } if (b->root->level) { @@ -441,26 +441,26 @@ void marktree_del_itr(MarkTree *b, MarkTreeIter *itr, bool rev) static mtnode_t *merge_node(MarkTree *b, mtnode_t *p, int i) { - mtnode_t *x = p->ptr[i], *y = p->ptr[i+1]; + mtnode_t *x = p->ptr[i], *y = p->ptr[i + 1]; x->key[x->n] = p->key[i]; refkey(b, x, x->n); if (i > 0) { - relative(p->key[i-1].pos, &x->key[x->n].pos); + relative(p->key[i - 1].pos, &x->key[x->n].pos); } - memmove(&x->key[x->n+1], y->key, (size_t)y->n * sizeof(mtkey_t)); + memmove(&x->key[x->n + 1], y->key, (size_t)y->n * sizeof(mtkey_t)); for (int k = 0; k < y->n; k++) { - refkey(b, x, x->n+1+k); - unrelative(x->key[x->n].pos, &x->key[x->n+1+k].pos); + refkey(b, x, x->n + 1 + k); + unrelative(x->key[x->n].pos, &x->key[x->n + 1 + k].pos); } if (x->level) { - memmove(&x->ptr[x->n+1], y->ptr, ((size_t)y->n + 1) * sizeof(mtnode_t *)); - for (int k = 0; k < y->n+1; k++) { - x->ptr[x->n+k+1]->parent = x; + memmove(&x->ptr[x->n + 1], y->ptr, ((size_t)y->n + 1) * sizeof(mtnode_t *)); + for (int k = 0; k < y->n + 1; k++) { + x->ptr[x->n + k + 1]->parent = x; } } - x->n += y->n+1; + x->n += y->n + 1; memmove(&p->key[i], &p->key[i + 1], (size_t)(p->n - i - 1) * sizeof(mtkey_t)); memmove(&p->ptr[i + 1], &p->ptr[i + 2], (size_t)(p->n - i - 1) * sizeof(mtkey_t *)); @@ -474,7 +474,7 @@ static mtnode_t *merge_node(MarkTree *b, mtnode_t *p, int i) // the two nodes instead of stealing just one key static void pivot_right(MarkTree *b, mtnode_t *p, int i) { - mtnode_t *x = p->ptr[i], *y = p->ptr[i+1]; + mtnode_t *x = p->ptr[i], *y = p->ptr[i + 1]; memmove(&y->key[1], y->key, (size_t)y->n * sizeof(mtkey_t)); if (y->level) { memmove(&y->ptr[1], y->ptr, ((size_t)y->n + 1) * sizeof(mtnode_t *)); @@ -490,7 +490,7 @@ static void pivot_right(MarkTree *b, mtnode_t *p, int i) x->n--; y->n++; if (i > 0) { - unrelative(p->key[i-1].pos, &p->key[i].pos); + unrelative(p->key[i - 1].pos, &p->key[i].pos); } relative(p->key[i].pos, &y->key[0].pos); for (int k = 1; k < y->n; k++) { @@ -500,7 +500,7 @@ static void pivot_right(MarkTree *b, mtnode_t *p, int i) static void pivot_left(MarkTree *b, mtnode_t *p, int i) { - mtnode_t *x = p->ptr[i], *y = p->ptr[i+1]; + mtnode_t *x = p->ptr[i], *y = p->ptr[i + 1]; // reverse from how we "always" do it. but pivot_left // is just the inverse of pivot_right, so reverse it literally. @@ -509,7 +509,7 @@ static void pivot_left(MarkTree *b, mtnode_t *p, int i) } unrelative(p->key[i].pos, &y->key[0].pos); if (i > 0) { - relative(p->key[i-1].pos, &p->key[i].pos); + relative(p->key[i - 1].pos, &p->key[i].pos); } x->key[x->n] = p->key[i]; @@ -517,10 +517,10 @@ static void pivot_left(MarkTree *b, mtnode_t *p, int i) p->key[i] = y->key[0]; refkey(b, p, i); if (x->level) { - x->ptr[x->n+1] = y->ptr[0]; - x->ptr[x->n+1]->parent = x; + x->ptr[x->n + 1] = y->ptr[0]; + x->ptr[x->n + 1]->parent = x; } - memmove(y->key, &y->key[1], (size_t)(y->n-1) * sizeof(mtkey_t)); + memmove(y->key, &y->key[1], (size_t)(y->n - 1) * sizeof(mtkey_t)); if (y->level) { memmove(y->ptr, &y->ptr[1], (size_t)y->n * sizeof(mtnode_t *)); } @@ -546,7 +546,7 @@ void marktree_clear(MarkTree *b) void marktree_free_node(mtnode_t *x) { if (x->level) { - for (int i = 0; i < x->n+1; i++) { + for (int i = 0; i < x->n + 1; i++) { marktree_free_node(x->ptr[i]); } } @@ -608,7 +608,7 @@ bool marktree_itr_get_ext(MarkTree *b, mtpos_t p, MarkTreeIter *itr, bool last, oldbase[itr->lvl] = itr->pos; } while (true) { - itr->i = marktree_getp_aux(itr->node, k, 0)+1; + itr->i = marktree_getp_aux(itr->node, k, 0) + 1; if (itr->node->level == 0) { break; @@ -618,8 +618,8 @@ bool marktree_itr_get_ext(MarkTree *b, mtpos_t p, MarkTreeIter *itr, bool last, itr->s[itr->lvl].oldcol = itr->pos.col; if (itr->i > 0) { - compose(&itr->pos, itr->node->key[itr->i-1].pos); - relative(itr->node->key[itr->i-1].pos, &k.pos); + compose(&itr->pos, itr->node->key[itr->i - 1].pos); + relative(itr->node->key[itr->i - 1].pos, &k.pos); } itr->node = itr->node->ptr[itr->i]; itr->lvl++; @@ -676,7 +676,7 @@ int marktree_itr_last(MarkTree *b, MarkTreeIter *itr) itr->s[itr->lvl].oldcol = itr->pos.col; assert(itr->i > 0); - compose(&itr->pos, itr->node->key[itr->i-1].pos); + compose(&itr->pos, itr->node->key[itr->i - 1].pos); itr->node = itr->node->ptr[itr->i]; itr->lvl++; @@ -712,7 +712,7 @@ static bool marktree_itr_next_skip(MarkTree *b, MarkTreeIter *itr, bool skip, mt itr->lvl--; itr->i = itr->s[itr->lvl].i; if (itr->i > 0) { - itr->pos.row -= itr->node->key[itr->i-1].pos.row; + itr->pos.row -= itr->node->key[itr->i - 1].pos.row; itr->pos.col = itr->s[itr->lvl].oldcol; } } @@ -723,10 +723,10 @@ static bool marktree_itr_next_skip(MarkTree *b, MarkTreeIter *itr, bool skip, mt // internal key, there is always a child after if (itr->i > 0) { itr->s[itr->lvl].oldcol = itr->pos.col; - compose(&itr->pos, itr->node->key[itr->i-1].pos); + compose(&itr->pos, itr->node->key[itr->i - 1].pos); } if (oldbase && itr->i == 0) { - oldbase[itr->lvl+1] = oldbase[itr->lvl]; + oldbase[itr->lvl + 1] = oldbase[itr->lvl]; } itr->s[itr->lvl].i = itr->i; assert(itr->node->ptr[itr->i]->parent == itr->node); @@ -757,7 +757,7 @@ bool marktree_itr_prev(MarkTree *b, MarkTreeIter *itr) return false; } itr->lvl--; - itr->i = itr->s[itr->lvl].i-1; + itr->i = itr->s[itr->lvl].i - 1; if (itr->i >= 0) { itr->pos.row -= itr->node->key[itr->i].pos.row; itr->pos.col = itr->s[itr->lvl].oldcol; @@ -770,7 +770,7 @@ bool marktree_itr_prev(MarkTree *b, MarkTreeIter *itr) // internal key, there is always a child before if (itr->i > 0) { itr->s[itr->lvl].oldcol = itr->pos.col; - compose(&itr->pos, itr->node->key[itr->i-1].pos); + compose(&itr->pos, itr->node->key[itr->i - 1].pos); } itr->s[itr->lvl].i = itr->i; assert(itr->node->ptr[itr->i]->parent == itr->node); @@ -796,7 +796,7 @@ void marktree_itr_rewind(MarkTree *b, MarkTreeIter *itr) bool marktree_itr_node_done(MarkTreeIter *itr) { - return !itr->node || itr->i == itr->node->n-1; + return !itr->node || itr->i == itr->node->n - 1; } @@ -854,7 +854,7 @@ bool marktree_splice(MarkTree *b, int start_line, int start_col, int old_extent_ return false; } mtpos_t delta = { new_extent.row - old_extent.row, - new_extent.col-old_extent.col }; + new_extent.col - old_extent.col }; if (may_delete) { mtpos_t ipos = marktree_itr_pos(itr); @@ -913,13 +913,13 @@ continue_same_node: moved = true; if (itr->node->level) { - oldbase[itr->lvl+1] = rawkey(itr).pos; - unrelative(oldbase[itr->lvl], &oldbase[itr->lvl+1]); + oldbase[itr->lvl + 1] = rawkey(itr).pos; + unrelative(oldbase[itr->lvl], &oldbase[itr->lvl + 1]); rawkey(itr).pos = loc_start; marktree_itr_next_skip(b, itr, false, oldbase); } else { rawkey(itr).pos = loc_start; - if (itr->i < itr->node->n-1) { + if (itr->i < itr->node->n - 1) { itr->i++; if (!past_right) { goto continue_same_node; @@ -946,12 +946,12 @@ past_continue_same_node: rawkey(itr).pos = loc_new; moved = true; if (itr->node->level) { - oldbase[itr->lvl+1] = oldpos; - unrelative(oldbase[itr->lvl], &oldbase[itr->lvl+1]); + oldbase[itr->lvl + 1] = oldpos; + unrelative(oldbase[itr->lvl], &oldbase[itr->lvl + 1]); marktree_itr_next_skip(b, itr, false, oldbase); } else { - if (itr->i < itr->node->n-1) { + if (itr->i < itr->node->n - 1) { itr->i++; goto past_continue_same_node; } else { @@ -1056,7 +1056,7 @@ found: {} } while (n->parent != NULL) { mtnode_t *p = n->parent; - for (i = 0; i < p->n+1; i++) { + for (i = 0; i < p->n + 1; i++) { if (p->ptr[i] == n) { goto found_node; } @@ -1064,10 +1064,10 @@ found: {} abort(); found_node: if (itr) { - itr->s[b->root->level-p->level].i = i; + itr->s[b->root->level - p->level].i = i; } if (i > 0) { - unrelative(p->key[i-1].pos, &key.pos); + unrelative(p->key[i - 1].pos, &key.pos); } n = p; } @@ -1099,7 +1099,7 @@ static void marktree_itr_fix_pos(MarkTree *b, MarkTreeIter *itr) itr->s[lvl].oldcol = itr->pos.col; int i = itr->s[lvl].i; if (i > 0) { - compose(&itr->pos, x->key[i-1].pos); + compose(&itr->pos, x->key[i - 1].pos); } assert(x->level); x = x->ptr[i]; @@ -1147,7 +1147,7 @@ static size_t check_node(MarkTree *b, mtnode_t *x, mtpos_t *last, bool *last_rig { assert(x->n <= 2 * T - 1); // TODO(bfredl): too strict if checking "in repair" post-delete tree. - assert(x->n >= (x != b->root ? T-1 : 0)); + assert(x->n >= (x != b->root ? T - 1 : 0)); size_t n_keys = (size_t)x->n; for (int i = 0; i < x->n; i++) { @@ -1157,7 +1157,7 @@ static size_t check_node(MarkTree *b, mtnode_t *x, mtpos_t *last, bool *last_rig *last = (mtpos_t) { 0, 0 }; } if (i > 0) { - unrelative(x->key[i-1].pos, last); + unrelative(x->key[i - 1].pos, last); } assert(pos_leq(*last, x->key[i].pos)); if (last->row == x->key[i].pos.row && last->col == x->key[i].pos.col) { @@ -1170,18 +1170,18 @@ static size_t check_node(MarkTree *b, mtnode_t *x, mtpos_t *last, bool *last_rig if (x->level) { n_keys += check_node(b, x->ptr[x->n], last, last_right); - unrelative(x->key[x->n-1].pos, last); + unrelative(x->key[x->n - 1].pos, last); - for (int i = 0; i < x->n+1; i++) { + for (int i = 0; i < x->n + 1; i++) { assert(x->ptr[i]->parent == x); - assert(x->ptr[i]->level == x->level-1); + assert(x->ptr[i]->level == x->level - 1); // PARANOIA: check no double node ref for (int j = 0; j < i; j++) { assert(x->ptr[i] != x->ptr[j]); } } } else { - *last = x->key[x->n-1].pos; + *last = x->key[x->n - 1].pos; } return n_keys; } @@ -1209,11 +1209,10 @@ void mt_inspect_node(MarkTree *b, garray_T *ga, mtnode_t *n, mtpos_t off) snprintf((char *)buf, sizeof(buf), "%d/%d", p.row, p.col); ga_concat(ga, buf); if (n->level) { - mt_inspect_node(b, ga, n->ptr[i+1], p); + mt_inspect_node(b, ga, n->ptr[i + 1], p); } else { ga_concat(ga, ","); } } ga_concat(ga, "]"); } - diff --git a/src/nvim/marktree.h b/src/nvim/marktree.h index ae6da92106..5b3171d9aa 100644 --- a/src/nvim/marktree.h +++ b/src/nvim/marktree.h @@ -55,7 +55,7 @@ typedef struct { #define DECOR_LEVELS 4 #define MT_FLAG_DECOR_OFFSET 4 -#define MT_FLAG_DECOR_MASK (((uint16_t)(DECOR_LEVELS-1)) << MT_FLAG_DECOR_OFFSET) +#define MT_FLAG_DECOR_MASK (((uint16_t)(DECOR_LEVELS - 1)) << MT_FLAG_DECOR_OFFSET) // next flag is (((uint16_t)1) << 6) diff --git a/src/nvim/match.c b/src/nvim/match.c index ed320eb6fc..86ddad0d47 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -4,6 +4,7 @@ // match.c: functions for highlighting matches #include <stdbool.h> + #include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/fold.h" @@ -504,9 +505,9 @@ void prepare_search_hl(win_T *wp, match_T *search_hl, linenr_T lnum) FUNC_ATTR_NONNULL_ALL { matchitem_T *cur; // points to the match list - match_T *shl; // points to search_hl or a match - bool shl_flag; // flag to indicate whether search_hl - // has been processed or not + match_T *shl; // points to search_hl or a match + bool shl_flag; // flag to indicate whether search_hl + // has been processed or not // When using a multi-line pattern, start searching at the top // of the window or just after a closed fold. @@ -583,10 +584,10 @@ bool prepare_search_hl_line(win_T *wp, linenr_T lnum, colnr_T mincol, char_u **l match_T *search_hl, int *search_attr, bool *search_attr_from_match) { matchitem_T *cur = wp->w_match_head; // points to the match list - match_T *shl; // points to search_hl or a match - bool shl_flag = false; // flag to indicate whether search_hl - // has been processed or not - bool area_highlighting = false; + match_T *shl; // points to search_hl or a match + bool shl_flag = false; // flag to indicate whether search_hl + // has been processed or not + bool area_highlighting = false; // Handle highlighting the last used search pattern and matches. // Do this for both search_hl and the match list. @@ -663,10 +664,10 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char_u **line, match bool *search_attr_from_match) { matchitem_T *cur = wp->w_match_head; // points to the match list - match_T *shl; // points to search_hl or a match - bool shl_flag = false; // flag to indicate whether search_hl - // has been processed or not - int search_attr = 0; + match_T *shl; // points to search_hl or a match + bool shl_flag = false; // flag to indicate whether search_hl + // has been processed or not + int search_attr = 0; // Do this for 'search_hl' and the match list (ordered by priority). while (cur != NULL || !shl_flag) { @@ -781,7 +782,7 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char_u **line, match bool get_prevcol_hl_flag(win_T *wp, match_T *search_hl, long curcol) { - long prevcol = curcol; + long prevcol = curcol; matchitem_T *cur; // points to the match list // we're not really at that column when skipping some text @@ -808,9 +809,9 @@ bool get_prevcol_hl_flag(win_T *wp, match_T *search_hl, long curcol) void get_search_match_hl(win_T *wp, match_T *search_hl, long col, int *char_attr) { matchitem_T *cur = wp->w_match_head; // points to the match list - match_T *shl; // points to search_hl or a match - bool shl_flag = false; // flag to indicate whether search_hl - // has been processed or not + match_T *shl; // points to search_hl or a match + bool shl_flag = false; // flag to indicate whether search_hl + // has been processed or not *char_attr = search_hl->attr; while (cur != NULL || !shl_flag) { @@ -1214,4 +1215,3 @@ void ex_match(exarg_T *eap) } eap->nextcmd = find_nextcmd(end); } - diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 6e3c5322e7..10744a86dc 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -584,8 +584,8 @@ size_t mb_string2cells_len(const char_u *str, size_t size) { size_t clen = 0; - for (const char_u *p = str; *p != NUL && p < str+size; - p += utfc_ptr2len_len(p, size+(p-str))) { + for (const char_u *p = str; *p != NUL && p < str + size; + p += utfc_ptr2len_len(p, size + (p - str))) { clen += utf_ptr2cells(p); } @@ -808,7 +808,7 @@ int utfc_ptr2char_len(const char_u *p, int *pcc, int maxlen) int len_cc = utf_ptr2len_len(p + len, maxlen - len); safe = len_cc > 1 && len_cc <= maxlen - len; if (!safe || (pcc[i] = utf_ptr2char(p + len)) < 0x80 - || !(i == 0 ? utf_composinglike(p, p+len) : utf_iscomposing(pcc[i]))) { + || !(i == 0 ? utf_composinglike(p, p + len) : utf_iscomposing(pcc[i]))) { break; } len += len_cc; @@ -1507,10 +1507,10 @@ void mb_utflen(const char_u *s, size_t len, size_t *codepoints, size_t *codeunit size_t count = 0, extra = 0; size_t clen; for (size_t i = 0; i < len && s[i] != NUL; i += clen) { - clen = utf_ptr2len_len(s+i, len-i); + clen = utf_ptr2len_len(s + i, len - i); // NB: gets the byte value of invalid sequence bytes. // we only care whether the char fits in the BMP or not - int c = (clen > 1) ? utf_ptr2char(s+i) : s[i]; + int c = (clen > 1) ? utf_ptr2char(s + i) : s[i]; count++; if (c > 0xFFFF) { extra++; @@ -1529,16 +1529,16 @@ ssize_t mb_utf_index_to_bytes(const char_u *s, size_t len, size_t index, bool us return 0; } for (i = 0; i < len && s[i] != NUL; i += clen) { - clen = utf_ptr2len_len(s+i, len-i); + clen = utf_ptr2len_len(s + i, len - i); // NB: gets the byte value of invalid sequence bytes. // we only care whether the char fits in the BMP or not - int c = (clen > 1) ? utf_ptr2char(s+i) : s[i]; + int c = (clen > 1) ? utf_ptr2char(s + i) : s[i]; count++; if (use_utf16_units && c > 0xFFFF) { count++; } if (count >= index) { - return i+clen; + return i + clen; } } return -1; diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 5c2f494450..ce6c702276 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -972,8 +972,7 @@ void ml_recover(bool checkext) if (b0p->b0_flags & B0_HAS_FENC) { int fnsize = B0_FNAME_SIZE_NOCRYPT; - for (p = b0p->b0_fname + fnsize; p > b0p->b0_fname && p[-1] != NUL; p--) { - } + for (p = b0p->b0_fname + fnsize; p > b0p->b0_fname && p[-1] != NUL; p--) {} b0_fenc = vim_strnsave(p, b0p->b0_fname + fnsize - p); } @@ -2438,8 +2437,8 @@ void ml_add_deleted_len_buf(buf_T *buf, char_u *ptr, ssize_t len) if (len == -1) { len = STRLEN(ptr); } - curbuf->deleted_bytes += len+1; - curbuf->deleted_bytes2 += len+1; + curbuf->deleted_bytes += len + 1; + curbuf->deleted_bytes2 += len + 1; if (curbuf->update_need_codepoints) { mb_utflen(ptr, len, &curbuf->deleted_codepoints, &curbuf->deleted_codeunits); @@ -2585,7 +2584,7 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message) // Line should always have an NL char internally (represented as NUL), // even if 'noeol' is set. assert(line_size >= 1); - ml_add_deleted_len_buf(buf, (char_u *)dp + line_start, line_size-1); + ml_add_deleted_len_buf(buf, (char_u *)dp + line_start, line_size - 1); /* * special case: If there is only one line in the data block it becomes empty. diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 14930238e5..19144a5dce 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -709,4 +709,3 @@ void free_all_mem(void) } #endif - diff --git a/src/nvim/menu.c b/src/nvim/menu.c index f648a06284..54d3f4c55d 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -236,8 +236,8 @@ void ex_menu(exarg_T *eap) } else if (modes & MENU_TIP_MODE) { map_buf = NULL; // Menu tips are plain text. } else { - map_to = (char *)replace_termcodes((char_u *)map_to, STRLEN(map_to), - (char_u **)&map_buf, false, true, true, CPO_TO_CPO_FLAGS); + map_to = (char *)replace_termcodes((char_u *)map_to, STRLEN(map_to), (char_u **)&map_buf, + REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS); } menuarg.modes = modes; menuarg.noremap[0] = noremap; @@ -486,8 +486,7 @@ erret: } else { menup = &parent->parent->children; } - for (; *menup != NULL && *menup != parent; menup = &((*menup)->next)) { - } + for (; *menup != NULL && *menup != parent; menup = &((*menup)->next)) {} if (*menup == NULL) { // safety check break; } @@ -1656,4 +1655,3 @@ static char *menu_translate_tab_and_shift(char *arg_start) return arg; } - diff --git a/src/nvim/message.c b/src/nvim/message.c index 6708001495..66df3f8a6f 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1022,8 +1022,7 @@ void ex_messages(void *const eap_p) c -= eap->line2; // Skip without number of messages specified - for (p = first_msg_hist; p != NULL && !got_int && c > 0; p = p->next, c--) { - } + for (p = first_msg_hist; p != NULL && !got_int && c > 0; p = p->next, c--) {} } // Display what was not skipped. @@ -1146,6 +1145,7 @@ void wait_return(int redraw) // Don't do mappings here, we put the character back in the // typeahead buffer. no_mapping++; + allow_keys++; // Temporarily disable Recording. If Recording is active, the // character will be recorded later, since it will be added to the @@ -1159,6 +1159,7 @@ void wait_return(int redraw) got_int = false; } no_mapping--; + allow_keys--; reg_recording = save_reg_recording; scriptout = save_scriptout; @@ -1214,7 +1215,7 @@ void wait_return(int redraw) } else if (vim_strchr((char_u *)"\r\n ", c) == NULL && c != Ctrl_C) { // Put the character back in the typeahead buffer. Don't use the // stuff buffer, because lmaps wouldn't work. - ins_char_typebuf(c, mod_mask); + ins_char_typebuf(vgetc_char, vgetc_mod_mask); do_redraw = true; // need a redraw even though there is // typeahead } @@ -2312,18 +2313,18 @@ void msg_scroll_up(bool may_throttle) msg_did_scroll = true; if (msg_use_msgsep()) { if (msg_grid_pos > 0) { - msg_grid_set_pos(msg_grid_pos-1, true); + msg_grid_set_pos(msg_grid_pos - 1, true); } else { grid_del_lines(&msg_grid, 0, 1, msg_grid.Rows, 0, msg_grid.Columns); - memmove(msg_grid.dirty_col, msg_grid.dirty_col+1, - (msg_grid.Rows-1) * sizeof(*msg_grid.dirty_col)); - msg_grid.dirty_col[msg_grid.Rows-1] = 0; + memmove(msg_grid.dirty_col, msg_grid.dirty_col + 1, + (msg_grid.Rows - 1) * sizeof(*msg_grid.dirty_col)); + msg_grid.dirty_col[msg_grid.Rows - 1] = 0; } } else { grid_del_lines(&msg_grid_adj, 0, 1, Rows, 0, Columns); } - grid_fill(&msg_grid_adj, Rows-1, Rows, 0, Columns, ' ', ' ', + grid_fill(&msg_grid_adj, Rows - 1, Rows, 0, Columns, ' ', ' ', HL_ATTR(HLF_MSG)); } @@ -2356,7 +2357,7 @@ void msg_scroll_flush(void) ui_ext_msg_set_pos(msg_grid_pos, true); } - int to_scroll = delta-pos_delta-msg_grid_scroll_discount; + int to_scroll = delta - pos_delta - msg_grid_scroll_discount; assert(to_scroll >= 0); // TODO(bfredl): msg_grid_pos should be 0 already when starting scrolling @@ -2365,8 +2366,8 @@ void msg_scroll_flush(void) ui_call_grid_scroll(msg_grid.handle, 0, Rows, 0, Columns, to_scroll, 0); } - for (int i = MAX(Rows-MAX(delta, 1), 0); i < Rows; i++) { - int row = i-msg_grid_pos; + for (int i = MAX(Rows - MAX(delta, 1), 0); i < Rows; i++) { + int row = i - msg_grid_pos; assert(row >= 0); ui_line(&msg_grid, row, 0, msg_grid.dirty_col[row], msg_grid.Columns, HL_ATTR(HLF_MSG), false); @@ -2879,7 +2880,7 @@ static int do_more_prompt(int typed_char) // scroll up, display line at bottom msg_scroll_up(true); inc_msg_scrolled(); - grid_fill(&msg_grid_adj, Rows-2, Rows-1, 0, Columns, ' ', ' ', + grid_fill(&msg_grid_adj, Rows - 2, Rows - 1, 0, Columns, ' ', ' ', HL_ATTR(HLF_MSG)); mp_last = disp_sb_line(Rows - 2, mp_last); toscroll--; @@ -3042,7 +3043,7 @@ void msg_clr_eos_force(void) HL_ATTR(HLF_MSG)); redraw_cmdline = true; // overwritten the command line - if (msg_row < Rows-1 || msg_col == (cmdmsg_rl ? Columns : 0)) { + if (msg_row < Rows - 1 || msg_col == (cmdmsg_rl ? Columns : 0)) { clear_cmdline = false; // command line has been cleared mode_displayed = false; // mode cleared or overwritten } diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 6b27ce9d7b..4495473074 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -262,8 +262,8 @@ retnomove: } if (grid == 0) { - row -= curwin->w_grid_alloc.comp_row+curwin->w_grid.row_offset; - col -= curwin->w_grid_alloc.comp_col+curwin->w_grid.col_offset; + row -= curwin->w_grid_alloc.comp_row + curwin->w_grid.row_offset; + col -= curwin->w_grid_alloc.comp_col + curwin->w_grid.col_offset; } // When clicking beyond the end of the window, scroll the screen. @@ -512,8 +512,8 @@ static win_T *mouse_find_grid_win(int *gridp, int *rowp, int *colp) win_T *wp = get_win_by_grid_handle(*gridp); if (wp && wp->w_grid_alloc.chars && !(wp->w_floating && !wp->w_float_config.focusable)) { - *rowp = MIN(*rowp-wp->w_grid.row_offset, wp->w_grid.Rows-1); - *colp = MIN(*colp-wp->w_grid.col_offset, wp->w_grid.Columns-1); + *rowp = MIN(*rowp - wp->w_grid.row_offset, wp->w_grid.Rows - 1); + *colp = MIN(*colp - wp->w_grid.col_offset, wp->w_grid.Columns - 1); return wp; } } else if (*gridp == 0) { @@ -523,8 +523,8 @@ static win_T *mouse_find_grid_win(int *gridp, int *rowp, int *colp) continue; } *gridp = grid->handle; - *rowp -= grid->comp_row+wp->w_grid.row_offset; - *colp -= grid->comp_col+wp->w_grid.col_offset; + *rowp -= grid->comp_row + wp->w_grid.row_offset; + *colp -= grid->comp_col + wp->w_grid.col_offset; return wp; } diff --git a/src/nvim/move.c b/src/nvim/move.c index 078b873892..49fa7bbf7f 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -2300,4 +2300,3 @@ void do_check_cursorbind(void) curwin = old_curwin; curbuf = old_curbuf; } - diff --git a/src/nvim/msgpack_rpc/helpers.h b/src/nvim/msgpack_rpc/helpers.h index e5fd92374d..dab8a16b6b 100644 --- a/src/nvim/msgpack_rpc/helpers.h +++ b/src/nvim/msgpack_rpc/helpers.h @@ -21,4 +21,3 @@ #endif #endif // NVIM_MSGPACK_RPC_HELPERS_H - diff --git a/src/nvim/normal.c b/src/nvim/normal.c index ed5f13d00a..74ab50ce1d 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -638,6 +638,7 @@ static void normal_get_additional_char(NormalState *s) int lang; // getting a text character no_mapping++; + allow_keys++; // no mapping for nchar, but allow key codes // Don't generate a CursorHold event here, most commands can't handle // it, e.g., nv_replace(), nv_csearch(). did_cursorhold = true; @@ -676,6 +677,7 @@ static void normal_get_additional_char(NormalState *s) if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) { // Allow mappings defined with ":lmap". no_mapping--; + allow_keys--; if (repl) { State = LREPLACE; } else { @@ -689,6 +691,7 @@ static void normal_get_additional_char(NormalState *s) if (langmap_active) { // Undo the decrement done above no_mapping++; + allow_keys++; } State = NORMAL_BUSY; s->need_flushbuf |= add_to_showcmd(*cp); @@ -769,6 +772,7 @@ static void normal_get_additional_char(NormalState *s) no_mapping++; } no_mapping--; + allow_keys--; } static void normal_invert_horizontal(NormalState *s) @@ -826,6 +830,7 @@ static bool normal_get_command_count(NormalState *s) if (s->ctrl_w) { no_mapping++; + allow_keys++; // no mapping for nchar, but keys } no_zero_mapping++; // don't map zero here @@ -834,6 +839,7 @@ static bool normal_get_command_count(NormalState *s) no_zero_mapping--; if (s->ctrl_w) { no_mapping--; + allow_keys--; } s->need_flushbuf |= add_to_showcmd(s->c); } @@ -844,9 +850,11 @@ static bool normal_get_command_count(NormalState *s) s->ca.opcount = s->ca.count0; // remember first count s->ca.count0 = 0; no_mapping++; + allow_keys++; // no mapping for nchar, but keys s->c = plain_vgetc(); // get next character LANGMAP_ADJUST(s->c, true); no_mapping--; + allow_keys--; s->need_flushbuf |= add_to_showcmd(s->c); return true; } @@ -995,7 +1003,7 @@ static int normal_execute(VimState *state, int key) // restart automatically. // Insert the typed character in the typeahead buffer, so that it can // be mapped in Insert mode. Required for ":lmap" to work. - int len = ins_char_typebuf(s->c, mod_mask); + int len = ins_char_typebuf(vgetc_char, vgetc_mod_mask); // When recording and gotchars() was called the character will be // recorded again, remove the previous recording. @@ -2593,7 +2601,7 @@ void clear_showcmd(void) sprintf((char *)showcmd_buf, "%d-%d", chars, bytes); } } - int limit = ui_has(kUIMessages) ? SHOWCMD_BUFLEN-1 : SHOWCMD_COLS; + int limit = ui_has(kUIMessages) ? SHOWCMD_BUFLEN - 1 : SHOWCMD_COLS; showcmd_buf[limit] = NUL; // truncate showcmd_visual = true; } else { @@ -2651,7 +2659,7 @@ bool add_to_showcmd(int c) } size_t old_len = STRLEN(showcmd_buf); size_t extra_len = STRLEN(p); - size_t limit = ui_has(kUIMessages) ? SHOWCMD_BUFLEN-1 : SHOWCMD_COLS; + size_t limit = ui_has(kUIMessages) ? SHOWCMD_BUFLEN - 1 : SHOWCMD_COLS; if (old_len + extra_len > limit) { size_t overflow = old_len + extra_len - limit; memmove(showcmd_buf, showcmd_buf + overflow, old_len - overflow + 1); @@ -2879,8 +2887,7 @@ static void nv_ignore(cmdarg_T *cap) /// Command character that doesn't do anything, but unlike nv_ignore() does /// start edit(). Used for "startinsert" executed while starting up. static void nv_nop(cmdarg_T *cap) -{ -} +{} /// Command character doesn't exist. static void nv_error(cmdarg_T *cap) @@ -3407,9 +3414,11 @@ static void nv_zet(cmdarg_T *cap) n = nchar - '0'; for (;;) { no_mapping++; + allow_keys++; // no mapping for nchar, but allow key codes nchar = plain_vgetc(); LANGMAP_ADJUST(nchar, true); no_mapping--; + allow_keys--; (void)add_to_showcmd(nchar); if (nchar == K_DEL || nchar == K_KDEL) { n /= 10; @@ -3785,9 +3794,11 @@ dozet: case 'u': // "zug" and "zuw": undo "zg" and "zw" no_mapping++; + allow_keys++; // no mapping for nchar, but allow key codes nchar = plain_vgetc(); LANGMAP_ADJUST(nchar, true); no_mapping--; + allow_keys--; (void)add_to_showcmd(nchar); if (vim_strchr((char_u *)"gGwW", nchar) == NULL) { clearopbeep(cap->oap); @@ -4603,7 +4614,7 @@ static void nv_gotofile(cmdarg_T *cap) (void)autowrite(curbuf, false); } setpcmark(); - if (do_ecmd(0, ptr, NULL, NULL, ECMD_LAST, + if (do_ecmd(0, (char *)ptr, NULL, NULL, ECMD_LAST, buf_hide(curbuf) ? ECMD_HIDE : 0, curwin) == OK && cap->nchar == 'F' && lnum >= 0) { curwin->w_cursor.lnum = lnum; @@ -5154,7 +5165,7 @@ static void nv_replace(cmdarg_T *cap) // get another character if (cap->nchar == Ctrl_V) { had_ctrl_v = Ctrl_V; - cap->nchar = get_literal(); + cap->nchar = get_literal(false); // Don't redo a multibyte character with CTRL-V. if (cap->nchar > DEL) { had_ctrl_v = NUL; @@ -5369,7 +5380,7 @@ static void nv_vreplace(cmdarg_T *cap) emsg(_(e_modifiable)); } else { if (cap->extra_char == Ctrl_V) { // get another character - cap->extra_char = get_literal(); + cap->extra_char = get_literal(false); } stuffcharReadbuff(cap->extra_char); stuffcharReadbuff(ESC); diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d6550f38fa..36e773a82d 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -406,14 +406,14 @@ static void shift_block(oparg_T *oap, int amount) int col_pre = bd.pre_whitesp_c - (bd.startspaces != 0); bd.textcol -= col_pre; const int len = (int)STRLEN(bd.textstart) + 1; - int col = bd.textcol + i +j + len; + int col = bd.textcol + i + j + len; assert(col >= 0); newp = (char_u *)xmalloc((size_t)col); memset(newp, NUL, (size_t)col); memmove(newp, oldp, (size_t)bd.textcol); startcol = bd.textcol; - oldlen = (int)(bd.textstart-old_textstart) + col_pre; - newlen = i+j; + oldlen = (int)(bd.textstart - old_textstart) + col_pre; + newlen = i + j; memset(newp + bd.textcol, TAB, (size_t)i); memset(newp + bd.textcol + i, ' ', (size_t)j); // the end @@ -510,7 +510,7 @@ static void shift_block(oparg_T *oap, int amount) // replace the line ml_replace(curwin->w_cursor.lnum, newp, false); changed_bytes(curwin->w_cursor.lnum, bd.textcol); - extmark_splice_cols(curbuf, (int)curwin->w_cursor.lnum-1, startcol, + extmark_splice_cols(curbuf, (int)curwin->w_cursor.lnum - 1, startcol, oldlen, newlen, kExtmarkUndo); State = oldstate; @@ -615,8 +615,8 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def STRMOVE(newp + offset, oldp); ml_replace(lnum, newp, false); - extmark_splice_cols(curbuf, (int)lnum-1, startcol, - skipped, offset-startcol, kExtmarkUndo); + extmark_splice_cols(curbuf, (int)lnum - 1, startcol, + skipped, offset - startcol, kExtmarkUndo); if (lnum == oap->end.lnum) { // Set "']" mark to the end of the block instead of the end of @@ -943,7 +943,7 @@ int do_record(int c) } // Name of requested register, or empty string for unnamed operation. - char buf[NUMBUFLEN+2]; + char buf[NUMBUFLEN + 2]; buf[0] = (char)regname; buf[1] = NUL; (void)tv_dict_add_str(dict, S_LEN("regname"), buf); @@ -1652,8 +1652,8 @@ int op_delete(oparg_T *oap) // replace the line ml_replace(lnum, newp, false); - extmark_splice_cols(curbuf, (int)lnum-1, bd.textcol, - bd.textlen, bd.startspaces+bd.endspaces, + extmark_splice_cols(curbuf, (int)lnum - 1, bd.textcol, + bd.textlen, bd.startspaces + bd.endspaces, kExtmarkUndo); } @@ -1688,7 +1688,7 @@ int op_delete(oparg_T *oap) truncate_line(false); // delete the rest of the line extmark_splice_cols(curbuf, - (int)curwin->w_cursor.lnum-1, curwin->w_cursor.col, + (int)curwin->w_cursor.lnum - 1, curwin->w_cursor.col, old_len - curwin->w_cursor.col, 0, kExtmarkUndo); // leave cursor past last char in line @@ -1808,8 +1808,8 @@ int op_delete(oparg_T *oap) curwin->w_cursor = curpos; // restore curwin->w_cursor (void)do_join(2, false, false, false, false); curbuf_splice_pending--; - extmark_splice(curbuf, (int)startpos.lnum-1, startpos.col, - (int)oap->line_count-1, n, deleted_bytes, + extmark_splice(curbuf, (int)startpos.lnum - 1, startpos.col, + (int)oap->line_count - 1, n, deleted_bytes, 0, 0, 0, kExtmarkUndo); } if (oap->op_type == OP_DELETE) { @@ -1855,7 +1855,7 @@ static inline void pbyte(pos_T lp, int c) assert(c <= UCHAR_MAX); *(ml_get_buf(curbuf, lp.lnum, true) + lp.col) = (char_u)c; if (!curbuf_splice_pending) { - extmark_splice_cols(curbuf, (int)lp.lnum-1, lp.col, 1, 1, kExtmarkUndo); + extmark_splice_cols(curbuf, (int)lp.lnum - 1, lp.col, 1, 1, kExtmarkUndo); } } @@ -2011,9 +2011,9 @@ static int op_replace(oparg_T *oap, int c) xfree(after_p); } curbuf_splice_pending--; - extmark_splice(curbuf, (int)baselnum-1, bd.textcol, + extmark_splice(curbuf, (int)baselnum - 1, bd.textcol, 0, bd.textlen, bd.textlen, - newrows, newcols, newrows+newcols, kExtmarkUndo); + newrows, newcols, newrows + newcols, kExtmarkUndo); } } else { // Characterwise or linewise motion replace. @@ -2598,8 +2598,8 @@ int op_change(oparg_T *oap) oldp += bd.textcol; STRMOVE(newp + offset, oldp); ml_replace(linenr, newp, false); - extmark_splice_cols(curbuf, (int)linenr-1, bd.textcol, - 0, vpos.coladd+(int)ins_len, kExtmarkUndo); + extmark_splice_cols(curbuf, (int)linenr - 1, bd.textcol, + 0, vpos.coladd + (int)ins_len, kExtmarkUndo); } } check_cursor(); @@ -2938,7 +2938,7 @@ static void do_autocmd_textyankpost(oparg_T *oap, yankreg_T *reg) (void)tv_dict_add_list(dict, S_LEN("regcontents"), list); // Register type. - char buf[NUMBUFLEN+2]; + char buf[NUMBUFLEN + 2]; format_reg_type(reg->y_type, reg->y_width, buf, ARRAY_SIZE(buf)); (void)tv_dict_add_str(dict, S_LEN("regtype"), buf); @@ -3426,7 +3426,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) assert(columns >= 0); memmove(ptr, oldp + bd.textcol + delcount, (size_t)columns); ml_replace(curwin->w_cursor.lnum, newp, false); - extmark_splice_cols(curbuf, (int)curwin->w_cursor.lnum-1, bd.textcol, + extmark_splice_cols(curbuf, (int)curwin->w_cursor.lnum - 1, bd.textcol, delcount, addcount, kExtmarkUndo); ++curwin->w_cursor.lnum; @@ -3555,7 +3555,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) curwin->w_cursor.col += (colnr_T)(totlen - 1); } changed_bytes(lnum, col); - extmark_splice_cols(curbuf, (int)lnum-1, col, + extmark_splice_cols(curbuf, (int)lnum - 1, col, 0, (int)totlen, kExtmarkUndo); if (VIsual_active) { lnum++; @@ -3652,20 +3652,20 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) int lastsize = 0; if (y_type == kMTCharWise || (y_type == kMTLineWise && flags & PUT_LINE_SPLIT)) { - for (i = 0; i < y_size-1; i++) { + for (i = 0; i < y_size - 1; i++) { totsize += (bcount_t)STRLEN(y_array[i]) + 1; } - lastsize = (int)STRLEN(y_array[y_size-1]); + lastsize = (int)STRLEN(y_array[y_size - 1]); totsize += lastsize; } if (y_type == kMTCharWise) { - extmark_splice(curbuf, (int)new_cursor.lnum-1, col, 0, 0, 0, - (int)y_size-1, lastsize, totsize, + extmark_splice(curbuf, (int)new_cursor.lnum - 1, col, 0, 0, 0, + (int)y_size - 1, lastsize, totsize, kExtmarkUndo); } else if (y_type == kMTLineWise && flags & PUT_LINE_SPLIT) { // Account for last pasted NL + last NL - extmark_splice(curbuf, (int)new_cursor.lnum-1, col + 1, 0, 0, 0, - (int)y_size+1, 0, totsize+2, kExtmarkUndo); + extmark_splice(curbuf, (int)new_cursor.lnum - 1, col + 1, 0, 0, 0, + (int)y_size + 1, 0, totsize + 2, kExtmarkUndo); } if (cnt == 1) { @@ -4139,8 +4139,8 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions } if (t > 0 && curbuf_splice_pending == 0) { - colnr_T removed = (int)(curr- curr_start); - extmark_splice(curbuf, (int)curwin->w_cursor.lnum-1, sumsize, + colnr_T removed = (int)(curr - curr_start); + extmark_splice(curbuf, (int)curwin->w_cursor.lnum - 1, sumsize, 1, removed, removed + 1, 0, spaces[t], spaces[t], kExtmarkUndo); @@ -4313,8 +4313,7 @@ static int same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, in * The first line has to be saved, only one line can be locked at a time. */ line1 = vim_strsave(ml_get(lnum)); - for (idx1 = 0; ascii_iswhite(line1[idx1]); ++idx1) { - } + for (idx1 = 0; ascii_iswhite(line1[idx1]); idx1++) {} line2 = ml_get(lnum + 1); for (idx2 = 0; idx2 < leader2_len; ++idx2) { if (!ascii_iswhite(line2[idx2])) { @@ -5221,13 +5220,13 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) if (!pre) { if (subtract) { if (n > oldn) { - n = 1 + (n ^ (uvarnumber_T)-1); + n = 1 + (n ^ (uvarnumber_T) - 1); negative ^= true; } } else { // add if (n < oldn) { - n = (n ^ (uvarnumber_T)-1); + n = (n ^ (uvarnumber_T) - 1); negative ^= true; } } @@ -7011,9 +7010,9 @@ bool prepare_yankreg_from_object(yankreg_T *reg, String regtype, size_t lines) if (!ascii_isdigit(regtype.data[1])) { return false; } - const char *p = regtype.data+1; + const char *p = regtype.data + 1; reg->y_width = getdigits_int((char_u **)&p, false, 1) - 1; - if (regtype.size > (size_t)(p-regtype.data)) { + if (regtype.size > (size_t)(p - regtype.data)) { return false; } } @@ -7027,12 +7026,12 @@ bool prepare_yankreg_from_object(yankreg_T *reg, String regtype, size_t lines) void finish_yankreg_from_object(yankreg_T *reg, bool clipboard_adjust) { - if (reg->y_size > 0 && STRLEN(reg->y_array[reg->y_size-1]) == 0) { + if (reg->y_size > 0 && STRLEN(reg->y_array[reg->y_size - 1]) == 0) { // a known-to-be charwise yank might have a final linebreak // but otherwise there is no line after the final newline if (reg->y_type != kMTCharWise) { if (reg->y_type == kMTUnknown || clipboard_adjust) { - xfree(reg->y_array[reg->y_size-1]); + xfree(reg->y_array[reg->y_size - 1]); reg->y_size--; } if (reg->y_type == kMTUnknown) { @@ -7135,11 +7134,11 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) reg->y_array[tv_idx++] = (char_u *)xstrdupnul((const char *)TV_LIST_ITEM_TV(li)->vval.v_string); }); - if (reg->y_size > 0 && STRLEN(reg->y_array[reg->y_size-1]) == 0) { + if (reg->y_size > 0 && STRLEN(reg->y_array[reg->y_size - 1]) == 0) { // a known-to-be charwise yank might have a final linebreak // but otherwise there is no line after the final newline if (reg->y_type != kMTCharWise) { - xfree(reg->y_array[reg->y_size-1]); + xfree(reg->y_array[reg->y_size - 1]); reg->y_size--; if (reg->y_type == kMTUnknown) { reg->y_type = kMTLineWise; @@ -7407,7 +7406,7 @@ bcount_t get_region_bytecount(buf_T *buf, linenr_T start_lnum, linenr_T end_lnum const char *first = (const char *)ml_get_buf(buf, start_lnum, false); bcount_t deleted_bytes = (bcount_t)STRLEN(first) - start_col + 1; - for (linenr_T i = 1; i <= end_lnum-start_lnum-1; i++) { + for (linenr_T i = 1; i <= end_lnum - start_lnum - 1; i++) { if (start_lnum + i > max_lnum) { return deleted_bytes; } diff --git a/src/nvim/option.c b/src/nvim/option.c index 49c76d2452..1a40bac91a 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3015,7 +3015,7 @@ ambw_end: } else if (varp == &p_pt) { // 'pastetoggle': translate key codes like in a mapping if (*p_pt) { - (void)replace_termcodes(p_pt, STRLEN(p_pt), &p, true, true, true, + (void)replace_termcodes(p_pt, STRLEN(p_pt), &p, REPTERM_FROM_PART | REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS); if (p != NULL) { if (new_value_alloced) { @@ -3858,10 +3858,10 @@ static bool parse_winhl_opt(win_T *wp) if (!colon) { return false; } - size_t nlen = (size_t)(colon-p); - char *hi = colon+1; + size_t nlen = (size_t)(colon - p); + char *hi = colon + 1; char *commap = xstrchrnul(hi, ','); - size_t len = (size_t)(commap-hi); + size_t len = (size_t)(commap - hi); int hl_id = len ? syn_check_group(hi, len) : -1; if (strncmp("Normal", p, nlen) == 0) { @@ -3879,7 +3879,7 @@ static bool parse_winhl_opt(win_T *wp) } } - p = *commap ? commap+1 : ""; + p = *commap ? commap + 1 : ""; } wp->w_hl_id_normal = w_hl_id_normal; @@ -5222,7 +5222,8 @@ int find_key_option_len(const char_u *arg_arg, size_t len, bool has_lt) } else if (has_lt) { arg--; // put arg at the '<' modifiers = 0; - key = find_special_key(&arg, len + 1, &modifiers, true, true, false); + key = find_special_key(&arg, len + 1, &modifiers, + FSK_KEYCODE | FSK_KEEP_X_KEY | FSK_SIMPLIFY, NULL); if (modifiers) { // can't handle modifiers here key = 0; } diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 745b888b5e..9ee2f57b3d 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -98,7 +98,7 @@ static void create_cursorhold_event(bool events_enabled) /// Low level input function /// -/// wait until either the input buffer is non-empty or , if `events` is not NULL +/// wait until either the input buffer is non-empty or, if `events` is not NULL /// until `events` is non-empty. int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *events) { @@ -106,6 +106,11 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *e return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen); } + // No risk of a UI flood, so disable CTRL-C "interrupt" behavior if it's mapped. + if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) { + ctrl_c_interrupts = false; + } + InbufPollResult result; if (ms >= 0) { if ((result = inbuf_poll(ms, events)) == kInputNone) { @@ -127,6 +132,8 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt, MultiQueue *e } } + ctrl_c_interrupts = true; + // If input was put directly in typeahead buffer bail out here. if (typebuf_changed(tb_change_cnt)) { return 0; @@ -238,9 +245,9 @@ size_t input_enqueue(String keys) // but since the keys are UTF-8, so the first byte cannot be // K_SPECIAL(0x80). uint8_t buf[19] = { 0 }; + // Do not simplify the keys here. Simplification will be done later. unsigned int new_size - = trans_special((const uint8_t **)&ptr, (size_t)(end - ptr), buf, true, - false); + = trans_special((const uint8_t **)&ptr, (size_t)(end - ptr), buf, FSK_KEYCODE, NULL); if (new_size) { new_size = handle_mouse_event(&ptr, buf, new_size); @@ -275,7 +282,7 @@ size_t input_enqueue(String keys) } size_t rv = (size_t)(ptr - keys.data); - process_interrupts(); + process_ctrl_c(); return rv; } @@ -413,7 +420,7 @@ size_t input_enqueue_mouse(int code, uint8_t modifier, int grid, int row, int co mouse_row = row; mouse_col = col; - size_t written = 3 + (size_t)(p-buf); + size_t written = 3 + (size_t)(p - buf); rbuffer_write(input_buffer, (char *)buf, written); return written; } @@ -480,15 +487,20 @@ static void input_read_cb(Stream *stream, RBuffer *buf, size_t c, void *data, bo } } -static void process_interrupts(void) +static void process_ctrl_c(void) { - if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) { + if (!ctrl_c_interrupts) { return; } size_t consume_count = 0; RBUFFER_EACH_REVERSE(input_buffer, c, i) { - if ((uint8_t)c == Ctrl_C) { + if ((uint8_t)c == Ctrl_C + || ((uint8_t)c == 'C' && i >= 3 + && (uint8_t)(*rbuffer_get(input_buffer, i - 3)) == K_SPECIAL + && (uint8_t)(*rbuffer_get(input_buffer, i - 2)) == KS_MODIFIER + && (uint8_t)(*rbuffer_get(input_buffer, i - 1)) == MOD_MASK_CTRL)) { + *rbuffer_get(input_buffer, i) = Ctrl_C; got_int = true; consume_count = i; break; diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c index 5bbd22c610..6233a90638 100644 --- a/src/nvim/os/pty_process_win.c +++ b/src/nvim/os/pty_process_win.c @@ -47,9 +47,9 @@ int pty_process_spawn(PtyProcess *ptyproc) assert(proc->err.closed); - if (!os_has_conpty_working() - || (conpty_object = - os_conpty_init(&in_name, &out_name, ptyproc->width, ptyproc->height)) == NULL) { + if (!os_has_conpty_working() || (conpty_object = os_conpty_init(&in_name, + &out_name, ptyproc->width, + ptyproc->height)) == NULL) { status = UV_ENOSYS; goto cleanup; } @@ -172,13 +172,11 @@ void pty_process_close(PtyProcess *ptyproc) void pty_process_close_master(PtyProcess *ptyproc) FUNC_ATTR_NONNULL_ALL -{ -} +{} void pty_process_teardown(Loop *loop) FUNC_ATTR_NONNULL_ALL -{ -} +{} static void pty_process_connect_cb(uv_connect_t *req, int status) FUNC_ATTR_NONNULL_ALL diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 5680cdbe42..57cf4a44f5 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -746,7 +746,7 @@ char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags, size_t *ret } // Add the redirection stuff - char_u *command = make_filter_cmd(cmd, infile, tempname); + char_u *command = (char_u *)make_filter_cmd((char *)cmd, (char *)infile, (char *)tempname); // Call the shell to execute the command (errors are ignored). // Don't check timestamps here. @@ -1099,8 +1099,8 @@ static void out_data_append_to_screen(char *output, size_t *count, bool eof) // incomplete UTF-8 sequence that could be composing with the last // complete sequence. // This will be corrected when we switch to vterm based implementation - int i = *p ? utfc_ptr2len_len((char_u *)p, (int)(end-p)) : 1; - if (!eof && i == 1 && utf8len_tab_zero[*(uint8_t *)p] > (end-p)) { + int i = *p ? utfc_ptr2len_len((char_u *)p, (int)(end - p)) : 1; + if (!eof && i == 1 && utf8len_tab_zero[*(uint8_t *)p] > (end - p)) { *count = (size_t)(p - output); goto end; } @@ -1331,4 +1331,3 @@ static char *shell_xescape_xquote(const char *cmd) return ncmd; } - diff --git a/src/nvim/path.c b/src/nvim/path.c index 66cfb3b31a..0ecdba468a 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1528,9 +1528,8 @@ void simplify_filename(char_u *filename) if (vim_ispathsep(*p)) { relative = false; do { - ++p; - } - while (vim_ispathsep(*p)); + p++; + } while (vim_ispathsep(*p)); } start = p; // remember start after "c:/" or "/" or "///" @@ -2325,7 +2324,7 @@ int append_path(char *path, const char *to_append, size_t max_len) } // Combine the path segments, separated by a slash. - if (current_length > 0 && !vim_ispathsep_nocolon(path[current_length-1])) { + if (current_length > 0 && !vim_ispathsep_nocolon(path[current_length - 1])) { current_length += 1; // Count the trailing slash. // +1 for the NUL at the end. @@ -2378,7 +2377,7 @@ static int path_to_absolute(const char_u *fname, char_u *buf, size_t len, int fo } else { assert(p >= fname); memcpy(relative_directory, fname, (size_t)(p - fname)); - relative_directory[p-fname] = NUL; + relative_directory[p - fname] = NUL; } end_of_path = (char *)(p + 1); } else { diff --git a/src/nvim/plines.c b/src/nvim/plines.c index a572f747df..bbe1a41b00 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -61,7 +61,7 @@ int win_get_fill(win_T *wp, linenr_T lnum) int n = diff_check(wp, lnum); if (n > 0) { - return virt_lines+n; + return virt_lines + n; } } return virt_lines; @@ -125,7 +125,7 @@ int plines_win_nofold(win_T *wp, linenr_T lnum) } col -= (unsigned int)width; width += win_col_off2(wp); - assert(col <= INT_MAX && (int)col < INT_MAX - (width -1)); + assert(col <= INT_MAX && (int)col < INT_MAX - (width - 1)); return ((int)col + (width - 1)) / width + 1; } @@ -507,4 +507,3 @@ static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp) } return n; } - diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index e354a589a5..15d0ae6c84 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -422,7 +422,7 @@ void pum_redraw(void) pum_grid.zindex = ((State == CMDLINE) ? kZIndexCmdlinePopupMenu : kZIndexPopupMenu); - bool moved = ui_comp_put_grid(&pum_grid, pum_row, pum_col-col_off, + bool moved = ui_comp_put_grid(&pum_grid, pum_row, pum_col - col_off, pum_height, grid_width, false, true); bool invalid_grid = moved || pum_invalid; pum_invalid = false; @@ -439,7 +439,7 @@ void pum_redraw(void) const char *anchor = pum_above ? "SW" : "NW"; int row_off = pum_above ? -pum_height : 0; ui_call_win_float_pos(pum_grid.handle, -1, cstr_to_string(anchor), - pum_anchor_grid, pum_row-row_off, pum_col-col_off, + pum_anchor_grid, pum_row - row_off, pum_col - col_off, false, pum_grid.zindex); } diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 03552a0a19..7c64b0aa0b 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -78,8 +78,7 @@ struct qfline_S { #define INVALID_QFBUFNR (0) /// Quickfix list type. -typedef enum -{ +typedef enum { QFLT_QUICKFIX, ///< Quickfix list - global list QFLT_LOCATION, ///< Location list - per window list QFLT_INTERNAL, ///< Internal - Temporary list used by @@ -429,8 +428,7 @@ static char *scanf_fmt_to_regpat(const char **pefmp, const char *efm, int len, c } if (efmp < efm + len) { *regpat++ = *++efmp; // could be ']' - while (efmp < efm + len && (*regpat++ = *++efmp) != ']') { - } + while (efmp < efm + len && (*regpat++ = *++efmp) != ']') {} if (efmp == efm + len) { emsg(_("E374: Missing ] in format string")); return NULL; @@ -4396,7 +4394,7 @@ void ex_make(exarg_T *eap) char *const cmd = make_get_fullcmd((char *)eap->arg, fname); - do_shell((char_u *)cmd, 0); + do_shell(cmd, 0); incr_quickfix_busy(); @@ -5425,7 +5423,7 @@ static int vgr_process_args(exarg_T *eap, vgr_args_T *args) } // Get the search pattern: either white-separated or enclosed in // - char *p = (char *)skip_vimgrep_pat(eap->arg, (char_u **)&args->spat, &args->flags); + char *p = skip_vimgrep_pat((char *)eap->arg, &args->spat, &args->flags); if (p == NULL) { emsg(_(e_invalpat)); return FAIL; @@ -7240,7 +7238,7 @@ void ex_helpgrep(exarg_T *eap) incr_quickfix_busy(); // Check for a specified language - char *const lang = (char *)check_help_lang(eap->arg); + char *const lang = check_help_lang((char *)eap->arg); regmatch_T regmatch = { .regprog = vim_regcomp(eap->arg, RE_MAGIC + RE_STRING), .rm_ic = false, @@ -7300,4 +7298,3 @@ void ex_helpgrep(exarg_T *eap) } } } - diff --git a/src/nvim/rbuffer.c b/src/nvim/rbuffer.c index 4ac50095b3..d280e08c03 100644 --- a/src/nvim/rbuffer.c +++ b/src/nvim/rbuffer.c @@ -224,4 +224,3 @@ int rbuffer_cmp(RBuffer *buf, const char *str, size_t count) return memcmp(str + n, buf->start_ptr, count); } - diff --git a/src/nvim/regexp.h b/src/nvim/regexp.h index 6edbcf8a31..085f78af54 100644 --- a/src/nvim/regexp.h +++ b/src/nvim/regexp.h @@ -19,6 +19,7 @@ // regexp.c #ifdef INCLUDE_GENERATED_DECLARATIONS # include "regexp.h.generated.h" + # include "regexp_bt.h.generated.h" #endif diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 1102096b32..970072a53c 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -485,7 +485,7 @@ static void expand_pack_entry(RuntimeSearchPath *search_path, Map(String, handle STRLCPY(buf, pack_entry, sizeof buf); STRLCPY(buf + pack_entry_len, start_pat[i], sizeof buf - pack_entry_len); expand_rtp_entry(search_path, rtp_used, buf, false); - size_t after_size = STRLEN(buf)+7; + size_t after_size = STRLEN(buf) + 7; char *after = xmallocz(after_size); xstrlcpy(after, buf, after_size); xstrlcat(after, "/after", after_size); @@ -499,7 +499,7 @@ static bool path_is_after(char_u *buf, size_t buflen) // vim8 considers all dirs like "foo/bar_after", "Xafter" etc, as an // "after" dir in SOME codepaths not not in ALL codepaths. return buflen >= 5 - && (!(buflen >= 6) || vim_ispathsep(buf[buflen-6])) + && (!(buflen >= 6) || vim_ispathsep(buf[buflen - 6])) && STRCMP(buf + buflen - 5, "after") == 0; } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 807503fd00..81c8830b84 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -390,7 +390,7 @@ int update_screen(int type) // CLEAR is already handled if (type == NOT_VALID && !ui_has(kUIMultigrid) && msg_scrolled) { ui_comp_set_screen_valid(false); - for (int i = valid; i < Rows-p_ch; i++) { + for (int i = valid; i < Rows - p_ch; i++) { grid_clear_line(&default_grid, default_grid.line_offset[i], Columns, false); } @@ -409,7 +409,7 @@ int update_screen(int type) curwin->w_redr_status = true; } } - msg_grid_set_pos(Rows-p_ch, false); + msg_grid_set_pos(Rows - p_ch, false); msg_grid_invalid = false; } else if (msg_scrolled > Rows - 5) { // clearing is faster type = CLEAR; @@ -473,7 +473,7 @@ int update_screen(int type) // After disabling msgsep the grid might not have been deallocated yet, // hence we also need to check msg_grid.chars if (type == NOT_VALID && (msg_use_grid() || msg_grid.chars)) { - grid_fill(&default_grid, Rows-p_ch, Rows, 0, Columns, ' ', ' ', 0); + grid_fill(&default_grid, Rows - p_ch, Rows, 0, Columns, ' ', ' ', 0); } ui_comp_set_screen_valid(true); @@ -1953,7 +1953,7 @@ static size_t fill_foldcolumn(char_u *p, win_T *wp, foldinfo_T foldinfo, linenr_ char_counter += len; } - return MAX(char_counter + (fdc-i), (size_t)fdc); + return MAX(char_counter + (fdc - i), (size_t)fdc); } static inline void provider_err_virt_text(linenr_T lnum, char *err) @@ -1964,7 +1964,7 @@ static inline void provider_err_virt_text(linenr_T lnum, char *err) ((VirtTextChunk){ .text = provider_err, .hl_id = hl_err })); err_decor.virt_text_width = mb_string2cells((char_u *)err); - decor_add_ephemeral(lnum-1, 0, lnum-1, 0, &err_decor); + decor_add_ephemeral(lnum - 1, 0, lnum - 1, 0, &err_decor); } static inline void get_line_number_str(win_T *wp, linenr_T lnum, char_u *buf, size_t buf_len) @@ -2159,7 +2159,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc row = startrow; buf_T *buf = wp->w_buffer; - bool end_fill = (lnum == buf->b_ml.ml_line_count+1); + bool end_fill = (lnum == buf->b_ml.ml_line_count + 1); if (!number_only) { // To speed up the loop below, set extra_check when there is linebreak, @@ -2183,9 +2183,9 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc } } - has_decor = decor_redraw_line(buf, lnum-1, &decor_state); + has_decor = decor_redraw_line(buf, lnum - 1, &decor_state); - providers_invoke_line(wp, providers, lnum-1, &has_decor, &provider_err); + providers_invoke_line(wp, providers, lnum - 1, &has_decor, &provider_err); if (provider_err) { provider_err_virt_text(lnum, provider_err); @@ -2389,7 +2389,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc memset(sattrs, 0, sizeof(sattrs)); num_signs = buf_get_signattrs(wp->w_buffer, lnum, sattrs); - decor_redraw_signs(buf, lnum-1, &num_signs, sattrs); + decor_redraw_signs(buf, lnum - 1, &num_signs, sattrs); // If this line has a sign with line highlighting set line_attr. // TODO(bfredl, vigoux): this should not take priority over decoration! @@ -3340,7 +3340,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (has_decor && v > 0) { bool selected = (area_active || (area_highlighting && noinvcur && (colnr_T)vcol == wp->w_virtcol)); - int extmark_attr = decor_redraw_col(wp->w_buffer, (colnr_T)v-1, off, + int extmark_attr = decor_redraw_col(wp->w_buffer, (colnr_T)v - 1, off, selected, &decor_state); if (extmark_attr != 0) { if (!attr_pri) { @@ -4206,7 +4206,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc screen_adjust_grid(¤t_grid, ¤t_row, &dummy_col); // Force a redraw of the first column of the next line. - current_grid->attrs[current_grid->line_offset[current_row+1]] = -1; + current_grid->attrs[current_grid->line_offset[current_row + 1]] = -1; // Remember that the line wraps, used for modeless copy. current_grid->line_wraps[current_row] = true; @@ -4291,7 +4291,7 @@ void draw_virt_text(buf_T *buf, int col_off, int *end_col, int max_col) } else if (item->decor.virt_text_pos == kVTEndOfLine && do_eol) { item->win_col = state->eol_col; } else if (item->decor.virt_text_pos == kVTWinCol) { - item->win_col = MAX(item->decor.col+col_off, 0); + item->win_col = MAX(item->decor.col + col_off, 0); } } if (item->win_col < 0) { @@ -4299,10 +4299,10 @@ void draw_virt_text(buf_T *buf, int col_off, int *end_col, int max_col) } int col = draw_virt_text_item(buf, item->win_col, item->decor.virt_text, - item->decor.hl_mode, max_col, item->win_col-col_off); + item->decor.hl_mode, max_col, item->win_col - col_off); item->win_col = -2; // deactivate if (item->decor.virt_text_pos == kVTEndOfLine && do_eol) { - state->eol_col = col+1; + state->eol_col = col + 1; } *end_col = MAX(*end_col, col); @@ -4348,7 +4348,7 @@ static int draw_virt_text_item(buf_T *buf, int col, VirtText vt, HlMode hl_mode, } schar_T dummy[2]; int cells = line_putchar(buf, &s, through ? dummy : &linebuf_char[col], - max_col-col, false, vcol); + max_col - col, false, vcol); // if we failed to emit a char, we still need to advance cells = MAX(cells, 1); @@ -4596,8 +4596,8 @@ static void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, if (bg_attr) { for (int c = col; c < endcol; c++) { - linebuf_attr[off_from+c] = - hl_combine_attr(bg_attr, linebuf_attr[off_from+c]); + linebuf_attr[off_from + c] = + hl_combine_attr(bg_attr, linebuf_attr[off_from + c]); } } @@ -4634,7 +4634,7 @@ static void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, schar_copy(grid->chars[off_to], linebuf_char[off_from]); if (char_cells == 2) { - schar_copy(grid->chars[off_to+1], linebuf_char[off_from+1]); + schar_copy(grid->chars[off_to + 1], linebuf_char[off_from + 1]); } grid->attrs[off_to] = linebuf_attr[off_from]; @@ -4674,7 +4674,7 @@ static void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, } else if (clear_end == -1) { end_dirty = endcol; } - clear_end = col+1; + clear_end = col + 1; } col++; off_to++; @@ -4694,7 +4694,7 @@ static void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, start_dirty = end_dirty; } if (clear_end > start_dirty) { - ui_line(grid, row, coloff+start_dirty, coloff+end_dirty, coloff+clear_end, + ui_line(grid, row, coloff + start_dirty, coloff + end_dirty, coloff + clear_end, bg_attr, wrap); } } @@ -5611,39 +5611,39 @@ static void win_redr_border(win_T *wp) grid_put_schar(grid, 0, 0, chars[0], attrs[0]); } for (int i = 0; i < icol; i++) { - grid_put_schar(grid, 0, i+adj[3], chars[1], attrs[1]); + grid_put_schar(grid, 0, i + adj[3], chars[1], attrs[1]); } if (adj[1]) { - grid_put_schar(grid, 0, icol+adj[3], chars[2], attrs[2]); + grid_put_schar(grid, 0, icol + adj[3], chars[2], attrs[2]); } grid_puts_line_flush(false); } for (int i = 0; i < irow; i++) { if (adj[3]) { - grid_puts_line_start(grid, i+adj[0]); - grid_put_schar(grid, i+adj[0], 0, chars[7], attrs[7]); + grid_puts_line_start(grid, i + adj[0]); + grid_put_schar(grid, i + adj[0], 0, chars[7], attrs[7]); grid_puts_line_flush(false); } if (adj[1]) { int ic = (i == 0 && !adj[0] && chars[2][0]) ? 2 : 3; - grid_puts_line_start(grid, i+adj[0]); - grid_put_schar(grid, i+adj[0], icol+adj[3], chars[ic], attrs[ic]); + grid_puts_line_start(grid, i + adj[0]); + grid_put_schar(grid, i + adj[0], icol + adj[3], chars[ic], attrs[ic]); grid_puts_line_flush(false); } } if (adj[2]) { - grid_puts_line_start(grid, irow+adj[0]); + grid_puts_line_start(grid, irow + adj[0]); if (adj[3]) { - grid_put_schar(grid, irow+adj[0], 0, chars[6], attrs[6]); + grid_put_schar(grid, irow + adj[0], 0, chars[6], attrs[6]); } for (int i = 0; i < icol; i++) { int ic = (i == 0 && !adj[3] && chars[6][0]) ? 6 : 5; - grid_put_schar(grid, irow+adj[0], i+adj[3], chars[ic], attrs[ic]); + grid_put_schar(grid, irow + adj[0], i + adj[3], chars[ic], attrs[ic]); } if (adj[1]) { - grid_put_schar(grid, irow+adj[0], icol+adj[3], chars[4], attrs[4]); + grid_put_schar(grid, irow + adj[0], icol + adj[3], chars[4], attrs[4]); } grid_puts_line_flush(false); } @@ -5795,7 +5795,7 @@ void grid_put_schar(ScreenGrid *grid, int row, int col, char_u *schar, int attr) put_dirty_first = MIN(put_dirty_first, col); // TODO(bfredl): Y U NO DOUBLEWIDTH? - put_dirty_last = MAX(put_dirty_last, col+1); + put_dirty_last = MAX(put_dirty_last, col + 1); } } @@ -5931,7 +5931,7 @@ void grid_puts_len(ScreenGrid *grid, char_u *text, int textlen, int row, int col grid->attrs[off + 1] = attr; } put_dirty_first = MIN(put_dirty_first, col); - put_dirty_last = MAX(put_dirty_last, col+mbyte_cells); + put_dirty_last = MAX(put_dirty_last, col + mbyte_cells); } off += mbyte_cells; @@ -5961,7 +5961,7 @@ void grid_puts_line_flush(bool set_cursor) if (put_dirty_first < put_dirty_last) { if (set_cursor) { ui_grid_cursor_goto(put_dirty_grid->handle, put_dirty_row, - MIN(put_dirty_last, put_dirty_grid->Columns-1)); + MIN(put_dirty_last, put_dirty_grid->Columns - 1)); } if (!put_dirty_grid->throttled) { ui_line(put_dirty_grid, put_dirty_row, put_dirty_first, put_dirty_last, @@ -6062,7 +6062,7 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, int if (dirty_first == INT_MAX) { dirty_first = col; } - dirty_last = col+1; + dirty_last = col + 1; } if (col == start_col) { schar_from_char(sc, c2); @@ -6134,7 +6134,7 @@ void win_grid_alloc(win_T *wp) if (grid->Rows != rows) { wp->w_lines_valid = 0; xfree(wp->w_lines); - wp->w_lines = xcalloc(rows+1, sizeof(wline_T)); + wp->w_lines = xcalloc(rows + 1, sizeof(wline_T)); } int was_resized = false; @@ -6570,7 +6570,7 @@ void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, } if (!grid->throttled) { - ui_call_grid_scroll(grid->handle, row, end, col, col+width, -line_count, 0); + ui_call_grid_scroll(grid->handle, row, end, col, col + width, -line_count, 0); } } @@ -6620,7 +6620,7 @@ void grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col, } if (!grid->throttled) { - ui_call_grid_scroll(grid->handle, row, end, col, col+width, line_count, 0); + ui_call_grid_scroll(grid->handle, row, end, col, col + width, line_count, 0); } } diff --git a/src/nvim/screen.h b/src/nvim/screen.h index 330ff1d4a1..33b713e756 100644 --- a/src/nvim/screen.h +++ b/src/nvim/screen.h @@ -24,7 +24,7 @@ typedef enum { WC_TOP_LEFT = 0, WC_TOP_RIGHT, WC_BOTTOM_LEFT, - WC_BOTTOM_RIGHT + WC_BOTTOM_RIGHT, } WindowCorner; /// By default, all windows are drawn on a single rectangular grid, represented by diff --git a/src/nvim/search.c b/src/nvim/search.c index 48df289831..6df3a6a5ec 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -2543,9 +2543,8 @@ int findsent(Direction dir, long count) if ((c = inc(&tpos)) == -1) { break; } - } - while (vim_strchr((char_u *)")]\"'", c = gchar_pos(&tpos)) - != NULL); + } while (vim_strchr((char_u *)")]\"'", c = gchar_pos(&tpos)) + != NULL); if (c == -1 || (!cpo_J && (c == ' ' || c == '\t')) || c == NUL || (cpo_J && (c == ' ' && inc(&tpos) >= 0 && gchar_pos(&tpos) == ' '))) { @@ -3673,8 +3672,7 @@ again: p = get_cursor_pos_ptr(); for (cp = p; *cp != NUL && *cp != '>' && !ascii_iswhite(*cp); - MB_PTR_ADV(cp)) { - } + MB_PTR_ADV(cp)) {} len = (int)(cp - p); if (len == 0) { curwin->w_cursor = old_pos; @@ -5497,10 +5495,8 @@ void find_pattern_in_path(char_u *ptr, Direction dir, size_t len, bool whole, bo } else { // find the file name after the end of the match for (p = incl_regmatch.endp[0]; - *p && !vim_isfilec(*p); p++) { - } - for (i = 0; vim_isfilec(p[i]); i++) { - } + *p && !vim_isfilec(*p); p++) {} + for (i = 0; vim_isfilec(p[i]); i++) {} } if (i == 0) { @@ -5709,15 +5705,15 @@ search_line: p = find_word_start(p); p = find_word_end(p); if (p > aux) { - if (*aux != ')' && IObuff[i-1] != TAB) { - if (IObuff[i-1] != ' ') { + if (*aux != ')' && IObuff[i - 1] != TAB) { + if (IObuff[i - 1] != ' ') { IObuff[i++] = ' '; } // IObuf =~ "\(\k\|\i\).* ", thus i >= 2 if (p_js - && (IObuff[i-2] == '.' - || IObuff[i-2] == '?' - || IObuff[i-2] == '!')) { + && (IObuff[i - 2] == '.' + || IObuff[i - 2] == '?' + || IObuff[i - 2] == '!')) { IObuff[i++] = ' '; } } @@ -5812,7 +5808,7 @@ search_line: curwin->w_cursor.lnum = lnum; check_cursor(); } else { - if (!GETFILE_SUCCESS(getfile(0, files[depth].name, NULL, true, + if (!GETFILE_SUCCESS(getfile(0, (char *)files[depth].name, NULL, true, files[depth].lnum, false))) { break; // failed to jump to file } diff --git a/src/nvim/sha256.c b/src/nvim/sha256.c index 2c6199bf8b..53c9cb7c81 100644 --- a/src/nvim/sha256.c +++ b/src/nvim/sha256.c @@ -86,7 +86,7 @@ static void sha256_process(context_sha256_T *ctx, const char_u data[SHA256_BUFFE #define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) #define R(t) \ - (W[t] = S1(W[(t) - 2]) + W[(t) - 7] + S0(W[(t) - 15]) + W[(t) - 16]) + (W[t] = S1(W[(t) - 2]) + W[(t) - 7] + S0(W[(t) - 15]) + W[(t) - 16]) #define P(a, b, c, d, e, f, g, h, x, K) { \ temp1 = (h) + S3(e) + F1(e, f, g) + (K) + (x); \ @@ -184,7 +184,7 @@ void sha256_update(context_sha256_T *ctx, const char_u *input, size_t length) return; } - uint32_t left = ctx->total[0] & (SHA256_BUFFER_SIZE-1); // left < buf size + uint32_t left = ctx->total[0] & (SHA256_BUFFER_SIZE - 1); // left < buf size ctx->total[0] += (uint32_t)length; ctx->total[0] &= 0xFFFFFFFF; @@ -335,7 +335,7 @@ bool sha256_self_test(void) sha256_finish(&ctx, sha256sum); for (size_t j = 0; j < SHA256_SUM_SIZE; j++) { - snprintf(output + j * SHA_STEP, SHA_STEP+1, "%02x", sha256sum[j]); + snprintf(output + j * SHA_STEP, SHA_STEP + 1, "%02x", sha256sum[j]); } } diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 76bf81ffbf..a19dbac6f3 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -3302,7 +3302,7 @@ static ShaDaReadResult msgpack_read_uint64(ShaDaReadDef *const sd_reader, const uint64_t buf = 0; char *buf_u8 = (char *)&buf; ShaDaReadResult fl_ret; - if ((fl_ret = fread_len(sd_reader, &(buf_u8[sizeof(buf)-length]), length)) + if ((fl_ret = fread_len(sd_reader, &(buf_u8[sizeof(buf) - length]), length)) != kSDReadStatusSuccess) { return fl_ret; } diff --git a/src/nvim/sign.c b/src/nvim/sign.c index 6685c2f231..db3ce45b51 100644 --- a/src/nvim/sign.c +++ b/src/nvim/sign.c @@ -5,8 +5,6 @@ // sign.c: functions for managing with signs // -#include "nvim/sign.h" - #include "nvim/ascii.h" #include "nvim/buffer.h" #include "nvim/charset.h" @@ -18,6 +16,7 @@ #include "nvim/move.h" #include "nvim/option.h" #include "nvim/screen.h" +#include "nvim/sign.h" #include "nvim/syntax.h" #include "nvim/vim.h" #include "nvim/window.h" @@ -1699,8 +1698,7 @@ void free_signs(void) } } -static enum -{ +static enum { EXP_SUBCMD, // expand :sign sub-commands EXP_DEFINE, // expand :sign define {name} args EXP_PLACE, // expand :sign place {id} args diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 20e1fefbb4..754d9dcb48 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1647,7 +1647,7 @@ void spell_cat_line(char_u *buf, char_u *line, int maxlen) n = (int)(p - line) + 1; if (n < maxlen - 1) { memset(buf, ' ', n); - STRLCPY(buf + n, p, maxlen - n); + STRLCPY(buf + n, p, maxlen - n); } } } @@ -3420,8 +3420,7 @@ static void spell_suggest_file(suginfo_T *su, char_u *fname) *p++ = NUL; if (STRICMP(su->su_badword, line) == 0) { // Match! Isolate the good word, until CR or NL. - for (len = 0; p[len] >= ' '; ++len) { - } + for (len = 0; p[len] >= ' '; len++) {} p[len] = NUL; // If the suggestion doesn't have specific case duplicate the case @@ -3816,8 +3815,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (sp->ts_prefixdepth == PFD_PREFIXTREE) { // Skip over the NUL bytes, we use them later. - for (n = 0; n < len && byts[arridx + n] == 0; ++n) { - } + for (n = 0; n < len && byts[arridx + n] == 0; n++) {} sp->ts_curi += n; // Always past NUL bytes now. @@ -3890,8 +3888,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // none this must be the first try without a prefix. n = stack[sp->ts_prefixdepth].ts_arridx; len = pbyts[n++]; - for (c = 0; c < len && pbyts[n + c] == 0; ++c) { - } + for (c = 0; c < len && pbyts[n + c] == 0; c++) {} if (c > 0) { c = valid_word_prefix(c, n, flags, tword + sp->ts_splitoff, slang, false); diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 0933e6d467..f4e50778cf 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -5887,4 +5887,3 @@ static void set_map_str(slang_T *lp, char_u *map) } } } - diff --git a/src/nvim/state.c b/src/nvim/state.c index 056828574f..6f4bab62d1 100644 --- a/src/nvim/state.c +++ b/src/nvim/state.c @@ -187,22 +187,17 @@ void get_mode(char *buf) if (State & VREPLACE_FLAG) { buf[i++] = 'R'; buf[i++] = 'v'; - if (ins_compl_active()) { - buf[i++] = 'c'; - } else if (ctrl_x_mode_not_defined_yet()) { - buf[i++] = 'x'; - } } else { if (State & REPLACE_FLAG) { buf[i++] = 'R'; } else { buf[i++] = 'i'; } - if (ins_compl_active()) { - buf[i++] = 'c'; - } else if (ctrl_x_mode_not_defined_yet()) { - buf[i++] = 'x'; - } + } + if (ins_compl_active()) { + buf[i++] = 'c'; + } else if (ctrl_x_mode_not_defined_yet()) { + buf[i++] = 'x'; } } else if ((State & CMDLINE) || exmode_active) { buf[i++] = 'c'; diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 76bb5a0186..3be7dfe477 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -1019,8 +1019,7 @@ static void syn_stack_alloc(void) // When shrinking the array, cleanup the existing stack. // Make sure that all valid entries fit in the new array. while (syn_block->b_sst_len - syn_block->b_sst_freecount + 2 > len - && syn_stack_cleanup()) { - } + && syn_stack_cleanup()) {} if (len < syn_block->b_sst_len - syn_block->b_sst_freecount + 2) { len = syn_block->b_sst_len - syn_block->b_sst_freecount + 2; } @@ -2699,8 +2698,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ // Be careful not to jump over the NUL at the end-of-line for (matchcol = regmatch.endpos[0].col; matchcol < line_len && matchcol < pos.col; - matchcol++) { - } + matchcol++) {} } // if the skip pattern includes end-of-line, break here @@ -5334,8 +5332,7 @@ static int get_id_list(char_u **const arg, const int keylen, int16_t **const lis // parse the arguments after "contains" int count = 0; do { - for (end = p; *end && !ascii_iswhite(*end) && *end != ','; end++) { - } + for (end = p; *end && !ascii_iswhite(*end) && *end != ','; end++) {} char_u *const name = xmalloc(end - p + 3); // leave room for "^$" STRLCPY(name + 1, p, end - p + 1); if (STRCMP(name + 1, "ALLBUT") == 0 @@ -5470,8 +5467,7 @@ static int16_t *copy_id_list(const int16_t *const list) } int count; - for (count = 0; list[count]; count++) { - } + for (count = 0; list[count]; count++) {} const size_t len = (count + 1) * sizeof(int16_t); int16_t *const retval = xmalloc(len); memmove(retval, list, len); @@ -5624,8 +5620,7 @@ void ex_syntax(exarg_T *eap) syn_cmdlinep = eap->cmdlinep; // isolate subcommand name - for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); subcmd_end++) { - } + for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); subcmd_end++) {} char_u *const subcmd_name = vim_strnsave(arg, subcmd_end - arg); if (eap->skip) { // skip error messages for all subcommands emsg_skip++; diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 39c9aacad0..40d65c2542 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -813,8 +813,7 @@ static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char_ } else { for (p = tagp.command; *p && *p != '\r' && *p != '\n'; - p++) { - } + p++) {} command_end = p; } @@ -933,8 +932,7 @@ static int add_llist_tags(char_u *tag, int num_matches, char_u **matches) cmd_end = tagp.command_end; if (cmd_end == NULL) { for (p = tagp.command; - *p && *p != '\r' && *p != '\n'; p++) { - } + *p && *p != '\r' && *p != '\n'; p++) {} cmd_end = p; } @@ -1780,8 +1778,7 @@ line_read_in: if (STRNCMP(lbuf, "!_TAG_FILE_ENCODING\t", 20) == 0) { // Prepare to convert every line from the specified // encoding to 'encoding'. - for (p = lbuf + 20; *p > ' ' && *p < 127; p++) { - } + for (p = lbuf + 20; *p > ' ' && *p < 127; p++) {} *p = NUL; convert_setup(&vimconv, lbuf + 20, p_enc); } @@ -2100,8 +2097,8 @@ parse_line: STRCPY(p, tagp.tagname); p[len] = '@'; STRCPY(p + len + 1, help_lang); - snprintf((char *)p + len + 1 + ML_EXTRA, 10, "%06d", - help_heuristic(tagp.tagname, + snprintf((char *)p + len + 1 + ML_EXTRA, STRLEN(p) + len + 1 + ML_EXTRA, "%06d", + help_heuristic((char *)tagp.tagname, match_re ? matchoff : 0, !match_no_ic) + help_pri); @@ -2614,15 +2611,13 @@ static int parse_match(char_u *lbuf, tagptrs_T *tagp) if (tagp->tagkind != NULL) { for (p = tagp->tagkind; *p && *p != '\t' && *p != '\r' && *p != '\n'; - MB_PTR_ADV(p)) { - } + MB_PTR_ADV(p)) {} tagp->tagkind_end = p; } if (tagp->user_data != NULL) { for (p = tagp->user_data; *p && *p != '\t' && *p != '\r' && *p != '\n'; - MB_PTR_ADV(p)) { - } + MB_PTR_ADV(p)) {} tagp->user_data_end = p; } } @@ -2800,7 +2795,7 @@ static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) if (getfile_result == GETFILE_UNUSED) { // Careful: getfile() may trigger autocommands and call jumpto_tag() // recursively. - getfile_result = getfile(0, fname, NULL, true, (linenr_T)0, forceit); + getfile_result = getfile(0, (char *)fname, NULL, true, (linenr_T)0, forceit); } keep_help_flag = false; diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index fd870361c7..b07c3786c3 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -744,8 +744,8 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, int *te int vt_fg_idx = ((!fg_default && fg_indexed) ? cell.fg.indexed.idx + 1 : 0); int vt_bg_idx = ((!bg_default && bg_indexed) ? cell.bg.indexed.idx + 1 : 0); - bool fg_set = vt_fg_idx && vt_fg_idx <= 16 && term->color_set[vt_fg_idx-1]; - bool bg_set = vt_bg_idx && vt_bg_idx <= 16 && term->color_set[vt_bg_idx-1]; + bool fg_set = vt_fg_idx && vt_fg_idx <= 16 && term->color_set[vt_fg_idx - 1]; + bool bg_set = vt_bg_idx && vt_bg_idx <= 16 && term->color_set[vt_bg_idx - 1]; int hl_attrs = (cell.attrs.bold ? HL_BOLD : 0) | (cell.attrs.italic ? HL_ITALIC : 0) @@ -1348,7 +1348,7 @@ static bool send_mouse_event(Terminal *term, int c) } end: - ins_char_typebuf(c, mod_mask); + ins_char_typebuf(vgetc_char, vgetc_mod_mask); return true; } diff --git a/src/nvim/testdir/test_backspace_opt.vim b/src/nvim/testdir/test_backspace_opt.vim index 11459991ea..59e94d2898 100644 --- a/src/nvim/testdir/test_backspace_opt.vim +++ b/src/nvim/testdir/test_backspace_opt.vim @@ -76,7 +76,7 @@ func Test_backspace_ctrl_u() set cpo-=< inoremap <c-u> <left><c-u> - exe "normal Avim3\<C-U>\<Esc>\<CR>" + exe "normal Avim3\<*C-U>\<Esc>\<CR>" iunmap <c-u> exe "normal Avim4\<C-U>\<C-U>\<Esc>\<CR>" @@ -86,7 +86,7 @@ func Test_backspace_ctrl_u() exe "normal A vim6\<Esc>Azwei\<C-G>u\<C-U>\<Esc>\<CR>" inoremap <c-u> <left><c-u> - exe "normal A vim7\<C-U>\<C-U>\<Esc>\<CR>" + exe "normal A vim7\<*C-U>\<*C-U>\<Esc>\<CR>" call assert_equal([ \ "1 this shouldn't be deleted", diff --git a/src/nvim/testdir/test_eval_stuff.vim b/src/nvim/testdir/test_eval_stuff.vim index 12febfeb93..95eccde35c 100644 --- a/src/nvim/testdir/test_eval_stuff.vim +++ b/src/nvim/testdir/test_eval_stuff.vim @@ -185,7 +185,7 @@ func Test_let_register() call Assert_reg('"', 'v', "abc", "['abc']", "abc", "['abc']") let @" = "abc\n" call Assert_reg('"', 'V', "abc\n", "['abc']", "abc\n", "['abc']") - let @" = "abc\r" + let @" = "abc\<C-m>" call Assert_reg('"', 'V', "abc\r\n", "['abc\r']", "abc\r\n", "['abc\r']") let @= = '"abc"' call Assert_reg('=', 'v', "abc", "['abc']", '"abc"', "['\"abc\"']") diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 6872eb3bb7..6ae957da70 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -211,6 +211,7 @@ let s:filename_checks = { \ 'gitrebase': ['git-rebase-todo'], \ 'gitsendemail': ['.gitsendemail.msg.xxxxxx'], \ 'gkrellmrc': ['gkrellmrc', 'gkrellmrc_x'], + \ 'gleam': ['file.gleam'], \ 'glsl': ['file.glsl'], \ 'gnash': ['gnashrc', '.gnashrc', 'gnashpluginrc', '.gnashpluginrc'], \ 'gnuplot': ['file.gpi', '.gnuplot'], diff --git a/src/nvim/testdir/test_langmap.vim b/src/nvim/testdir/test_langmap.vim index 066c3bf2bd..eca8a95564 100644 --- a/src/nvim/testdir/test_langmap.vim +++ b/src/nvim/testdir/test_langmap.vim @@ -20,5 +20,32 @@ func Test_langmap() silent! call feedkeys("gg0}%}\<C-G>}^\<Esc>00", 'tx') call assert_equal('a}^de', getline(1)) + " Error cases + call assert_fails('set langmap=aA,b', 'E357:') + call assert_fails('set langmap=z;y;y;z', 'E358:') + + " Map character > 256 + enew! + set langmap=Äx,ăl,Äx + call setline(1, ['abcde']) + call feedkeys('gg2lÄ', 'tx') + call assert_equal('abde', getline(1)) + + " special characters in langmap + enew! + call setline(1, ['Hello World']) + set langmap=\\;\\,,\\,\\; + call feedkeys('ggfo,', 'tx') + call assert_equal(8, col('.')) + call feedkeys(';', 'tx') + call assert_equal(5, col('.')) + set langmap& + set langmap=\\;\\,;\\,\\; + call feedkeys('ggfo,', 'tx') + call assert_equal(8, col('.')) + call feedkeys(';', 'tx') + call assert_equal(5, col('.')) + + set langmap& quit! endfunc diff --git a/src/nvim/testdir/test_maparg.vim b/src/nvim/testdir/test_maparg.vim index 5b082198cf..cebde89996 100644 --- a/src/nvim/testdir/test_maparg.vim +++ b/src/nvim/testdir/test_maparg.vim @@ -47,9 +47,34 @@ function Test_maparg() call assert_equal(['{', 'w', 'o'], [d.lhs, d.rhs, d.mode]) ounmap { + lmap { w + let d = maparg('{', 'l', 0, 1) + call assert_equal(['{', 'w', 'l'], [d.lhs, d.rhs, d.mode]) + lunmap { + + nmap { w + let d = maparg('{', 'n', 0, 1) + call assert_equal(['{', 'w', 'n'], [d.lhs, d.rhs, d.mode]) + nunmap { + + xmap { w + let d = maparg('{', 'x', 0, 1) + call assert_equal(['{', 'w', 'x'], [d.lhs, d.rhs, d.mode]) + xunmap { + + smap { w + let d = maparg('{', 's', 0, 1) + call assert_equal(['{', 'w', 's'], [d.lhs, d.rhs, d.mode]) + sunmap { + map abc <Nop> call assert_equal("<Nop>", maparg('abc')) unmap abc + + call feedkeys(":abbr esc \<C-V>\<C-V>\<C-V>\<C-V>\<C-V>\<Esc>\<CR>", "xt") + let d = maparg('esc', 'i', 1, 1) + call assert_equal(['esc', "\<C-V>\<C-V>\<Esc>", '!'], [d.lhs, d.rhs, d.mode]) + abclear endfunction func Test_mapcheck() diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index a9500f8f77..1da3b71a32 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -62,7 +62,7 @@ func Test_map_ctrl_c_insert() inoremap <c-c> <ctrl-c> cnoremap <c-c> dummy cunmap <c-c> - call feedkeys("GoTEST2: CTRL-C |\<C-C>A|\<Esc>", "xt") + call feedkeys("GoTEST2: CTRL-C |\<*C-C>A|\<Esc>", "xt") call assert_equal('TEST2: CTRL-C |<ctrl-c>A|', getline('$')) unmap! <c-c> set nomodified @@ -71,7 +71,7 @@ endfunc func Test_map_ctrl_c_visual() " mapping of ctrl-c in Visual mode vnoremap <c-c> :<C-u>$put ='vmap works' - call feedkeys("GV\<C-C>\<CR>", "xt") + call feedkeys("GV\<*C-C>\<CR>", "xt") call assert_equal('vmap works', getline('$')) vunmap <c-c> set nomodified @@ -221,7 +221,7 @@ endfunc func Test_map_meta_quotes() imap <M-"> foo - call feedkeys("Go-\<M-\">-\<Esc>", "xt") + call feedkeys("Go-\<*M-\">-\<Esc>", "xt") call assert_equal("-foo-", getline('$')) set nomodified iunmap <M-"> @@ -429,6 +429,44 @@ func Test_error_in_map_expr() exe buf .. 'bwipe!' endfunc +func Test_list_mappings() + " Remove default mappings + imapclear + + " reset 'isident' to check it isn't used + set isident= + inoremap <C-m> CtrlM + inoremap <A-S> AltS + inoremap <S-/> ShiftSlash + set isident& + call assert_equal([ + \ 'i <S-/> * ShiftSlash', + \ 'i <M-S> * AltS', + \ 'i <C-M> * CtrlM', + \], execute('imap')->trim()->split("\n")) + iunmap <C-M> + iunmap <A-S> + call assert_equal(['i <S-/> * ShiftSlash'], execute('imap')->trim()->split("\n")) + iunmap <S-/> + call assert_equal(['No mapping found'], execute('imap')->trim()->split("\n")) + + " List global, buffer local and script local mappings + nmap ,f /^\k\+ (<CR> + nmap <buffer> ,f /^\k\+ (<CR> + nmap <script> ,fs /^\k\+ (<CR> + call assert_equal(['n ,f @/^\k\+ (<CR>', + \ 'n ,fs & /^\k\+ (<CR>', + \ 'n ,f /^\k\+ (<CR>'], + \ execute('nmap ,f')->trim()->split("\n")) + + " List <Nop> mapping + nmap ,n <Nop> + call assert_equal(['n ,n <Nop>'], + \ execute('nmap ,n')->trim()->split("\n")) + + nmapclear +endfunc + func Test_expr_map_gets_cursor() new call setline(1, ['one', 'some w!rd']) @@ -554,6 +592,15 @@ func Test_map_error() call assert_fails('mapclear abc', 'E474:') call assert_fails('abclear abc', 'E474:') + call assert_fails('abbr $xyz abc', 'E474:') + + " space character in an abbreviation + call assert_fails('abbr ab<space> ABC', 'E474:') + + " invalid <expr> map + map <expr> ,f abc + call assert_fails('normal ,f', 'E121:') + unmap <expr> ,f endfunc " Test for <special> key mapping @@ -581,11 +628,66 @@ endfunc " Test for hasmapto() func Test_hasmapto() call assert_equal(0, hasmapto('/^\k\+ (')) + map ,f /^\k\+ (<CR> + call assert_equal(1, hasmapto('/^\k\+ (')) + unmap ,f + + " Insert mode mapping + call assert_equal(0, hasmapto('/^\k\+ (', 'i')) + imap ,f /^\k\+ (<CR> + call assert_equal(1, hasmapto('/^\k\+ (', 'i')) + iunmap ,f + + " Normal mode mapping call assert_equal(0, hasmapto('/^\k\+ (', 'n')) nmap ,f /^\k\+ (<CR> call assert_equal(1, hasmapto('/^\k\+ (')) call assert_equal(1, hasmapto('/^\k\+ (', 'n')) + nunmap ,f + + " Visual and Select mode mapping call assert_equal(0, hasmapto('/^\k\+ (', 'v')) + call assert_equal(0, hasmapto('/^\k\+ (', 'x')) + call assert_equal(0, hasmapto('/^\k\+ (', 's')) + vmap ,f /^\k\+ (<CR> + call assert_equal(1, hasmapto('/^\k\+ (', 'v')) + call assert_equal(1, hasmapto('/^\k\+ (', 'x')) + call assert_equal(1, hasmapto('/^\k\+ (', 's')) + vunmap ,f + + " Visual mode mapping + call assert_equal(0, hasmapto('/^\k\+ (', 'x')) + xmap ,f /^\k\+ (<CR> + call assert_equal(1, hasmapto('/^\k\+ (', 'v')) + call assert_equal(1, hasmapto('/^\k\+ (', 'x')) + call assert_equal(0, hasmapto('/^\k\+ (', 's')) + xunmap ,f + + " Select mode mapping + call assert_equal(0, hasmapto('/^\k\+ (', 's')) + smap ,f /^\k\+ (<CR> + call assert_equal(1, hasmapto('/^\k\+ (', 'v')) + call assert_equal(0, hasmapto('/^\k\+ (', 'x')) + call assert_equal(1, hasmapto('/^\k\+ (', 's')) + sunmap ,f + + " Operator-pending mode mapping + call assert_equal(0, hasmapto('/^\k\+ (', 'o')) + omap ,f /^\k\+ (<CR> + call assert_equal(1, hasmapto('/^\k\+ (', 'o')) + ounmap ,f + + " Language mapping + call assert_equal(0, hasmapto('/^\k\+ (', 'l')) + lmap ,f /^\k\+ (<CR> + call assert_equal(1, hasmapto('/^\k\+ (', 'l')) + lunmap ,f + + " Cmdline mode mapping + call assert_equal(0, hasmapto('/^\k\+ (', 'c')) + cmap ,f /^\k\+ (<CR> + call assert_equal(1, hasmapto('/^\k\+ (', 'c')) + cunmap ,f call assert_equal(0, hasmapto('/^\k\+ (', 'n', 1)) endfunc @@ -597,8 +699,176 @@ func Test_mapcomplete() \ getcompletion('', 'mapping')) call assert_equal([], getcompletion(',d', 'mapping')) + call feedkeys(":unmap <buf\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"unmap <buffer>', @:) + + call feedkeys(":unabbr <buf\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"unabbr <buffer>', @:) + call feedkeys(":abbr! \<C-A>\<C-B>\"\<CR>", 'tx') - call assert_match("abbr! \x01", @:) + call assert_equal("\"abbr! \x01", @:) + + " Multiple matches for a map + nmap ,f /H<CR> + omap ,f /H<CR> + call feedkeys(":map ,\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"map ,f', @:) + mapclear +endfunc + +" Test for <expr> in abbreviation +func Test_expr_abbr() + new + iabbr <expr> teh "the" + call feedkeys("iteh ", "tx") + call assert_equal('the ', getline(1)) + iabclear + call setline(1, '') + + " invalid <expr> abbreviation + abbr <expr> hte GetAbbr() + call assert_fails('normal ihte ', 'E117:') + call assert_equal(' ', getline(1)) + unabbr <expr> hte + + close! +endfunc + +" Test for storing mappings in different modes in a vimrc file +func Test_mkvimrc_mapmodes() + map a1 /a1 + nmap a2 /a2 + vmap a3 /a3 + smap a4 /a4 + xmap a5 /a5 + omap a6 /a6 + map! a7 /a7 + imap a8 /a8 + lmap a9 /a9 + cmap a10 /a10 + tmap a11 /a11 + " Normal + Visual map + map a12 /a12 + sunmap a12 + ounmap a12 + " Normal + Selectmode map + map a13 /a13 + xunmap a13 + ounmap a13 + " Normal + OpPending map + map a14 /a14 + vunmap a14 + " Visual + Selectmode map + map a15 /a15 + nunmap a15 + ounmap a15 + " Visual + OpPending map + map a16 /a16 + nunmap a16 + sunmap a16 + " Selectmode + OpPending map + map a17 /a17 + nunmap a17 + xunmap a17 + " Normal + Visual + Selectmode map + map a18 /a18 + ounmap a18 + " Normal + Visual + OpPending map + map a19 /a19 + sunmap a19 + " Normal + Selectmode + OpPending map + map a20 /a20 + xunmap a20 + " Visual + Selectmode + OpPending map + map a21 /a21 + nunmap a21 + " Mapping to Nop + map a22 <Nop> + " Script local mapping + map <script> a23 /a23 + + " Newline in {lhs} and {rhs} of a map + exe "map a24\<C-V>\<C-J> ia24\<C-V>\<C-J><Esc>" + + " Abbreviation + abbr a25 A25 + cabbr a26 A26 + iabbr a27 A27 + + mkvimrc! Xvimrc + let l = readfile('Xvimrc') + call assert_equal(['map a1 /a1'], filter(copy(l), 'v:val =~ " a1 "')) + call assert_equal(['nmap a2 /a2'], filter(copy(l), 'v:val =~ " a2 "')) + call assert_equal(['vmap a3 /a3'], filter(copy(l), 'v:val =~ " a3 "')) + call assert_equal(['smap a4 /a4'], filter(copy(l), 'v:val =~ " a4 "')) + call assert_equal(['xmap a5 /a5'], filter(copy(l), 'v:val =~ " a5 "')) + call assert_equal(['omap a6 /a6'], filter(copy(l), 'v:val =~ " a6 "')) + call assert_equal(['map! a7 /a7'], filter(copy(l), 'v:val =~ " a7 "')) + call assert_equal(['imap a8 /a8'], filter(copy(l), 'v:val =~ " a8 "')) + call assert_equal(['lmap a9 /a9'], filter(copy(l), 'v:val =~ " a9 "')) + call assert_equal(['cmap a10 /a10'], filter(copy(l), 'v:val =~ " a10 "')) + call assert_equal(['tmap a11 /a11'], filter(copy(l), 'v:val =~ " a11 "')) + call assert_equal(['nmap a12 /a12', 'xmap a12 /a12'], + \ filter(copy(l), 'v:val =~ " a12 "')) + call assert_equal(['nmap a13 /a13', 'smap a13 /a13'], + \ filter(copy(l), 'v:val =~ " a13 "')) + call assert_equal(['nmap a14 /a14', 'omap a14 /a14'], + \ filter(copy(l), 'v:val =~ " a14 "')) + call assert_equal(['vmap a15 /a15'], filter(copy(l), 'v:val =~ " a15 "')) + call assert_equal(['xmap a16 /a16', 'omap a16 /a16'], + \ filter(copy(l), 'v:val =~ " a16 "')) + call assert_equal(['smap a17 /a17', 'omap a17 /a17'], + \ filter(copy(l), 'v:val =~ " a17 "')) + call assert_equal(['nmap a18 /a18', 'vmap a18 /a18'], + \ filter(copy(l), 'v:val =~ " a18 "')) + call assert_equal(['nmap a19 /a19', 'xmap a19 /a19', 'omap a19 /a19'], + \ filter(copy(l), 'v:val =~ " a19 "')) + call assert_equal(['nmap a20 /a20', 'smap a20 /a20', 'omap a20 /a20'], + \ filter(copy(l), 'v:val =~ " a20 "')) + call assert_equal(['vmap a21 /a21', 'omap a21 /a21'], + \ filter(copy(l), 'v:val =~ " a21 "')) + call assert_equal(['map a22 <Nop>'], filter(copy(l), 'v:val =~ " a22 "')) + call assert_equal([], filter(copy(l), 'v:val =~ " a23 "')) + call assert_equal(["map a24<NL> ia24<NL>\x16\e"], + \ filter(copy(l), 'v:val =~ " a24"')) + + call assert_equal(['abbr a25 A25'], filter(copy(l), 'v:val =~ " a25 "')) + call assert_equal(['cabbr a26 A26'], filter(copy(l), 'v:val =~ " a26 "')) + call assert_equal(['iabbr a27 A27'], filter(copy(l), 'v:val =~ " a27 "')) + call delete('Xvimrc') + + mapclear + nmapclear + vmapclear + xmapclear + smapclear + omapclear + imapclear + lmapclear + cmapclear + tmapclear +endfunc + +" Test for recursive mapping ('maxmapdepth') +func Test_map_recursive() + map x y + map y x + call assert_fails('normal x', 'E223:') + unmap x + unmap y +endfunc + +" Test for removing an abbreviation using {rhs} and with space after {lhs} +func Test_abbr_remove() + abbr foo bar + let d = maparg('foo', 'i', 1, 1) + call assert_equal(['foo', 'bar', '!'], [d.lhs, d.rhs, d.mode]) + unabbr bar + call assert_equal({}, maparg('foo', 'i', 1, 1)) + + abbr foo bar + unabbr foo<space><tab> + call assert_equal({}, maparg('foo', 'i', 1, 1)) endfunc func Test_map_cmdkey_redo() @@ -739,4 +1009,20 @@ func Test_mouse_drag_insert_map() set mouse& endfunc +func Test_unmap_simplifiable() + map <C-I> foo + map <Tab> bar + call assert_equal('foo', maparg('<C-I>')) + call assert_equal('bar', maparg('<Tab>')) + unmap <C-I> + call assert_equal('', maparg('<C-I>')) + call assert_equal('bar', maparg('<Tab>')) + unmap <Tab> + + map <C-I> foo + unmap <Tab> + " This should not error + unmap <C-I> +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 82c4cc128b..8be0c79499 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -112,6 +112,14 @@ func Test_echospace() set ruler& showcmd& endfunc +func Test_mapping_at_hit_return_prompt() + nnoremap <C-B> :echo "hit ctrl-b"<CR> + call feedkeys(":ls\<CR>", "xt") + call feedkeys("\<*C-B>", "xt") + call assert_match('hit ctrl-b', Screenline(&lines - 1)) + nunmap <C-B> +endfunc + func Test_quit_long_message() CheckScreendump diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index eb367cfe5c..9a31f61582 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -325,6 +325,21 @@ func Test_compl_vim_cmds_after_register_expr() bwipe! endfunc +func Test_compl_ignore_mappings() + call setline(1, ['foo', 'bar', 'baz', 'foobar']) + inoremap <C-P> (C-P) + inoremap <C-N> (C-N) + normal! G + call feedkeys("o\<C-X>\<C-N>\<C-N>\<C-N>\<C-P>\<C-N>\<C-Y>", 'tx') + call assert_equal('baz', getline('.')) + " Also test with unsimplified keys + call feedkeys("o\<C-X>\<*C-N>\<*C-N>\<*C-N>\<*C-P>\<*C-N>\<C-Y>", 'tx') + call assert_equal('baz', getline('.')) + iunmap <C-P> + iunmap <C-N> + bwipe! +endfunc + func DummyCompleteOne(findstart, base) if a:findstart return 0 diff --git a/src/nvim/testdir/test_regex_char_classes.vim b/src/nvim/testdir/test_regex_char_classes.vim index b0d76a15e2..db16f057c8 100644 --- a/src/nvim/testdir/test_regex_char_classes.vim +++ b/src/nvim/testdir/test_regex_char_classes.vim @@ -66,22 +66,22 @@ func Test_regex_char_classes() let save_enc = &encoding set encoding=utf-8 - let input = "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé" + let input = "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé" " Format is [cmd_to_run, expected_output] let tests = [ \ [':s/\%#=0\d//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1\d//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2\d//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0[0-9]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1[0-9]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2[0-9]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0\D//g', \ "0123456789"], \ [':s/\%#=1\D//g', @@ -95,17 +95,17 @@ func Test_regex_char_classes() \ [':s/\%#=2[^0-9]//g', \ "0123456789"], \ [':s/\%#=0\o//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1\o//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2\o//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0[0-7]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1[0-7]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2[0-7]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0\O//g', \ "01234567"], \ [':s/\%#=1\O//g', @@ -119,17 +119,17 @@ func Test_regex_char_classes() \ [':s/\%#=2[^0-7]//g', \ "01234567"], \ [':s/\%#=0\x//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1\x//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2\x//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0[0-9A-Fa-f]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1[0-9A-Fa-f]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2[0-9A-Fa-f]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0\X//g', \ "0123456789ABCDEFabcdef"], \ [':s/\%#=1\X//g', @@ -143,17 +143,17 @@ func Test_regex_char_classes() \ [':s/\%#=2[^0-9A-Fa-f]//g', \ "0123456789ABCDEFabcdef"], \ [':s/\%#=0\w//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1\w//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2\w//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0[0-9A-Za-z_]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1[0-9A-Za-z_]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2[0-9A-Za-z_]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0\W//g', \ "0123456789ABCDEFGHIXYZ_abcdefghiwxyz"], \ [':s/\%#=1\W//g', @@ -167,17 +167,17 @@ func Test_regex_char_classes() \ [':s/\%#=2[^0-9A-Za-z_]//g', \ "0123456789ABCDEFGHIXYZ_abcdefghiwxyz"], \ [':s/\%#=0\h//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1\h//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2\h//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0[A-Za-z_]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1[A-Za-z_]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2[A-Za-z_]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0\H//g', \ "ABCDEFGHIXYZ_abcdefghiwxyz"], \ [':s/\%#=1\H//g', @@ -191,17 +191,17 @@ func Test_regex_char_classes() \ [':s/\%#=2[^A-Za-z_]//g', \ "ABCDEFGHIXYZ_abcdefghiwxyz"], \ [':s/\%#=0\a//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1\a//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2\a//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0[A-Za-z]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1[A-Za-z]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2[A-Za-z]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0\A//g', \ "ABCDEFGHIXYZabcdefghiwxyz"], \ [':s/\%#=1\A//g', @@ -215,17 +215,17 @@ func Test_regex_char_classes() \ [':s/\%#=2[^A-Za-z]//g', \ "ABCDEFGHIXYZabcdefghiwxyz"], \ [':s/\%#=0\l//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1\l//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2\l//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0[a-z]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1[a-z]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2[a-z]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0\L//g', \ "abcdefghiwxyz"], \ [':s/\%#=1\L//g', @@ -239,17 +239,17 @@ func Test_regex_char_classes() \ [':s/\%#=2[^a-z]//g', \ "abcdefghiwxyz"], \ [':s/\%#=0\u//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1\u//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2\u//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0[A-Z]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1[A-Z]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2[A-Z]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0\U//g', \ "ABCDEFGHIXYZ"], \ [':s/\%#=1\U//g', @@ -269,11 +269,11 @@ func Test_regex_char_classes() \ [':s/\%#=2\%' . line('.') . 'l^\t...//g', \ "!\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0[0-z]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=1[0-z]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=2[0-z]//g', - \ "\t\<C-L>\r !\"#$%&'()#+'-./{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./{|}~\<C-?>\u0080\u0082\u0090\u009b¦±¼ÇÓé"], \ [':s/\%#=0[^0-z]//g', \ "0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz"], \ [':s/\%#=1[^0-z]//g', @@ -293,3 +293,5 @@ func Test_regex_char_classes() enew! close endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim index 86fd0147a5..7a15e9a6f1 100644 --- a/src/nvim/testdir/test_substitute.vim +++ b/src/nvim/testdir/test_substitute.vim @@ -177,9 +177,9 @@ func Test_sub_cmd_1() \ ['I', 's/I/\lII/', ['iI']], \ ['J', 's/J/\LJ\EJ/', ['jJ']], \ ['K', 's/K/\Uk\ek/', ['Kk']], - \ ['lLl', "s/L/\<C-V>\r/", ["l\<C-V>", 'l']], + \ ['lLl', "s/L/\<C-V>\<C-M>/", ["l\<C-V>", 'l']], \ ['mMm', 's/M/\r/', ['m', 'm']], - \ ['nNn', "s/N/\\\<C-V>\r/", ["n\<C-V>", 'n']], + \ ['nNn', "s/N/\\\<C-V>\<C-M>/", ["n\<C-V>", 'n']], \ ['oOo', 's/O/\n/', ["o\no"]], \ ['pPp', 's/P/\b/', ["p\<C-H>p"]], \ ['qQq', 's/Q/\t/', ["q\tq"]], @@ -208,9 +208,9 @@ func Test_sub_cmd_2() \ ['I', 's/I/\lII/', ['iI']], \ ['J', 's/J/\LJ\EJ/', ['jJ']], \ ['K', 's/K/\Uk\ek/', ['Kk']], - \ ['lLl', "s/L/\<C-V>\r/", ["l\<C-V>", 'l']], + \ ['lLl', "s/L/\<C-V>\<C-M>/", ["l\<C-V>", 'l']], \ ['mMm', 's/M/\r/', ['m', 'm']], - \ ['nNn', "s/N/\\\<C-V>\r/", ["n\<C-V>", 'n']], + \ ['nNn', "s/N/\\\<C-V>\<C-M>/", ["n\<C-V>", 'n']], \ ['oOo', 's/O/\n/', ["o\no"]], \ ['pPp', 's/P/\b/', ["p\<C-H>p"]], \ ['qQq', 's/Q/\t/', ["q\tq"]], @@ -230,9 +230,9 @@ func Test_sub_cmd_3() " List entry format: [input, cmd, output] let tests = [['aAa', "s/A/\\='\\'/", ['a\a']], \ ['bBb', "s/B/\\='\\\\'/", ['b\\b']], - \ ['cCc', "s/C/\\='\<C-V>\r'/", ["c\<C-V>", 'c']], - \ ['dDd', "s/D/\\='\\\<C-V>\r'/", ["d\\\<C-V>", 'd']], - \ ['eEe', "s/E/\\='\\\\\<C-V>\r'/", ["e\\\\\<C-V>", 'e']], + \ ['cCc', "s/C/\\='\<C-V>\<C-M>'/", ["c\<C-V>", 'c']], + \ ['dDd', "s/D/\\='\\\<C-V>\<C-M>'/", ["d\\\<C-V>", 'd']], + \ ['eEe', "s/E/\\='\\\\\<C-V>\<C-M>'/", ["e\\\\\<C-V>", 'e']], \ ['fFf', "s/F/\\='\r'/", ['f', 'f']], \ ['gGg', "s/G/\\='\<C-V>\<C-J>'/", ["g\<C-V>", 'g']], \ ['hHh', "s/H/\\='\\\<C-V>\<C-J>'/", ["h\\\<C-V>", 'h']], @@ -254,11 +254,11 @@ func Test_sub_cmd_4() \ ['a\a']], \ ['bBb', "s/B/\\=substitute(submatch(0), '.', '\\', '')/", \ ['b\b']], - \ ['cCc', "s/C/\\=substitute(submatch(0), '.', '\<C-V>\r', '')/", + \ ['cCc', "s/C/\\=substitute(submatch(0), '.', '\<C-V>\<C-M>', '')/", \ ["c\<C-V>", 'c']], - \ ['dDd', "s/D/\\=substitute(submatch(0), '.', '\\\<C-V>\r', '')/", + \ ['dDd', "s/D/\\=substitute(submatch(0), '.', '\\\<C-V>\<C-M>', '')/", \ ["d\<C-V>", 'd']], - \ ['eEe', "s/E/\\=substitute(submatch(0), '.', '\\\\\<C-V>\r', '')/", + \ ['eEe', "s/E/\\=substitute(submatch(0), '.', '\\\\\<C-V>\<C-M>', '')/", \ ["e\\\<C-V>", 'e']], \ ['fFf', "s/F/\\=substitute(submatch(0), '.', '\\r', '')/", \ ['f', 'f']], @@ -316,7 +316,7 @@ func Test_sub_cmd_7() set cpo& " List entry format: [input, cmd, output] - let tests = [ ["A\<C-V>\rA", 's/A./\=submatch(0)/', ['A', 'A']], + let tests = [ ["A\<C-V>\<C-M>A", 's/A./\=submatch(0)/', ['A', 'A']], \ ["B\<C-V>\<C-J>B", 's/B./\=submatch(0)/', ['B', 'B']], \ ["C\<C-V>\<C-J>C", 's/C./\=strtrans(string(submatch(0, 1)))/', [strtrans("['C\<C-J>']C")]], \ ["D\<C-V>\<C-J>\nD", 's/D.\nD/\=strtrans(string(submatch(0, 1)))/', [strtrans("['D\<C-J>', 'D']")]], @@ -467,11 +467,11 @@ func Test_sub_replace_1() call assert_equal('iI', substitute('I', 'I', '\lII', '')) call assert_equal('jJ', substitute('J', 'J', '\LJ\EJ', '')) call assert_equal('Kk', substitute('K', 'K', '\Uk\ek', '')) - call assert_equal("l\<C-V>\rl", - \ substitute('lLl', 'L', "\<C-V>\r", '')) - call assert_equal("m\rm", substitute('mMm', 'M', '\r', '')) - call assert_equal("n\<C-V>\rn", - \ substitute('nNn', 'N', "\\\<C-V>\r", '')) + call assert_equal("l\<C-V>\<C-M>l", + \ substitute('lLl', 'L', "\<C-V>\<C-M>", '')) + call assert_equal("m\<C-M>m", substitute('mMm', 'M', '\r', '')) + call assert_equal("n\<C-V>\<C-M>n", + \ substitute('nNn', 'N', "\\\<C-V>\<C-M>", '')) call assert_equal("o\no", substitute('oOo', 'O', '\n', '')) call assert_equal("p\<C-H>p", substitute('pPp', 'P', '\b', '')) call assert_equal("q\tq", substitute('qQq', 'Q', '\t', '')) @@ -480,7 +480,7 @@ func Test_sub_replace_1() call assert_equal("u\nu", substitute('uUu', 'U', "\n", '')) call assert_equal("v\<C-H>v", substitute('vVv', 'V', "\b", '')) call assert_equal("w\\w", substitute('wWw', 'W', "\\", '')) - call assert_equal("x\rx", substitute('xXx', 'X', "\r", '')) + call assert_equal("x\<C-M>x", substitute('xXx', 'X', "\r", '')) call assert_equal("YyyY", substitute('Y', 'Y', '\L\uyYy\l\EY', '')) call assert_equal("zZZz", substitute('Z', 'Z', '\U\lZzZ\u\Ez', '')) endfunc @@ -500,17 +500,17 @@ func Test_sub_replace_2() call assert_equal('iI', substitute('I', 'I', '\lII', '')) call assert_equal('jJ', substitute('J', 'J', '\LJ\EJ', '')) call assert_equal('Kk', substitute('K', 'K', '\Uk\ek', '')) - call assert_equal("l\<C-V>\rl", - \ substitute('lLl', 'L', "\<C-V>\r", '')) - call assert_equal("m\rm", substitute('mMm', 'M', '\r', '')) - call assert_equal("n\<C-V>\rn", - \ substitute('nNn', 'N', "\\\<C-V>\r", '')) + call assert_equal("l\<C-V>\<C-M>l", + \ substitute('lLl', 'L', "\<C-V>\<C-M>", '')) + call assert_equal("m\<C-M>m", substitute('mMm', 'M', '\r', '')) + call assert_equal("n\<C-V>\<C-M>n", + \ substitute('nNn', 'N', "\\\<C-V>\<C-M>", '')) call assert_equal("o\no", substitute('oOo', 'O', '\n', '')) call assert_equal("p\<C-H>p", substitute('pPp', 'P', '\b', '')) call assert_equal("q\tq", substitute('qQq', 'Q', '\t', '')) call assert_equal('r\r', substitute('rRr', 'R', '\\', '')) call assert_equal('scs', substitute('sSs', 'S', '\c', '')) - call assert_equal("t\rt", substitute('tTt', 'T', "\r", '')) + call assert_equal("t\<C-M>t", substitute('tTt', 'T', "\r", '')) call assert_equal("u\nu", substitute('uUu', 'U', "\n", '')) call assert_equal("v\<C-H>v", substitute('vVv', 'V', "\b", '')) call assert_equal('w\w', substitute('wWw', 'W', "\\", '')) @@ -528,7 +528,7 @@ func Test_sub_replace_3() call assert_equal("e\\\\\re", substitute('eEe', 'E', "\\=\"\\\\\\\\\r\"", '')) call assert_equal('f\rf', substitute('fFf', 'F', '\="\\r"', '')) call assert_equal('j\nj', substitute('jJj', 'J', '\="\\n"', '')) - call assert_equal("k\rk", substitute('kKk', 'K', '\="\r"', '')) + call assert_equal("k\<C-M>k", substitute('kKk', 'K', '\="\r"', '')) call assert_equal("l\nl", substitute('lLl', 'L', '\="\n"', '')) endfunc @@ -540,10 +540,10 @@ func Test_sub_replace_4() \ '\=substitute(submatch(0), ".", "\\", "")', '')) call assert_equal('b\b', substitute('bBb', 'B', \ '\=substitute(submatch(0), ".", "\\\\", "")', '')) - call assert_equal("c\<C-V>\rc", substitute('cCc', 'C', '\=substitute(submatch(0), ".", "\<C-V>\r", "")', '')) - call assert_equal("d\<C-V>\rd", substitute('dDd', 'D', '\=substitute(submatch(0), ".", "\\\<C-V>\r", "")', '')) - call assert_equal("e\\\<C-V>\re", substitute('eEe', 'E', '\=substitute(submatch(0), ".", "\\\\\<C-V>\r", "")', '')) - call assert_equal("f\rf", substitute('fFf', 'F', '\=substitute(submatch(0), ".", "\\r", "")', '')) + call assert_equal("c\<C-V>\<C-M>c", substitute('cCc', 'C', '\=substitute(submatch(0), ".", "\<C-V>\<C-M>", "")', '')) + call assert_equal("d\<C-V>\<C-M>d", substitute('dDd', 'D', '\=substitute(submatch(0), ".", "\\\<C-V>\<C-M>", "")', '')) + call assert_equal("e\\\<C-V>\<C-M>e", substitute('eEe', 'E', '\=substitute(submatch(0), ".", "\\\\\<C-V>\<C-M>", "")', '')) + call assert_equal("f\<C-M>f", substitute('fFf', 'F', '\=substitute(submatch(0), ".", "\\r", "")', '')) call assert_equal("j\nj", substitute('jJj', 'J', '\=substitute(submatch(0), ".", "\\n", "")', '')) call assert_equal("k\rk", substitute('kKk', 'K', '\=substitute(submatch(0), ".", "\r", "")', '')) call assert_equal("l\nl", substitute('lLl', 'L', '\=substitute(submatch(0), ".", "\n", "")', '')) diff --git a/src/nvim/testdir/test_termcodes.vim b/src/nvim/testdir/test_termcodes.vim new file mode 100644 index 0000000000..f3b10a922e --- /dev/null +++ b/src/nvim/testdir/test_termcodes.vim @@ -0,0 +1,26 @@ + +func Test_simplify_ctrl_at() + " feeding unsimplified CTRL-@ should still trigger i_CTRL-@ + call feedkeys("ifoo\<Esc>A\<*C-@>x", 'xt') + call assert_equal('foofo', getline(1)) + bw! +endfunc + +func Test_simplify_noremap() + call feedkeys("i\<*C-M>", 'nx') + call assert_equal('', getline(1)) + call assert_equal([0, 2, 1, 0, 1], getcurpos()) + bw! +endfunc + +func Test_simplify_timedout() + inoremap <C-M>a b + call feedkeys("i\<*C-M>", 'xt') + call assert_equal('', getline(1)) + call assert_equal([0, 2, 1, 0, 1], getcurpos()) + iunmap <C-M>a + bw! +endfunc + + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 5771ec4445..f0b84c0eab 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -3,9 +3,9 @@ // testing.c: Support for tests +#include "nvim/eval.h" #include "nvim/eval/encode.h" #include "nvim/ex_docmd.h" -#include "nvim/eval.h" #include "nvim/os/os.h" #include "nvim/testing.h" @@ -559,4 +559,3 @@ void f_test_write_list_log(typval_T *const argvars, typval_T *const rettv, FunPt } list_write_log(fname); } - diff --git a/src/nvim/testing.h b/src/nvim/testing.h index 34ee1d10df..1522ebc7b7 100644 --- a/src/nvim/testing.h +++ b/src/nvim/testing.h @@ -1,8 +1,8 @@ #ifndef NVIM_TESTING_H #define NVIM_TESTING_H -#include "nvim/eval/typval.h" #include "nvim/eval/funcs.h" +#include "nvim/eval/typval.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "testing.h.generated.h" diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 399ad325d1..fbbd6f1bc2 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -13,8 +13,8 @@ #include "nvim/option.h" #include "nvim/os/input.h" #include "nvim/os/os.h" -#include "nvim/tui/tui.h" #include "nvim/tui/input.h" +#include "nvim/tui/tui.h" #include "nvim/vim.h" #ifdef WIN32 # include "nvim/os/os_win_console.h" diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 61c6dc5ca3..720abb1cec 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -391,6 +391,8 @@ static void terminfo_stop(UI *ui) // Reset cursor to normal before exiting alternate screen. unibi_out(ui, unibi_cursor_normal); unibi_out(ui, unibi_keypad_local); + // Disable extended keys before exiting alternate screen. + unibi_out_ext(ui, data->unibi_ext.disable_extended_keys); unibi_out(ui, unibi_exit_ca_mode); // Restore title/icon from the "stack". #4063 unibi_out_ext(ui, data->unibi_ext.restore_title); @@ -401,8 +403,6 @@ static void terminfo_stop(UI *ui) unibi_out_ext(ui, data->unibi_ext.disable_bracketed_paste); // Disable focus reporting unibi_out_ext(ui, data->unibi_ext.disable_focus_reporting); - // Disable extended keys - unibi_out_ext(ui, data->unibi_ext.disable_extended_keys); flush_buf(ui); uv_tty_reset_mode(); uv_close((uv_handle_t *)&data->output_handle, NULL); @@ -897,7 +897,7 @@ static void clear_region(UI *ui, int top, int bot, int left, int right, int attr unibi_out(ui, unibi_clr_eos); } } else { - int width = right-left; + int width = right - left; // iterate through each line and clear for (int row = top; row < bot; row++) { @@ -1186,12 +1186,12 @@ static void tui_grid_scroll(UI *ui, Integer g, Integer startrow, // -V751 { TUIData *data = ui->data; UGrid *grid = &data->grid; - int top = (int)startrow, bot = (int)endrow-1; - int left = (int)startcol, right = (int)endcol-1; + int top = (int)startrow, bot = (int)endrow - 1; + int left = (int)startcol, right = (int)endcol - 1; - bool fullwidth = left == 0 && right == ui->width-1; + bool fullwidth = left == 0 && right == ui->width - 1; data->scroll_region_is_full_screen = fullwidth - && top == 0 && bot == ui->height-1; + && top == 0 && bot == ui->height - 1; ugrid_scroll(grid, top, bot, left, right, (int)rows); @@ -1294,10 +1294,10 @@ static void tui_flush(UI *ui) assert(r.bot <= grid->height && r.right <= grid->width); for (int row = r.top; row < r.bot; row++) { - int clear_attr = grid->cells[row][r.right-1].attr; + int clear_attr = grid->cells[row][r.right - 1].attr; int clear_col; for (clear_col = r.right; clear_col > 0; clear_col--) { - UCell *cell = &grid->cells[row][clear_col-1]; + UCell *cell = &grid->cells[row][clear_col - 1]; if (!(cell->data[0] == ' ' && cell->data[1] == NUL && cell->attr == clear_attr)) { break; @@ -1309,7 +1309,7 @@ static void tui_flush(UI *ui) print_cell(ui, cell); }); if (clear_col < r.right) { - clear_region(ui, row, row+1, clear_col, r.right, clear_attr); + clear_region(ui, row, row + 1, clear_col, r.right, clear_attr); } } } @@ -1389,8 +1389,7 @@ static void tui_set_title(UI *ui, String title) } static void tui_set_icon(UI *ui, String icon) -{ -} +{} static void tui_screenshot(UI *ui, String path) { @@ -1438,9 +1437,9 @@ static void tui_raw_line(UI *ui, Integer g, Integer linerow, Integer startcol, I TUIData *data = ui->data; UGrid *grid = &data->grid; for (Integer c = startcol; c < endcol; c++) { - memcpy(grid->cells[linerow][c].data, chunk[c-startcol], sizeof(schar_T)); - assert((size_t)attrs[c-startcol] < kv_size(data->attrs)); - grid->cells[linerow][c].attr = attrs[c-startcol]; + memcpy(grid->cells[linerow][c].data, chunk[c - startcol], sizeof(schar_T)); + assert((size_t)attrs[c - startcol] < kv_size(data->attrs)); + grid->cells[linerow][c].attr = attrs[c - startcol]; } UGRID_FOREACH_CELL(grid, (int)linerow, (int)startcol, (int)endcol, { cursor_goto(ui, (int)linerow, curcol); @@ -1450,7 +1449,7 @@ static void tui_raw_line(UI *ui, Integer g, Integer linerow, Integer startcol, I if (clearcol > endcol) { ugrid_clear_chunk(grid, (int)linerow, (int)endcol, (int)clearcol, (sattr_T)clearattr); - clear_region(ui, (int)linerow, (int)linerow+1, (int)endcol, (int)clearcol, + clear_region(ui, (int)linerow, (int)linerow + 1, (int)endcol, (int)clearcol, (int)clearattr); } diff --git a/src/nvim/ugrid.c b/src/nvim/ugrid.c index ef84cdf334..d96da3f2bb 100644 --- a/src/nvim/ugrid.c +++ b/src/nvim/ugrid.c @@ -39,12 +39,12 @@ void ugrid_resize(UGrid *grid, int width, int height) void ugrid_clear(UGrid *grid) { - clear_region(grid, 0, grid->height-1, 0, grid->width-1, 0); + clear_region(grid, 0, grid->height - 1, 0, grid->width - 1, 0); } void ugrid_clear_chunk(UGrid *grid, int row, int col, int endcol, sattr_T attr) { - clear_region(grid, row, row, col, endcol-1, attr); + clear_region(grid, row, row, col, endcol - 1, attr); } void ugrid_goto(UGrid *grid, int row, int col) @@ -82,7 +82,7 @@ void ugrid_scroll(UGrid *grid, int top, int bot, int left, int right, int count) static void clear_region(UGrid *grid, int top, int bot, int left, int right, sattr_T attr) { for (int row = top; row <= bot; row++) { - UGRID_FOREACH_CELL(grid, row, left, right+1, { + UGRID_FOREACH_CELL(grid, row, left, right + 1, { cell->data[0] = ' '; cell->data[1] = 0; cell->attr = attr; @@ -99,4 +99,3 @@ static void destroy_cells(UGrid *grid) XFREE_CLEAR(grid->cells); } } - diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 4fe3e1157c..ac20b00c71 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -12,7 +12,6 @@ #include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/cursor_shape.h" -#include "nvim/msgpack_rpc/channel.h" #include "nvim/diff.h" #include "nvim/event/loop.h" #include "nvim/ex_cmds2.h" @@ -25,6 +24,7 @@ #include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/move.h" +#include "nvim/msgpack_rpc/channel.h" #include "nvim/normal.h" #include "nvim/option.h" #include "nvim/os/input.h" @@ -453,7 +453,7 @@ void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol, if (p_wd && !(rdb_flags & RDB_COMPOSITOR)) { // If 'writedelay' is active, set the cursor to indicate what was drawn. ui_call_grid_cursor_goto(grid->handle, row, - MIN(clearcol, (int)grid->Columns-1)); + MIN(clearcol, (int)grid->Columns - 1)); ui_call_flush(); uint64_t wd = (uint64_t)labs(p_wd); os_microdelay(wd * 1000u, true); diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c index 3402df817a..84098e9476 100644 --- a/src/nvim/ui_bridge.c +++ b/src/nvim/ui_bridge.c @@ -166,7 +166,7 @@ static void ui_bridge_raw_line(UI *ui, Integer grid, Integer row, Integer startc Integer clearcol, Integer clearattr, LineFlags flags, const schar_T *chunk, const sattr_T *attrs) { - size_t ncol = (size_t)(endcol-startcol); + size_t ncol = (size_t)(endcol - startcol); schar_T *c = xmemdup(chunk, ncol * sizeof(schar_T)); sattr_T *hl = xmemdup(attrs, ncol * sizeof(sattr_T)); UI_BRIDGE_CALL(ui, raw_line, 10, ui, INT2PTR(grid), INT2PTR(row), diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 6a7695bf72..4d1b9b1c52 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -1,20 +1,20 @@ // This is an open source non-commercial project. Dear PVS-Studio, please check // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com +#include <assert.h> #include <stdbool.h> #include <stdint.h> -#include <assert.h> -#include "nvim/vim.h" +#include "nvim/api/private/dispatch.h" +#include "nvim/api/private/helpers.h" +#include "nvim/highlight.h" #include "nvim/log.h" #include "nvim/map.h" -#include "nvim/ui_client.h" -#include "nvim/api/private/helpers.h" #include "nvim/msgpack_rpc/channel.h" -#include "nvim/api/private/dispatch.h" -#include "nvim/ui.h" -#include "nvim/highlight.h" #include "nvim/screen.h" +#include "nvim/ui.h" +#include "nvim/ui_client.h" +#include "nvim/vim.h" static Map(String, UIClientHandler) ui_client_handlers = MAP_INIT; @@ -109,7 +109,7 @@ static HlAttrs ui_client_dict2hlattrs(Dictionary d, bool rgb) } #ifdef INCLUDE_GENERATED_DECLARATIONS -#include "ui_events_client.generated.h" +# include "ui_events_client.generated.h" #endif void ui_client_event_grid_resize(Array args) @@ -210,5 +210,5 @@ void ui_client_event_grid_line(Array args) return; error: - ELOG("Error handling ui event 'grid_line'"); + ELOG("Error handling ui event 'grid_line'"); } diff --git a/src/nvim/ui_client.h b/src/nvim/ui_client.h index 253deecc52..d31341ae60 100644 --- a/src/nvim/ui_client.h +++ b/src/nvim/ui_client.h @@ -6,8 +6,9 @@ typedef void (*UIClientHandler)(Array args); #ifdef INCLUDE_GENERATED_DECLARATIONS -#include "ui_client.h.generated.h" -#include "ui_events_client.h.generated.h" +# include "ui_client.h.generated.h" + +# include "ui_events_client.h.generated.h" #endif #endif // NVIM_UI_CLIENT_H diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index e356960cc8..60ad8609a4 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -141,15 +141,15 @@ bool ui_comp_put_grid(ScreenGrid *grid, int row, int col, int height, int width, grid->comp_col, grid->comp_col + grid->Columns); if (grid->comp_col < col) { compose_area(MAX(row, grid->comp_row), - MIN(row+height, grid->comp_row+grid->Rows), + MIN(row + height, grid->comp_row + grid->Rows), grid->comp_col, col); } - if (col+width < grid->comp_col+grid->Columns) { + if (col + width < grid->comp_col + grid->Columns) { compose_area(MAX(row, grid->comp_row), - MIN(row+height, grid->comp_row+grid->Rows), - col+width, grid->comp_col+grid->Columns); + MIN(row + height, grid->comp_row + grid->Rows), + col + width, grid->comp_col + grid->Columns); } - compose_area(row+height, grid->comp_row+grid->Rows, + compose_area(row + height, grid->comp_row + grid->Rows, grid->comp_col, grid->comp_col + grid->Columns); grid->comp_disabled = false; } @@ -166,19 +166,19 @@ bool ui_comp_put_grid(ScreenGrid *grid, int row, int col, int height, int width, #endif size_t insert_at = kv_size(layers); - while (insert_at > 0 && kv_A(layers, insert_at-1)->zindex > grid->zindex) { + while (insert_at > 0 && kv_A(layers, insert_at - 1)->zindex > grid->zindex) { insert_at--; } - if (curwin && kv_A(layers, insert_at-1) == &curwin->w_grid_alloc - && kv_A(layers, insert_at-1)->zindex == grid->zindex + if (curwin && kv_A(layers, insert_at - 1) == &curwin->w_grid_alloc + && kv_A(layers, insert_at - 1)->zindex == grid->zindex && !on_top) { insert_at--; } // not found: new grid kv_pushp(layers); - for (size_t i = kv_size(layers)-1; i > insert_at; i--) { - kv_A(layers, i) = kv_A(layers, i-1); + for (size_t i = kv_size(layers) - 1; i > insert_at; i--) { + kv_A(layers, i) = kv_A(layers, i - 1); kv_A(layers, i)->comp_index = i; } kv_A(layers, insert_at) = grid; @@ -188,8 +188,8 @@ bool ui_comp_put_grid(ScreenGrid *grid, int row, int col, int height, int width, grid->comp_index = insert_at; } if (moved && valid && ui_comp_should_draw()) { - compose_area(grid->comp_row, grid->comp_row+grid->Rows, - grid->comp_col, grid->comp_col+grid->Columns); + compose_area(grid->comp_row, grid->comp_row + grid->Rows, + grid->comp_col, grid->comp_col + grid->Columns); } return moved; } @@ -206,8 +206,8 @@ void ui_comp_remove_grid(ScreenGrid *grid) curgrid = &default_grid; } - for (size_t i = grid->comp_index; i < kv_size(layers)-1; i++) { - kv_A(layers, i) = kv_A(layers, i+1); + for (size_t i = grid->comp_index; i < kv_size(layers) - 1; i++) { + kv_A(layers, i) = kv_A(layers, i + 1); kv_A(layers, i)->comp_index = i; } (void)kv_pop(layers); @@ -241,7 +241,7 @@ static void ui_comp_raise_grid(ScreenGrid *grid, size_t new_index) { size_t old_index = grid->comp_index; for (size_t i = old_index; i < new_index; i++) { - kv_A(layers, i) = kv_A(layers, i+1); + kv_A(layers, i) = kv_A(layers, i + 1); kv_A(layers, i)->comp_index = i; } kv_A(layers, new_index) = grid; @@ -249,10 +249,10 @@ static void ui_comp_raise_grid(ScreenGrid *grid, size_t new_index) for (size_t i = old_index; i < new_index; i++) { ScreenGrid *grid2 = kv_A(layers, i); int startcol = MAX(grid->comp_col, grid2->comp_col); - int endcol = MIN(grid->comp_col+grid->Columns, - grid2->comp_col+grid2->Columns); + int endcol = MIN(grid->comp_col + grid->Columns, + grid2->comp_col + grid2->Columns); compose_area(MAX(grid->comp_row, grid2->comp_row), - MIN(grid->comp_row+grid->Rows, grid2->comp_row+grid2->Rows), + MIN(grid->comp_row + grid->Rows, grid2->comp_row + grid2->Rows), startcol, endcol); } } @@ -262,13 +262,13 @@ static void ui_comp_grid_cursor_goto(UI *ui, Integer grid_handle, Integer r, Int if (!ui_comp_should_draw() || !ui_comp_set_grid((int)grid_handle)) { return; } - int cursor_row = curgrid->comp_row+(int)r; - int cursor_col = curgrid->comp_col+(int)c; + int cursor_row = curgrid->comp_row + (int)r; + int cursor_col = curgrid->comp_col + (int)c; // TODO(bfredl): maybe not the best time to do this, for efficiency we // should configure all grids before entering win_update() if (curgrid != &default_grid) { - size_t new_index = kv_size(layers)-1; + size_t new_index = kv_size(layers) - 1; while (new_index > 1 && kv_A(layers, new_index)->zindex > curgrid->zindex) { new_index--; @@ -289,11 +289,11 @@ static void ui_comp_grid_cursor_goto(UI *ui, Integer grid_handle, Integer r, Int ScreenGrid *ui_comp_mouse_focus(int row, int col) { - for (ssize_t i = (ssize_t)kv_size(layers)-1; i > 0; i--) { + for (ssize_t i = (ssize_t)kv_size(layers) - 1; i > 0; i--) { ScreenGrid *grid = kv_A(layers, i); if (grid->focusable - && row >= grid->comp_row && row < grid->comp_row+grid->Rows - && col >= grid->comp_col && col < grid->comp_col+grid->Columns) { + && row >= grid->comp_row && row < grid->comp_row + grid->Rows + && col >= grid->comp_col && col < grid->comp_col + grid->Columns) { return grid; } } @@ -323,9 +323,9 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag int col = (int)startcol; ScreenGrid *grid = NULL; schar_T *bg_line = &default_grid.chars[default_grid.line_offset[row] - +(size_t)startcol]; + + (size_t)startcol]; sattr_T *bg_attrs = &default_grid.attrs[default_grid.line_offset[row] - +(size_t)startcol]; + + (size_t)startcol]; int grid_width, grid_height; while (col < endcol) { @@ -355,7 +355,7 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag assert(grid != NULL); assert(until > col); assert(until <= default_grid.Columns); - size_t n = (size_t)(until-col); + size_t n = (size_t)(until - col); if (row == msg_sep_row && grid->comp_index <= msg_grid.comp_index) { // TODO(bfredl): when we implement borders around floating windows, then @@ -363,18 +363,18 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag grid = &msg_grid; sattr_T msg_sep_attr = (sattr_T)HL_ATTR(HLF_MSGSEP); for (int i = col; i < until; i++) { - memcpy(linebuf[i-startcol], msg_sep_char, sizeof(*linebuf)); - attrbuf[i-startcol] = msg_sep_attr; + memcpy(linebuf[i - startcol], msg_sep_char, sizeof(*linebuf)); + attrbuf[i - startcol] = msg_sep_attr; } } else { - size_t off = grid->line_offset[row-grid->comp_row] - + (size_t)(col-grid->comp_col); - memcpy(linebuf+(col-startcol), grid->chars+off, n * sizeof(*linebuf)); - memcpy(attrbuf+(col-startcol), grid->attrs+off, n * sizeof(*attrbuf)); - if (grid->comp_col+grid->Columns > until - && grid->chars[off+n][0] == NUL) { - linebuf[until-1-startcol][0] = ' '; - linebuf[until-1-startcol][1] = '\0'; + size_t off = grid->line_offset[row - grid->comp_row] + + (size_t)(col - grid->comp_col); + memcpy(linebuf + (col - startcol), grid->chars + off, n * sizeof(*linebuf)); + memcpy(attrbuf + (col - startcol), grid->attrs + off, n * sizeof(*attrbuf)); + if (grid->comp_col + grid->Columns > until + && grid->chars[off + n][0] == NUL) { + linebuf[until - 1 - startcol][0] = ' '; + linebuf[until - 1 - startcol][1] = '\0'; if (col == startcol && n == 1) { skipstart = 0; } @@ -384,18 +384,18 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag // 'pumblend' and 'winblend' if (grid->blending) { int width; - for (int i = col-(int)startcol; i < until-startcol; i += width) { + for (int i = col - (int)startcol; i < until - startcol; i += width) { width = 1; // negative space bool thru = strequal((char *)linebuf[i], " ") && bg_line[i][0] != NUL; - if (i+1 < endcol-startcol && bg_line[i+1][0] == NUL) { + if (i + 1 < endcol - startcol && bg_line[i + 1][0] == NUL) { width = 2; - thru &= strequal((char *)linebuf[i+1], " "); + thru &= strequal((char *)linebuf[i + 1], " "); } attrbuf[i] = (sattr_T)hl_blend_attrs(bg_attrs[i], attrbuf[i], &thru); if (width == 2) { - attrbuf[i+1] = (sattr_T)hl_blend_attrs(bg_attrs[i+1], - attrbuf[i+1], &thru); + attrbuf[i + 1] = (sattr_T)hl_blend_attrs(bg_attrs[i + 1], + attrbuf[i + 1], &thru); } if (thru) { memcpy(linebuf + i, bg_line + i, (size_t)width * sizeof(linebuf[i])); @@ -405,19 +405,19 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag // Tricky: if overlap caused a doublewidth char to get cut-off, must // replace the visible half with a space. - if (linebuf[col-startcol][0] == NUL) { - linebuf[col-startcol][0] = ' '; - linebuf[col-startcol][1] = NUL; - if (col == endcol-1) { + if (linebuf[col - startcol][0] == NUL) { + linebuf[col - startcol][0] = ' '; + linebuf[col - startcol][1] = NUL; + if (col == endcol - 1) { skipend = 0; } - } else if (n > 1 && linebuf[col-startcol+1][0] == NUL) { + } else if (n > 1 && linebuf[col - startcol + 1][0] == NUL) { skipstart = 0; } col = until; } - if (linebuf[endcol-startcol-1][0] == NUL) { + if (linebuf[endcol - startcol - 1][0] == NUL) { skipend = 0; } @@ -430,7 +430,7 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag flags = flags & ~kLineFlagWrap; } - for (int i = skipstart; i < (endcol-skipend)-startcol; i++) { + for (int i = skipstart; i < (endcol - skipend) - startcol; i++) { if (attrbuf[i] < 0) { if (rdb_flags & RDB_INVALID) { abort(); @@ -439,10 +439,10 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag } } } - ui_composed_call_raw_line(1, row, startcol+skipstart, - endcol-skipend, endcol-skipend, 0, flags, - (const schar_T *)linebuf+skipstart, - (const sattr_T *)attrbuf+skipstart); + ui_composed_call_raw_line(1, row, startcol + skipstart, + endcol - skipend, endcol - skipend, 0, flags, + (const schar_T *)linebuf + skipstart, + (const sattr_T *)attrbuf + skipstart); } static void compose_debug(Integer startrow, Integer endrow, Integer startcol, Integer endcol, @@ -464,7 +464,7 @@ static void compose_debug(Integer startrow, Integer endrow, Integer startcol, In if (delay) { - debug_delay(endrow-startrow); + debug_delay(endrow - startrow); } } @@ -497,8 +497,8 @@ static void compose_area(Integer startrow, Integer endrow, Integer startcol, Int void ui_comp_compose_grid(ScreenGrid *grid) { if (ui_comp_should_draw()) { - compose_area(grid->comp_row, grid->comp_row+grid->Rows, - grid->comp_col, grid->comp_col+grid->Columns); + compose_area(grid->comp_row, grid->comp_row + grid->Rows, + grid->comp_col, grid->comp_col + grid->Columns); } } @@ -541,13 +541,13 @@ static void ui_comp_raw_line(UI *ui, Integer grid, Integer row, Integer startcol // TODO(bfredl): eventually should just fix compose_line to respect clearing // and optimize it for uncovered lines. if (flags & kLineFlagInvalid || covered || curgrid->blending) { - compose_debug(row, row+1, startcol, clearcol, dbghl_composed, true); + compose_debug(row, row + 1, startcol, clearcol, dbghl_composed, true); compose_line(row, startcol, clearcol, flags); } else { - compose_debug(row, row+1, startcol, endcol, dbghl_normal, false); - compose_debug(row, row+1, endcol, clearcol, dbghl_clear, true); + compose_debug(row, row + 1, startcol, endcol, dbghl_normal, false); + compose_debug(row, row + 1, endcol, clearcol, dbghl_clear, true); #ifndef NDEBUG - for (int i = 0; i < endcol-startcol; i++) { + for (int i = 0; i < endcol - startcol; i++) { assert(attrs[i] >= 0); } #endif @@ -572,7 +572,7 @@ static void ui_comp_msg_set_pos(UI *ui, Integer grid, Integer row, Boolean scrol { msg_grid.comp_row = (int)row; if (scrolled && row > 0) { - msg_sep_row = (int)row-1; + msg_sep_row = (int)row - 1; if (sep_char.data) { STRLCPY(msg_sep_char, sep_char.data, sizeof(msg_sep_char)); } @@ -581,19 +581,19 @@ static void ui_comp_msg_set_pos(UI *ui, Integer grid, Integer row, Boolean scrol } if (row > msg_current_row && ui_comp_should_draw()) { - compose_area(MAX(msg_current_row-1, 0), row, 0, default_grid.Columns); + compose_area(MAX(msg_current_row - 1, 0), row, 0, default_grid.Columns); } else if (row < msg_current_row && ui_comp_should_draw() && msg_current_row < Rows) { int delta = msg_current_row - (int)row; if (msg_grid.blending) { - int first_row = MAX((int)row-(scrolled?1:0), 0); - compose_area(first_row, Rows-delta, 0, Columns); + int first_row = MAX((int)row - (scrolled?1:0), 0); + compose_area(first_row, Rows - delta, 0, Columns); } else { // scroll separator together with message text - int first_row = MAX((int)row-(msg_was_scrolled?1:0), 0); + int first_row = MAX((int)row - (msg_was_scrolled?1:0), 0); ui_composed_call_grid_scroll(1, first_row, Rows, 0, Columns, delta, 0); if (scrolled && !msg_was_scrolled && row > 0) { - compose_area(row-1, row, 0, Columns); + compose_area(row - 1, row, 0, Columns); } } } @@ -607,9 +607,9 @@ static void ui_comp_msg_set_pos(UI *ui, Integer grid, Integer row, Boolean scrol /// TODO(bfredl): currently this only handles message row static bool curgrid_covered_above(int row) { - bool above_msg = (kv_A(layers, kv_size(layers)-1) == &msg_grid - && row < msg_current_row-(msg_was_scrolled?1:0)); - return kv_size(layers)-(above_msg?1:0) > curgrid->comp_index+1; + bool above_msg = (kv_A(layers, kv_size(layers) - 1) == &msg_grid + && row < msg_current_row - (msg_was_scrolled?1:0)); + return kv_size(layers) - (above_msg?1:0) > curgrid->comp_index + 1; } static void ui_comp_grid_scroll(UI *ui, Integer grid, Integer top, Integer bot, Integer left, @@ -634,8 +634,8 @@ static void ui_comp_grid_scroll(UI *ui, Integer grid, Integer top, Integer bot, // row, where the latter might scroll invalid space created by the first. // ideally win_update() should keep track of this itself and not scroll // the invalid space. - if (curgrid->attrs[curgrid->line_offset[r-curgrid->comp_row] - +left-curgrid->comp_col] >= 0) { + if (curgrid->attrs[curgrid->line_offset[r - curgrid->comp_row] + + left - curgrid->comp_col] >= 0) { compose_line(r, left, right, 0); } } @@ -665,4 +665,3 @@ static void ui_comp_grid_resize(UI *ui, Integer grid, Integer width, Integer hei } } } - diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 2d8df4cad8..007febee66 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -3110,7 +3110,7 @@ void u_undoline(void) oldp = u_save_line(curbuf->b_u_line_lnum); ml_replace(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr, true); changed_bytes(curbuf->b_u_line_lnum, 0); - extmark_splice_cols(curbuf, (int)curbuf->b_u_line_lnum-1, 0, (colnr_T)STRLEN(oldp), + extmark_splice_cols(curbuf, (int)curbuf->b_u_line_lnum - 1, 0, (colnr_T)STRLEN(oldp), (colnr_T)STRLEN(curbuf->b_u_line_ptr), kExtmarkUndo); xfree(curbuf->b_u_line_ptr); curbuf->b_u_line_ptr = oldp; diff --git a/src/nvim/version.c b/src/nvim/version.c index 71cca52773..d5e8d435df 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -2053,7 +2053,7 @@ static void list_features(void) version_msg(_("\n\nFeatures: ")); for (int i = 0; features[i] != NULL; i++) { version_msg(features[i]); - if (features[i+1] != NULL) { + if (features[i + 1] != NULL) { version_msg(" "); } } @@ -2329,4 +2329,3 @@ void ex_intro(exarg_T *eap) intro_message(TRUE); wait_return(TRUE); } - diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index b8b0a38f44..29d686193d 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -541,8 +541,7 @@ LexExprToken viml_pexpr_next_token(ParserState *const pstate, const int flags) ret.data.opt.len = 4; ret.len += 4; } else { - for (; p < e && ASCII_ISALPHA(*p); p++) { - } + for (; p < e && ASCII_ISALPHA(*p); p++) {} ret.data.opt.len = (size_t)(p - ret.data.opt.name); if (ret.data.opt.len == 0) { OPTNAMEMISS(ret); @@ -1817,9 +1816,13 @@ static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const no } // Special key, e.g.: "\<C-W>" case '<': { - const size_t special_len = ( - trans_special((const char_u **)&p, (size_t)(e - p), - (char_u *)v_p, true, true)); + int flags = FSK_KEYCODE | FSK_IN_STRING; + + if (p[1] != '*') { + flags |= FSK_SIMPLIFY; + } + const size_t special_len = trans_special((const char_u **)&p, (size_t)(e - p), + (char_u *)v_p, flags, NULL); if (special_len != 0) { v_p += special_len; } else { diff --git a/src/nvim/window.c b/src/nvim/window.c index f68cfe4c9c..90f7145f51 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -429,7 +429,7 @@ newwindow: // set current window height case Ctrl__: case '_': - win_setheight(Prenum ? (int)Prenum : Rows-1); + win_setheight(Prenum ? (int)Prenum : Rows - 1); break; // increase current window width @@ -489,7 +489,7 @@ wingotofile: setpcmark(); if (win_split(0, 0) == OK) { RESET_BINDING(curwin); - if (do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL, ECMD_HIDE, NULL) == FAIL) { + if (do_ecmd(0, (char *)ptr, NULL, NULL, ECMD_LASTL, ECMD_HIDE, NULL) == FAIL) { // Failed to open the file, close the window opened for it. win_close(curwin, false, false); goto_tabpage_win(oldtab, oldwin); @@ -534,11 +534,13 @@ wingotofile: case Ctrl_G: CHECK_CMDWIN; no_mapping++; + allow_keys++; // no mapping for xchar, but allow key codes if (xchar == NUL) { xchar = plain_vgetc(); } LANGMAP_ADJUST(xchar, true); no_mapping--; + allow_keys--; (void)add_to_showcmd(xchar); switch (xchar) { case '}': @@ -879,11 +881,11 @@ void ui_ext_win_position(win_T *wp) row += row_off; col += col_off; if (c.bufpos.lnum >= 0) { - pos_T pos = { c.bufpos.lnum+1, c.bufpos.col, 0 }; + pos_T pos = { c.bufpos.lnum + 1, c.bufpos.col, 0 }; int trow, tcol, tcolc, tcole; textpos2screenpos(win, &pos, &trow, &tcol, &tcolc, &tcole, true); - row += trow-1; - col += tcol-1; + row += trow - 1; + col += tcol - 1; } } api_clear_error(&dummy); @@ -929,13 +931,13 @@ void ui_ext_win_viewport(win_T *wp) if ((wp == curwin || ui_has(kUIMultigrid)) && wp->w_viewport_invalid) { int botline = wp->w_botline; int line_count = wp->w_buffer->b_ml.ml_line_count; - if (botline == line_count+1 && wp->w_empty_rows == 0) { + if (botline == line_count + 1 && wp->w_empty_rows == 0) { // TODO(bfredl): The might be more cases to consider, like how does this // interact with incomplete final line? Diff filler lines? botline = wp->w_buffer->b_ml.ml_line_count; } - ui_call_win_viewport(wp->w_grid_alloc.handle, wp->handle, wp->w_topline-1, - botline, wp->w_cursor.lnum-1, wp->w_cursor.col, + ui_call_win_viewport(wp->w_grid_alloc.handle, wp->handle, wp->w_topline - 1, + botline, wp->w_cursor.lnum - 1, wp->w_cursor.col, line_count); wp->w_viewport_invalid = false; } @@ -1875,8 +1877,7 @@ static void win_rotate(bool upwards, int count) assert(frp->fr_parent->fr_child); // find last frame and append removed window/frame after it - for (; frp->fr_next != NULL; frp = frp->fr_next) { - } + for (; frp->fr_next != NULL; frp = frp->fr_next) {} win_append(frp->fr_win, wp1); frame_append(frp, wp1->w_frame); @@ -1884,8 +1885,7 @@ static void win_rotate(bool upwards, int count) } else { // last window becomes first window // find last window/frame in the list and remove it for (frp = curwin->w_frame; frp->fr_next != NULL; - frp = frp->fr_next) { - } + frp = frp->fr_next) {} wp1 = frp->fr_win; wp2 = wp1->w_prev; // will become last window win_remove(wp1, NULL); @@ -2955,8 +2955,7 @@ void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp) // Careful: Autocommands may have closed the tab page or made it the // current tab page. - for (ptp = first_tabpage; ptp != NULL && ptp != tp; ptp = ptp->tp_next) { - } + for (ptp = first_tabpage; ptp != NULL && ptp != tp; ptp = ptp->tp_next) {} if (ptp == NULL || tp == curtab) { // If the buffer was removed from the window we have to give it any // buffer. @@ -3314,8 +3313,7 @@ static tabpage_T *alt_tabpage(void) } // Find the last but one tab page. - for (tp = first_tabpage; tp->tp_next != curtab; tp = tp->tp_next) { - } + for (tp = first_tabpage; tp->tp_next != curtab; tp = tp->tp_next) {} return tp; } @@ -3438,13 +3436,11 @@ void frame_new_height(frame_T *topfrp, int height, bool topfirst, bool wfh) if (topfirst) { do { frp = frp->fr_next; - } - while (wfh && frp != NULL && frame_fixed_height(frp)); + } while (wfh && frp != NULL && frame_fixed_height(frp)); } else { do { frp = frp->fr_prev; - } - while (wfh && frp != NULL && frame_fixed_height(frp)); + } while (wfh && frp != NULL && frame_fixed_height(frp)); } // Increase "height" if we could not reduce enough frames. if (frp == NULL) { @@ -3551,8 +3547,7 @@ static void frame_add_statusline(frame_T *frp) } else { assert(frp->fr_layout == FR_COL); // Only need to handle the last frame in the column. - for (frp = frp->fr_child; frp->fr_next != NULL; frp = frp->fr_next) { - } + for (frp = frp->fr_child; frp->fr_next != NULL; frp = frp->fr_next) {} frame_add_statusline(frp); } } @@ -3638,13 +3633,11 @@ static void frame_new_width(frame_T *topfrp, int width, bool leftfirst, bool wfw if (leftfirst) { do { frp = frp->fr_next; - } - while (wfw && frp != NULL && frame_fixed_width(frp)); + } while (wfw && frp != NULL && frame_fixed_width(frp)); } else { do { frp = frp->fr_prev; - } - while (wfw && frp != NULL && frame_fixed_width(frp)); + } while (wfw && frp != NULL && frame_fixed_width(frp)); } // Increase "width" if we could not reduce enough frames. if (frp == NULL) { @@ -4422,14 +4415,12 @@ void goto_tabpage(int n) ttp = curtab; for (i = n; i < 0; ++i) { for (tp = first_tabpage; tp->tp_next != ttp && tp->tp_next != NULL; - tp = tp->tp_next) { - } + tp = tp->tp_next) {} ttp = tp; } } else if (n == 9999) { // Go to last tab page. - for (tp = first_tabpage; tp->tp_next != NULL; tp = tp->tp_next) { - } + for (tp = first_tabpage; tp->tp_next != NULL; tp = tp->tp_next) {} } else { // Go to tab page "n". tp = find_tabpage(n); diff --git a/src/uncrustify.cfg b/src/uncrustify.cfg index 49ce394dc9..401e48d6e0 100644 --- a/src/uncrustify.cfg +++ b/src/uncrustify.cfg @@ -1,4 +1,4 @@ -# Uncrustify-0.74.0 +# Uncrustify-0.74.0_f # # General options @@ -81,7 +81,7 @@ sp_arith = ignore # ignore/add/remove/force/not_defined # Add or remove space around arithmetic operators '+' and '-'. # # Overrides sp_arith. -sp_arith_additive = ignore # ignore/add/remove/force/not_defined +sp_arith_additive = force # ignore/add/remove/force/not_defined # Add or remove space around assignment operator '=', '+=', etc. sp_assign = ignore # ignore/add/remove/force/not_defined @@ -172,7 +172,7 @@ sp_inside_paren = remove # ignore/add/remove/force/not_defined sp_paren_paren = remove # ignore/add/remove/force/not_defined # Add or remove space between back-to-back parentheses, i.e. ')(' vs. ') ('. -sp_cparen_oparen = ignore # ignore/add/remove/force/not_defined +sp_cparen_oparen = remove # ignore/add/remove/force/not_defined # Whether to balance spaces inside nested parentheses. sp_balance_nested_parens = false # true/false @@ -343,13 +343,13 @@ sp_inside_for_open = ignore # ignore/add/remove/force/not_defined sp_inside_for_close = ignore # ignore/add/remove/force/not_defined # Add or remove space between '((' or '))' of control statements. -sp_sparen_paren = ignore # ignore/add/remove/force/not_defined +sp_sparen_paren = remove # ignore/add/remove/force/not_defined # Add or remove space after ')' of control statements. sp_after_sparen = ignore # ignore/add/remove/force/not_defined # Add or remove space between ')' and '{' of control statements. -sp_sparen_brace = ignore # ignore/add/remove/force/not_defined +sp_sparen_brace = force # ignore/add/remove/force/not_defined # Add or remove space between 'do' and '{'. sp_do_brace_open = force # ignore/add/remove/force/not_defined @@ -592,7 +592,7 @@ sp_type_func = ignore # ignore/add/remove/force/not_defined sp_type_brace_init_lst = ignore # ignore/add/remove/force/not_defined # Add or remove space between function name and '(' on function declaration. -sp_func_proto_paren = ignore # ignore/add/remove/force/not_defined +sp_func_proto_paren = remove # ignore/add/remove/force/not_defined # Add or remove space between function name and '()' on function declaration # without parameters. @@ -1507,7 +1507,7 @@ donot_indent_func_def_close_paren = false # true/false # Whether to collapse empty blocks between '{' and '}'. # If true, overrides nl_inside_empty_func -nl_collapse_empty_body = false # true/false +nl_collapse_empty_body = true # true/false # Don't split one-line braced assignments, as in 'foo_t f = { 1, 2 };'. nl_assign_leave_one_liners = false # true/false @@ -1575,11 +1575,11 @@ nl_start_of_file = ignore # ignore/add/remove/force/not_defined nl_start_of_file_min = 0 # unsigned number # Add or remove newline at the end of the file. -nl_end_of_file = ignore # ignore/add/remove/force/not_defined +nl_end_of_file = force # ignore/add/remove/force/not_defined # The minimum number of newlines at the end of the file (only used if # nl_end_of_file is 'add' or 'force'). -nl_end_of_file_min = 0 # unsigned number +nl_end_of_file_min = 1 # unsigned number # Add or remove newline between '=' and '{'. nl_assign_brace = ignore # ignore/add/remove/force/not_defined @@ -1599,7 +1599,7 @@ nl_after_square_assign = ignore # ignore/add/remove/force/not_defined nl_fcall_brace = ignore # ignore/add/remove/force/not_defined # Add or remove newline between 'enum' and '{'. -nl_enum_brace = ignore # ignore/add/remove/force/not_defined +nl_enum_brace = remove # ignore/add/remove/force/not_defined # Add or remove newline between 'enum' and 'class'. nl_enum_class = ignore # ignore/add/remove/force/not_defined @@ -1675,7 +1675,7 @@ nl_oc_brace_catch = ignore # ignore/add/remove/force/not_defined nl_brace_square = ignore # ignore/add/remove/force/not_defined # Add or remove newline between '}' and ')' in a function invocation. -nl_brace_fparen = ignore # ignore/add/remove/force/not_defined +nl_brace_fparen = remove # ignore/add/remove/force/not_defined # Add or remove newline between 'while' and '{'. nl_while_brace = ignore # ignore/add/remove/force/not_defined @@ -1700,7 +1700,7 @@ nl_brace_brace = ignore # ignore/add/remove/force/not_defined nl_do_brace = remove # ignore/add/remove/force/not_defined # Add or remove newline between '}' and 'while' of 'do' statement. -nl_brace_while = ignore # ignore/add/remove/force/not_defined +nl_brace_while = remove # ignore/add/remove/force/not_defined # Add or remove newline between 'switch' and '{'. nl_switch_brace = ignore # ignore/add/remove/force/not_defined @@ -3391,5 +3391,5 @@ set QUESTION REAL_FATTR_CONST set QUESTION REAL_FATTR_NONNULL_ALL set QUESTION REAL_FATTR_PURE set QUESTION REAL_FATTR_WARN_UNUSED_RESULT -# option(s) with 'not default' value: 86 +# option(s) with 'not default' value: 97 # |