aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/command.c6
-rw-r--r--src/nvim/api/extmark.c2
-rw-r--r--src/nvim/api/keysets.lua3
-rw-r--r--src/nvim/api/vim.c19
-rw-r--r--src/nvim/buffer.c8
-rw-r--r--src/nvim/buffer_defs.h2
-rw-r--r--src/nvim/buffer_updates.c9
-rw-r--r--src/nvim/charset.c16
-rw-r--r--src/nvim/charset.h1
-rw-r--r--src/nvim/cmdexpand.c10
-rw-r--r--src/nvim/drawline.c8
-rw-r--r--src/nvim/drawscreen.c10
-rw-r--r--src/nvim/edit.c52
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/eval/userfunc.c16
-rw-r--r--src/nvim/ex_cmds.c9
-rw-r--r--src/nvim/ex_docmd.c10
-rw-r--r--src/nvim/ex_getln.c2
-rw-r--r--src/nvim/fileio.c20
-rw-r--r--src/nvim/fold.c4
-rw-r--r--src/nvim/getchar.c14
-rw-r--r--src/nvim/globals.h4
-rw-r--r--src/nvim/hardcopy.c12
-rw-r--r--src/nvim/hashtab.c3
-rw-r--r--src/nvim/hashtab.h17
-rw-r--r--src/nvim/indent.c2
-rw-r--r--src/nvim/indent_c.c472
-rw-r--r--src/nvim/insexpand.c19
-rw-r--r--src/nvim/keycodes.c28
-rw-r--r--src/nvim/lua/executor.c16
-rw-r--r--src/nvim/main.c262
-rw-r--r--src/nvim/main.h3
-rw-r--r--src/nvim/mapping.c74
-rw-r--r--src/nvim/memory.c20
-rw-r--r--src/nvim/message.c12
-rw-r--r--src/nvim/move.c62
-rw-r--r--src/nvim/normal.c2
-rw-r--r--src/nvim/option.c170
-rw-r--r--src/nvim/options.lua2
-rw-r--r--src/nvim/os/input.c2
-rw-r--r--src/nvim/os/shell.c2
-rw-r--r--src/nvim/os/users.c2
-rw-r--r--src/nvim/os_unix.c6
-rw-r--r--src/nvim/regexp.c16
-rw-r--r--src/nvim/regexp_bt.c16
-rw-r--r--src/nvim/spell.c80
-rw-r--r--src/nvim/spell_defs.h4
-rw-r--r--src/nvim/spellfile.c38
-rw-r--r--src/nvim/spellsuggest.c212
-rw-r--r--src/nvim/strings.c4
-rw-r--r--src/nvim/terminal.c4
-rw-r--r--src/nvim/testdir/test_cursor_func.vim8
-rw-r--r--src/nvim/testdir/test_filetype.vim11
-rw-r--r--src/nvim/testdir/test_fold.vim21
-rw-r--r--src/nvim/testdir/test_ins_complete.vim42
-rw-r--r--src/nvim/testdir/test_signs.vim58
-rw-r--r--src/nvim/testdir/test_startup.vim8
-rw-r--r--src/nvim/testdir/test_usercommands.vim5
-rw-r--r--src/nvim/testdir/test_window_cmd.vim13
-rw-r--r--src/nvim/testdir/test_writefile.vim46
-rw-r--r--src/nvim/tui/terminfo.c75
-rw-r--r--src/nvim/tui/terminfo.h2
-rw-r--r--src/nvim/tui/tui.c109
-rw-r--r--src/nvim/undo.c6
-rw-r--r--src/nvim/usercmd.c9
-rw-r--r--src/nvim/vim.h5
-rw-r--r--src/nvim/viml/parser/expressions.c2
-rw-r--r--src/nvim/window.c2
68 files changed, 1208 insertions, 1003 deletions
diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c
index ac1927eeb1..abd265f2cf 100644
--- a/src/nvim/api/command.c
+++ b/src/nvim/api/command.c
@@ -660,6 +660,12 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error
OBJ_TO_CMOD_FLAG(CMOD_LOCKMARKS, mods.lockmarks, false, "'mods.lockmarks'");
OBJ_TO_CMOD_FLAG(CMOD_NOSWAPFILE, mods.noswapfile, false, "'mods.noswapfile'");
+ if (cmdinfo.cmdmod.cmod_flags & CMOD_ERRSILENT) {
+ // CMOD_ERRSILENT must imply CMOD_SILENT, otherwise apply_cmdmod() and undo_cmdmod() won't
+ // work properly.
+ cmdinfo.cmdmod.cmod_flags |= CMOD_SILENT;
+ }
+
if ((cmdinfo.cmdmod.cmod_flags & CMOD_SANDBOX) && !(ea.argt & EX_SBOXOK)) {
VALIDATION_ERROR("Command cannot be run in sandbox");
}
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c
index bdc0900dd9..f7c6b398d5 100644
--- a/src/nvim/api/extmark.c
+++ b/src/nvim/api/extmark.c
@@ -40,7 +40,7 @@ void api_extmark_free_all_mem(void)
map_destroy(String, handle_T)(&namespace_ids);
}
-/// Creates a new \*namespace\* or gets an existing one.
+/// Creates a new namespace or gets an existing one. \*namespace\*
///
/// Namespaces are used for buffer highlights and virtual text, see
/// |nvim_buf_add_highlight()| and |nvim_buf_set_extmark()|.
diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua
index 7e0d399573..8ded9cfa5d 100644
--- a/src/nvim/api/keysets.lua
+++ b/src/nvim/api/keysets.lua
@@ -219,5 +219,8 @@ return {
cmd_opts = {
"output";
};
+ echo_opts = {
+ "verbose";
+ };
}
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 70b07dabe8..83c9d54725 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -726,8 +726,11 @@ void nvim_set_vvar(String name, Object value, Error *err)
/// text chunk with specified highlight. `hl_group` element
/// can be omitted for no highlight.
/// @param history if true, add to |message-history|.
-/// @param opts Optional parameters. Reserved for future use.
-void nvim_echo(Array chunks, Boolean history, Dictionary opts, Error *err)
+/// @param opts Optional parameters.
+/// - verbose: Message was printed as a result of 'verbose' option
+/// if Nvim was invoked with -V3log_file, the message will be
+/// redirected to the log_file and surpressed from direct output.
+void nvim_echo(Array chunks, Boolean history, Dict(echo_opts) *opts, Error *err)
FUNC_API_SINCE(7)
{
HlMessage hl_msg = parse_hl_msg(chunks, err);
@@ -735,13 +738,19 @@ void nvim_echo(Array chunks, Boolean history, Dictionary opts, Error *err)
goto error;
}
- if (opts.size > 0) {
- api_set_error(err, kErrorTypeValidation, "opts dict isn't empty");
- goto error;
+ bool verbose = api_object_to_bool(opts->verbose, "verbose", false, err);
+
+ if (verbose) {
+ verbose_enter();
}
msg_multiattr(hl_msg, history ? "echomsg" : "echo", history);
+ if (verbose) {
+ verbose_leave();
+ verbose_stop(); // flush now
+ }
+
if (history) {
// history takes ownership
return;
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index b67aee6907..0c74ccf0f4 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -1090,13 +1090,13 @@ char *do_bufdel(int command, char *arg, int addr_count, int start_bnr, int end_b
errormsg = (char *)IObuff;
} else if (deleted >= p_report) {
if (command == DOBUF_UNLOAD) {
- smsg(NGETTEXT("%d buffer unloaded", "%d buffers unloaded", (unsigned long)deleted),
+ smsg(NGETTEXT("%d buffer unloaded", "%d buffers unloaded", deleted),
deleted);
} else if (command == DOBUF_DEL) {
- smsg(NGETTEXT("%d buffer deleted", "%d buffers deleted", (unsigned long)deleted),
+ smsg(NGETTEXT("%d buffer deleted", "%d buffers deleted", deleted),
deleted);
} else {
- smsg(NGETTEXT("%d buffer wiped out", "%d buffers wiped out", (unsigned long)deleted),
+ smsg(NGETTEXT("%d buffer wiped out", "%d buffers wiped out", deleted),
deleted);
}
}
@@ -3149,7 +3149,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate)
vim_snprintf_add(buffer, IOSIZE,
NGETTEXT("%" PRId64 " line --%d%%--",
"%" PRId64 " lines --%d%%--",
- (unsigned long)curbuf->b_ml.ml_line_count),
+ curbuf->b_ml.ml_line_count),
(int64_t)curbuf->b_ml.ml_line_count, n);
} else {
vim_snprintf_add(buffer, IOSIZE,
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index e828b294b9..90fdaf9d3b 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -318,7 +318,7 @@ typedef struct {
typedef struct mapblock mapblock_T;
struct mapblock {
mapblock_T *m_next; // next mapblock in list
- uint8_t *m_keys; // mapped from, lhs
+ char *m_keys; // mapped from, lhs
char *m_str; // mapped to, rhs
char *m_orig_str; // rhs as entered by the user
LuaRef m_luaref; // lua function reference as rhs
diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c
index 2c92fb26b2..c66571560a 100644
--- a/src/nvim/buffer_updates.c
+++ b/src/nvim/buffer_updates.c
@@ -147,6 +147,15 @@ void buf_updates_unregister(buf_T *buf, uint64_t channelid)
}
}
+void buf_free_callbacks(buf_T *buf)
+{
+ kv_destroy(buf->update_channels);
+ for (size_t i = 0; i < kv_size(buf->update_callbacks); i++) {
+ buffer_update_callbacks_free(kv_A(buf->update_callbacks, i));
+ }
+ kv_destroy(buf->update_callbacks);
+}
+
void buf_updates_unload(buf_T *buf, bool can_reload)
{
size_t size = kv_size(buf->update_channels);
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index a8abee42be..51eddd5850 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -418,6 +418,22 @@ char *transstr(const char *const s, bool untab)
return buf;
}
+size_t kv_transstr(StringBuilder *str, const char *const s, bool untab)
+ FUNC_ATTR_NONNULL_ARG(1)
+{
+ if (!s) {
+ return 0;
+ }
+
+ // Compute the length of the result, taking account of unprintable
+ // multi-byte characters.
+ const size_t len = transstr_len(s, untab);
+ kv_ensure_space(*str, len + 1);
+ transstr_buf(s, str->items + str->size, len + 1, untab);
+ str->size += len; // do not include NUL byte
+ return len;
+}
+
/// Convert the string "str[orglen]" to do ignore-case comparing.
/// Use the current locale.
///
diff --git a/src/nvim/charset.h b/src/nvim/charset.h
index 978a357aa7..e1ef06ef1d 100644
--- a/src/nvim/charset.h
+++ b/src/nvim/charset.h
@@ -7,6 +7,7 @@
#include "nvim/eval/typval.h"
#include "nvim/option_defs.h"
#include "nvim/pos.h"
+#include "nvim/strings.h"
#include "nvim/types.h"
/// Return the folded-case equivalent of the given character
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c
index d1a56feef4..c964c96dd7 100644
--- a/src/nvim/cmdexpand.c
+++ b/src/nvim/cmdexpand.c
@@ -2960,7 +2960,7 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp)
if (xp->xp_context == EXPAND_FILES
|| xp->xp_context == EXPAND_DIRECTORIES
|| xp->xp_context == EXPAND_SHELLCMD) {
- char_u upseg[5];
+ char upseg[5];
upseg[0] = PATHSEP;
upseg[1] = '.';
@@ -2977,7 +2977,7 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp)
// go down a directory
c = (int)p_wc;
KeyTyped = true; // in case the key was mapped
- } else if (STRNCMP(xp->xp_pattern, upseg + 1, 3) == 0
+ } else if (strncmp(xp->xp_pattern, upseg + 1, 3) == 0
&& c == K_DOWN) {
// If in a direct ancestor, strip off one ../ to go down
int found = false;
@@ -3024,9 +3024,9 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp)
if (!found) {
j = i;
- } else if (STRNCMP(cclp->cmdbuff + j, upseg, 4) == 0) {
+ } else if (strncmp(cclp->cmdbuff + j, upseg, 4) == 0) {
j += 4;
- } else if (STRNCMP(cclp->cmdbuff + j, upseg + 1, 3) == 0
+ } else if (strncmp(cclp->cmdbuff + j, upseg + 1, 3) == 0
&& j == i) {
j += 3;
} else {
@@ -3037,7 +3037,7 @@ int wildmenu_process_key(CmdlineInfo *cclp, int key, expand_T *xp)
// TODO(tarruda): this is only for DOS/Unix systems - need to put in
// machine-specific stuff here and in upseg init
cmdline_del(cclp, j);
- put_on_cmdline(upseg + 1, 3, false);
+ put_on_cmdline((char_u *)upseg + 1, 3, false);
} else if (cclp->cmdpos > i) {
cmdline_del(cclp, i);
}
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index b5119ca8a2..74e493926f 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -553,7 +553,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
int char_attr = 0; // attributes for next character
bool attr_pri = false; // char_attr has priority
bool area_highlighting = false; // Visual or incsearch highlighting in this line
- int attr = 0; // attributes for area highlighting
+ int vi_attr = 0; // attributes for Visual and incsearch highlighting
int area_attr = 0; // attributes desired by highlighting
int search_attr = 0; // attributes desired by 'hlsearch'
int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
@@ -792,7 +792,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
// if inverting in this line set area_highlighting
if (fromcol >= 0) {
area_highlighting = true;
- attr = win_hl_attr(wp, HLF_V);
+ vi_attr = win_hl_attr(wp, HLF_V);
}
// handle 'incsearch' and ":s///c" highlighting
} else if (highlight_match
@@ -816,7 +816,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
tocol = fromcol + 1;
}
area_highlighting = true;
- attr = win_hl_attr(wp, HLF_I);
+ vi_attr = win_hl_attr(wp, HLF_I);
}
}
@@ -1413,7 +1413,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
|| ((int)vcol_prev == fromcol_prev
&& vcol_prev < vcol // not at margin
&& vcol < tocol)) {
- area_attr = attr; // start highlighting
+ area_attr = vi_attr; // start highlighting
if (area_highlighting) {
area_active = true;
}
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c
index 4a300384e7..de6bdda71e 100644
--- a/src/nvim/drawscreen.c
+++ b/src/nvim/drawscreen.c
@@ -956,9 +956,6 @@ static void draw_sep_connectors_win(win_T *wp)
/// bot: from bot_start to last row (when scrolled up)
static void win_update(win_T *wp, DecorProviders *providers)
{
- bool called_decor_providers = false;
-win_update_start:
- ;
int top_end = 0; // Below last row of the top area that needs
// updating. 0 when no top area updating.
int mid_start = 999; // first row of the mid area that needs
@@ -1028,13 +1025,6 @@ win_update_start:
DecorProviders line_providers;
decor_providers_invoke_win(wp, providers, &line_providers, &provider_err);
- if (must_redraw != 0) {
- must_redraw = 0;
- if (!called_decor_providers) {
- called_decor_providers = true;
- goto win_update_start;
- }
- }
redraw_win_signcol(wp);
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 09836e747f..5df52ab56e 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -2777,7 +2777,7 @@ static bool echeck_abbr(int c)
return false;
}
- return check_abbr(c, (char_u *)get_cursor_line_ptr(), curwin->w_cursor.col,
+ return check_abbr(c, get_cursor_line_ptr(), curwin->w_cursor.col,
curwin->w_cursor.lnum == Insstart.lnum ? Insstart.col : 0);
}
@@ -3018,11 +3018,11 @@ bool cindent_on(void)
/// @param line_is_empty when true, accept keys with '0' before them.
bool in_cinkeys(int keytyped, int when, bool line_is_empty)
{
- uint8_t *look;
+ char *look;
int try_match;
int try_match_word;
- uint8_t *p;
- uint8_t *line;
+ char *p;
+ char *line;
bool icase;
if (keytyped == NUL) {
@@ -3031,9 +3031,9 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty)
}
if (*curbuf->b_p_inde != NUL) {
- look = (uint8_t *)curbuf->b_p_indk; // 'indentexpr' set: use 'indentkeys'
+ look = curbuf->b_p_indk; // 'indentexpr' set: use 'indentkeys'
} else {
- look = (uint8_t *)curbuf->b_p_cink; // 'indentexpr' empty: use 'cinkeys'
+ look = curbuf->b_p_cink; // 'indentexpr' empty: use 'cinkeys'
}
while (*look) {
// Find out if we want to try a match with this key, depending on
@@ -3086,9 +3086,9 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty)
// cursor.
} else if (*look == 'e') {
if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4) {
- p = (uint8_t *)get_cursor_line_ptr();
- if ((uint8_t *)skipwhite((char *)p) == p + curwin->w_cursor.col - 4
- && STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0) {
+ p = get_cursor_line_ptr();
+ if (skipwhite(p) == p + curwin->w_cursor.col - 4
+ && strncmp(p + curwin->w_cursor.col - 4, "else", 4) == 0) {
return true;
}
}
@@ -3099,12 +3099,12 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty)
// class::method for C++).
} else if (*look == ':') {
if (try_match && keytyped == ':') {
- p = (uint8_t *)get_cursor_line_ptr();
+ p = get_cursor_line_ptr();
if (cin_iscase((char_u *)p, false) || cin_isscopedecl((char_u *)p) || cin_islabel()) {
return true;
}
// Need to get the line again after cin_islabel().
- p = (uint8_t *)get_cursor_line_ptr();
+ p = get_cursor_line_ptr();
if (curwin->w_cursor.col > 2
&& p[curwin->w_cursor.col - 1] == ':'
&& p[curwin->w_cursor.col - 2] == ':') {
@@ -3112,7 +3112,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty)
const bool i = cin_iscase((char_u *)p, false)
|| cin_isscopedecl((char_u *)p)
|| cin_islabel();
- p = (uint8_t *)get_cursor_line_ptr();
+ p = get_cursor_line_ptr();
p[curwin->w_cursor.col - 1] = ':';
if (i) {
return true;
@@ -3151,22 +3151,22 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty)
} else {
icase = false;
}
- p = (uint8_t *)vim_strchr((char *)look, ',');
+ p = vim_strchr(look, ',');
if (p == NULL) {
- p = look + strlen((char *)look);
+ p = look + strlen(look);
}
if ((try_match || try_match_word)
&& curwin->w_cursor.col >= (colnr_T)(p - look)) {
bool match = false;
if (keytyped == KEY_COMPLETE) {
- uint8_t *n, *s;
+ char *n, *s;
// Just completed a word, check if it starts with "look".
// search back for the start of a word.
- line = (uint8_t *)get_cursor_line_ptr();
+ line = get_cursor_line_ptr();
for (s = line + curwin->w_cursor.col; s > line; s = n) {
- n = mb_prevptr((char_u *)line, (char_u *)s);
+ n = (char *)mb_prevptr((char_u *)line, (char_u *)s);
if (!vim_iswordp((char_u *)n)) {
break;
}
@@ -3174,22 +3174,22 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty)
assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX);
if (s + (p - look) <= line + curwin->w_cursor.col
&& (icase
- ? mb_strnicmp((char *)s, (char *)look, (size_t)(p - look))
- : STRNCMP(s, look, p - look)) == 0) {
+ ? mb_strnicmp(s, look, (size_t)(p - look))
+ : strncmp(s, look, (size_t)(p - look))) == 0) {
match = true;
}
} else {
// TODO(@brammool): multi-byte
- if (keytyped == (int)p[-1]
+ if (keytyped == (int)(uint8_t)p[-1]
|| (icase && keytyped < 256
&& TOLOWER_LOC(keytyped) == TOLOWER_LOC((int)p[-1]))) {
- line = (uint8_t *)get_cursor_pos_ptr();
+ line = get_cursor_pos_ptr();
assert(p >= look && (uintmax_t)(p - look) <= SIZE_MAX);
if ((curwin->w_cursor.col == (colnr_T)(p - look)
- || !vim_iswordc(line[-(p - look) - 1]))
+ || !vim_iswordc((uint8_t)line[-(p - look) - 1]))
&& (icase
- ? mb_strnicmp((char *)line - (p - look), (char *)look, (size_t)(p - look))
- : STRNCMP(line - (p - look), look, p - look)) == 0) {
+ ? mb_strnicmp(line - (p - look), look, (size_t)(p - look))
+ : strncmp(line - (p - look), look, (size_t)(p - look))) == 0) {
match = true;
}
}
@@ -3210,7 +3210,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty)
// Ok, it's a boring generic character.
} else {
- if (try_match && *look == keytyped) {
+ if (try_match && (uint8_t)(*look) == keytyped) {
return true;
}
if (*look != NUL) {
@@ -3219,7 +3219,7 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty)
}
// Skip over ", ".
- look = (uint8_t *)skip_to_option_part((char *)look);
+ look = skip_to_option_part(look);
}
return false;
}
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 8734700305..d9081680ae 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -3838,7 +3838,7 @@ static int get_string_tv(char **arg, typval_T *rettv, int evaluate)
if (p[1] != '*') {
flags |= FSK_SIMPLIFY;
}
- extra = trans_special((const char_u **)&p, strlen(p), (char_u *)name, flags, false, NULL);
+ extra = trans_special((const char **)&p, strlen(p), (char_u *)name, flags, false, NULL);
if (extra != 0) {
name += extra;
if (name >= rettv->vval.v_string + len) {
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index a37613dca9..69b074ab99 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -1297,7 +1297,7 @@ void free_all_functions(void)
ufunc_T *fp;
uint64_t skipped = 0;
uint64_t todo = 1;
- uint64_t used;
+ int changed;
// Clean up the current_funccal chain and the funccal stack.
while (current_funccal != NULL) {
@@ -1321,9 +1321,9 @@ void free_all_functions(void)
if (func_name_refcount((char_u *)fp->uf_name)) {
skipped++;
} else {
- used = func_hashtab.ht_used;
+ changed = func_hashtab.ht_changed;
func_clear(fp, true);
- if (used != func_hashtab.ht_used) {
+ if (changed != func_hashtab.ht_changed) {
skipped = 0;
break;
}
@@ -1993,8 +1993,8 @@ char *save_function_name(char **name, bool skip, int flags, funcdict_T *fudi)
/// Otherwise functions matching "regmatch".
static void list_functions(regmatch_T *regmatch)
{
- const size_t used = func_hashtab.ht_used;
- size_t todo = used;
+ const int changed = func_hashtab.ht_changed;
+ size_t todo = func_hashtab.ht_used;
const hashitem_T *const ht_array = func_hashtab.ht_array;
for (const hashitem_T *hi = ht_array; todo > 0 && !got_int; hi++) {
@@ -2008,7 +2008,7 @@ static void list_functions(regmatch_T *regmatch)
: (!isdigit(*fp->uf_name)
&& vim_regexec(regmatch, (char *)fp->uf_name, 0)))) {
list_func_head(fp, false, false);
- if (used != func_hashtab.ht_used || ht_array != func_hashtab.ht_array) {
+ if (changed != func_hashtab.ht_changed) {
emsg(_("E454: function list was modified"));
return;
}
@@ -2730,15 +2730,17 @@ bool function_exists(const char *const name, bool no_deref)
char *get_user_func_name(expand_T *xp, int idx)
{
static size_t done;
+ static int changed;
static hashitem_T *hi;
ufunc_T *fp;
if (idx == 0) {
done = 0;
hi = func_hashtab.ht_array;
+ changed = func_hashtab.ht_changed;
}
assert(hi);
- if (done < func_hashtab.ht_used) {
+ if (changed == func_hashtab.ht_changed && done < func_hashtab.ht_used) {
if (done++ > 0) {
hi++;
}
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 78d0888e27..5eb5359e90 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -1367,12 +1367,13 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp)
{
bool is_fish_shell =
#if defined(UNIX)
- STRNCMP(invocation_path_tail((char_u *)p_sh, NULL), "fish", 4) == 0;
+ strncmp((char *)invocation_path_tail((char_u *)p_sh, NULL), "fish", 4) == 0;
#else
false;
#endif
- bool is_pwsh = STRNCMP(invocation_path_tail((char_u *)p_sh, NULL), "pwsh", 4) == 0
- || STRNCMP(invocation_path_tail((char_u *)p_sh, NULL), "powershell", 10) == 0;
+ bool is_pwsh = strncmp((char *)invocation_path_tail((char_u *)p_sh, NULL), "pwsh", 4) == 0
+ || strncmp((char *)invocation_path_tail((char_u *)p_sh, NULL), "powershell",
+ 10) == 0;
size_t len = strlen(cmd) + 1; // At least enough space for cmd + NULL.
@@ -1502,7 +1503,7 @@ void print_line(linenr_T lnum, int use_number, int list)
msg_start();
silent_mode = false;
- info_message = true; // use mch_msg(), not mch_errmsg()
+ info_message = true; // use os_msg(), not os_errmsg()
print_line_no_prefix(lnum, use_number, list);
if (save_silent) {
msg_putchar('\n');
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 88ae0a8226..b99df64a3d 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -4391,14 +4391,14 @@ static int check_more(int message, bool forceit)
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);
+ "%d more files to edit. Quit anyway?", n), n);
if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 1) == VIM_YES) {
return OK;
}
return FAIL;
}
semsg(NGETTEXT("E173: %" PRId64 " more file to edit",
- "E173: %" PRId64 " more files to edit", (unsigned long)n), (int64_t)n);
+ "E173: %" PRId64 " more files to edit", n), (int64_t)n);
quitmore = 2; // next try to quit is allowed
}
return FAIL;
@@ -6631,7 +6631,7 @@ enum {
/// Check "str" for starting with a special cmdline variable.
/// If found return one of the SPEC_ values and set "*usedlen" to the length of
/// the variable. Otherwise return -1 and "*usedlen" is unchanged.
-ssize_t find_cmdline_var(const char_u *src, size_t *usedlen)
+ssize_t find_cmdline_var(const char *src, size_t *usedlen)
FUNC_ATTR_NONNULL_ALL
{
static char *(spec_str[]) = {
@@ -6655,7 +6655,7 @@ ssize_t find_cmdline_var(const char_u *src, size_t *usedlen)
for (size_t i = 0; i < ARRAY_SIZE(spec_str); i++) {
size_t len = strlen(spec_str[i]);
- if (STRNCMP(src, spec_str[i], len) == 0) {
+ if (strncmp(src, spec_str[i], len) == 0) {
*usedlen = len;
assert(i <= SSIZE_MAX);
return (ssize_t)i;
@@ -6711,7 +6711,7 @@ char_u *eval_vars(char_u *src, const char_u *srcstart, size_t *usedlen, linenr_T
}
// Check if there is something to do.
- ssize_t spec_idx = find_cmdline_var(src, usedlen);
+ ssize_t spec_idx = find_cmdline_var((char *)src, usedlen);
if (spec_idx < 0) { // no match
*usedlen = 1;
return NULL;
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index bd77df1704..97f4c6261b 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -3929,7 +3929,7 @@ static int ccheck_abbr(int c)
spos = 0;
}
- return check_abbr(c, (char_u *)ccline.cmdbuff, ccline.cmdpos, spos);
+ return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos);
}
/// Escape special characters in "fname", depending on "what":
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index eaaed8b25c..fdf1973719 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -2560,7 +2560,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en
#ifdef HAVE_ACL
// For systems that support ACL: get the ACL from the original file.
if (!newfile) {
- acl = mch_get_acl((char_u *)fname);
+ acl = os_get_acl((char_u *)fname);
}
#endif
@@ -2800,7 +2800,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en
(double)file_info_old.stat.st_mtim.tv_sec);
#endif
#ifdef HAVE_ACL
- mch_set_acl((char_u *)backup, acl);
+ os_set_acl((char_u *)backup, acl);
#endif
SET_ERRMSG(NULL);
break;
@@ -3336,7 +3336,7 @@ restore_backup:
// Probably need to set the ACL before changing the user (can't set the
// ACL on a file the user doesn't own).
if (!backup_copy) {
- mch_set_acl((char_u *)wfname, acl);
+ os_set_acl((char_u *)wfname, acl);
}
#endif
@@ -3552,7 +3552,7 @@ nofail:
}
#endif
#ifdef HAVE_ACL
- mch_free_acl(acl);
+ os_free_acl(acl);
#endif
if (errmsg != NULL) {
@@ -4591,12 +4591,12 @@ int vim_rename(const char *from, const char *to)
perm = os_getperm(from);
#ifdef HAVE_ACL
// For systems that support ACL: get the ACL from the original file.
- acl = mch_get_acl((char_u *)from);
+ acl = os_get_acl((char_u *)from);
#endif
fd_in = os_open((char *)from, O_RDONLY, 0);
if (fd_in < 0) {
#ifdef HAVE_ACL
- mch_free_acl(acl);
+ os_free_acl(acl);
#endif
return -1;
}
@@ -4607,7 +4607,7 @@ int vim_rename(const char *from, const char *to)
if (fd_out < 0) {
close(fd_in);
#ifdef HAVE_ACL
- mch_free_acl(acl);
+ os_free_acl(acl);
#endif
return -1;
}
@@ -4619,7 +4619,7 @@ int vim_rename(const char *from, const char *to)
close(fd_out);
close(fd_in);
#ifdef HAVE_ACL
- mch_free_acl(acl);
+ os_free_acl(acl);
#endif
return -1;
}
@@ -4644,8 +4644,8 @@ int vim_rename(const char *from, const char *to)
os_setperm((const char *)to, perm);
#endif
#ifdef HAVE_ACL
- mch_set_acl((char_u *)to, acl);
- mch_free_acl(acl);
+ os_set_acl((char_u *)to, acl);
+ os_free_acl(acl);
#endif
if (errmsg != NULL) {
semsg(errmsg, to);
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index 08b963ae89..275ddc6912 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -1781,7 +1781,7 @@ char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo
}
}
if (text == NULL) {
- unsigned long count = (unsigned long)(lnume - lnum + 1); // NOLINT(bugprone-misplaced-widening-cast)
+ long count = lnume - lnum + 1;
vim_snprintf(buf, FOLD_TEXT_LEN,
NGETTEXT("+--%3ld line folded",
@@ -3269,7 +3269,7 @@ void f_foldtext(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
}
}
- int count = foldend - foldstart + 1;
+ long count = foldend - foldstart + 1;
char *txt = NGETTEXT("+-%s%3ld line: ", "+-%s%3ld lines: ", count);
size_t len = strlen(txt)
+ strlen(dashes) // for %s
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index fa4d2942f6..db4d640f46 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -1968,7 +1968,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
// Only consider an entry if the first character matches and it is
// for the current state.
// Skip ":lmap" mappings if keys were mapped.
- if (mp->m_keys[0] == tb_c1 && (mp->m_mode & local_State)
+ if ((uint8_t)mp->m_keys[0] == tb_c1 && (mp->m_mode & local_State)
&& ((mp->m_mode & MODE_LANGMAP) == 0 || typebuf.tb_maplen == 0)) {
int nomap = nolmaplen;
int modifiers = 0;
@@ -1994,7 +1994,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
}
modifiers = 0;
}
- if (mp->m_keys[mlen] != c2) {
+ if ((uint8_t)mp->m_keys[mlen] != c2) {
break;
}
}
@@ -2002,7 +2002,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
// Don't allow mapping the first byte(s) of a multi-byte char.
// Happens when mapping <M-a> and then changing 'encoding'.
// Beware that 0x80 is escaped.
- char_u *p1 = mp->m_keys;
+ char_u *p1 = (char_u *)mp->m_keys;
char_u *p2 = (char_u *)mb_unescape((const char **)&p1);
if (p2 != NULL && MB_BYTE2LEN(tb_c1) > utfc_ptr2len((char *)p2)) {
@@ -2020,8 +2020,8 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
// mapping starts with K_SNR.
uint8_t *s = typebuf.tb_noremap + typebuf.tb_off;
if (*s == RM_SCRIPT
- && (mp->m_keys[0] != K_SPECIAL
- || mp->m_keys[1] != KS_EXTRA
+ && ((uint8_t)mp->m_keys[0] != K_SPECIAL
+ || (uint8_t)mp->m_keys[1] != KS_EXTRA
|| mp->m_keys[2] != KE_SNR)) {
continue;
}
@@ -2212,7 +2212,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
vgetc_busy = 0;
may_garbage_collect = false;
- save_m_keys = xstrdup((char *)mp->m_keys);
+ save_m_keys = xstrdup(mp->m_keys);
if (save_m_luaref == LUA_NOREF) {
save_m_str = xstrdup(mp->m_str);
}
@@ -2266,7 +2266,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
if (save_m_noremap != REMAP_YES) {
noremap = save_m_noremap;
- } else if (strncmp(map_str, save_m_keys != NULL ? save_m_keys : (char *)mp->m_keys,
+ } else if (strncmp(map_str, save_m_keys != NULL ? save_m_keys : mp->m_keys,
(size_t)keylen) != 0) {
noremap = REMAP_YES;
} else {
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 0169b62188..bce81b376b 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -75,6 +75,10 @@
# define VIMRC_FILE ".nvimrc"
#endif
+#ifndef VIMRC_LUA_FILE
+# define VIMRC_LUA_FILE ".nvim.lua"
+#endif
+
EXTERN struct nvim_stats_s {
int64_t fsync;
int64_t redraw;
diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c
index 3e43eca92c..0240761483 100644
--- a/src/nvim/hardcopy.c
+++ b/src/nvim/hardcopy.c
@@ -232,7 +232,7 @@ struct prt_ps_resource_S {
char_u filename[MAXPATHL + 1];
PrtResourceType type;
char_u title[256];
- char_u version[256];
+ char version[256];
};
struct prt_dsc_comment_S {
@@ -243,7 +243,7 @@ struct prt_dsc_comment_S {
struct prt_dsc_line_S {
int type;
- char_u *string;
+ char *string;
int len;
};
@@ -251,7 +251,7 @@ struct prt_dsc_line_S {
// couple of KB of comments!
#define PRT_FILE_BUFFER_LEN (2048)
struct prt_resfile_buffer_S {
- char_u buffer[PRT_FILE_BUFFER_LEN];
+ char buffer[PRT_FILE_BUFFER_LEN];
int len;
int line_start;
int line_end;
@@ -1550,8 +1550,8 @@ static int prt_resfile_strncmp(int offset, const char *string, int len)
if (len > (prt_resfile.line_end - (prt_resfile.line_start + offset))) {
return 1;
}
- return STRNCMP(&prt_resfile.buffer[prt_resfile.line_start + offset],
- string, len);
+ return strncmp(&prt_resfile.buffer[prt_resfile.line_start + offset],
+ string, (size_t)len);
}
static int prt_resfile_skip_nonws(int offset)
@@ -1751,7 +1751,7 @@ static bool prt_check_resource(const struct prt_ps_resource_S *resource, const c
FUNC_ATTR_NONNULL_ALL
{
// Version number m.n should match, the revision number does not matter
- if (STRNCMP(resource->version, version, strlen(version)) != 0) {
+ if (strncmp(resource->version, version, strlen(version)) != 0) {
semsg(_("E621: \"%s\" resource file has wrong version"),
resource->name);
return false;
diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c
index 31dc6f5bd4..fdbfdd7d77 100644
--- a/src/nvim/hashtab.c
+++ b/src/nvim/hashtab.c
@@ -223,6 +223,7 @@ int hash_add(hashtab_T *ht, char *key)
void hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash)
{
ht->ht_used++;
+ ht->ht_changed++;
if (hi->hi_key == NULL) {
ht->ht_filled++;
}
@@ -242,6 +243,7 @@ void hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash)
void hash_remove(hashtab_T *ht, hashitem_T *hi)
{
ht->ht_used--;
+ ht->ht_changed++;
hi->hi_key = HI_KEY_REMOVED;
hash_may_resize(ht, 0);
}
@@ -384,6 +386,7 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems)
ht->ht_array = newarray;
ht->ht_mask = newmask;
ht->ht_filled = ht->ht_used;
+ ht->ht_changed++;
}
#define HASH_CYCLE_BODY(hash, p) \
diff --git a/src/nvim/hashtab.h b/src/nvim/hashtab.h
index 28a3b69d44..0a50fb2ef8 100644
--- a/src/nvim/hashtab.h
+++ b/src/nvim/hashtab.h
@@ -61,14 +61,15 @@ typedef struct hashitem_S {
///
/// The hashtable grows to accommodate more entries when needed.
typedef struct hashtable_S {
- hash_T ht_mask; /// mask used for hash value
- /// (nr of items in array is "ht_mask" + 1)
- size_t ht_used; /// number of items used
- size_t ht_filled; /// number of items used or removed
- int ht_locked; /// counter for hash_lock()
- hashitem_T *ht_array; /// points to the array, allocated when it's
- /// not "ht_smallarray"
- hashitem_T ht_smallarray[HT_INIT_SIZE]; /// initial array
+ hash_T ht_mask; ///< mask used for hash value
+ ///< (nr of items in array is "ht_mask" + 1)
+ size_t ht_used; ///< number of items used
+ size_t ht_filled; ///< number of items used or removed
+ int ht_changed; ///< incremented when adding or removing an item
+ int ht_locked; ///< counter for hash_lock()
+ hashitem_T *ht_array; ///< points to the array, allocated when it's
+ ///< not "ht_smallarray"
+ hashitem_T ht_smallarray[HT_INIT_SIZE]; ///< initial array
} hashtab_T;
/// Iterate over a hashtab
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index 2777ebd18c..7d3b1f4a3f 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -378,7 +378,7 @@ int get_indent_lnum(linenr_T lnum)
int get_indent_buf(buf_T *buf, linenr_T lnum)
{
return get_indent_str_vtab(ml_get_buf(buf, lnum, false),
- curbuf->b_p_ts,
+ buf->b_p_ts,
buf->b_p_vts_array,
false);
}
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index 18f301f96e..ca08f67e32 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -131,7 +131,7 @@ static pos_T *find_start_rawstring(int ind_maxcomment) // XXX
// Skip to the end of a "string" and a 'c' character.
// If there is no string or character, return argument unmodified.
-static const char_u *skip_string(const char_u *p)
+static const char *skip_string(const char *p)
{
int i;
@@ -172,7 +172,7 @@ static const char_u *skip_string(const char_u *p)
const ptrdiff_t delim_len = paren - delim;
for (p += 3; *p; p++) {
- if (p[0] == ')' && STRNCMP(p + 1, delim, delim_len) == 0
+ if (p[0] == ')' && strncmp(p + 1, delim, (size_t)delim_len) == 0
&& p[delim_len + 1] == '"') {
p += delim_len + 1;
break;
@@ -197,7 +197,7 @@ int is_pos_in_string(const char_u *line, colnr_T col)
const char_u *p;
for (p = line; *p && (colnr_T)(p - line) < col; p++) {
- p = skip_string(p);
+ p = (char_u *)skip_string((char *)p);
}
return !((colnr_T)(p - line) <= col);
}
@@ -213,12 +213,12 @@ bool cin_is_cinword(const char *line)
bool retval = false;
size_t cinw_len = strlen(curbuf->b_p_cinw) + 1;
- char_u *cinw_buf = xmalloc(cinw_len);
+ char *cinw_buf = xmalloc(cinw_len);
line = skipwhite((char *)line);
for (char *cinw = curbuf->b_p_cinw; *cinw;) {
- size_t len = copy_option_part(&cinw, (char *)cinw_buf, cinw_len, ",");
- if (STRNCMP(line, cinw_buf, len) == 0
+ size_t len = copy_option_part(&cinw, cinw_buf, cinw_len, ",");
+ if (strncmp(line, cinw_buf, len) == 0
&& (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1]))) {
retval = true;
break;
@@ -350,7 +350,7 @@ bool cin_islabel(void) // XXX
// Exclude "default" from labels, since it should be indented
// like a switch label. Same for C++ scope declarations.
- if (cin_isdefault(s)) {
+ if (cin_isdefault((char *)s)) {
return false;
}
if (cin_isscopedecl(s)) {
@@ -408,7 +408,7 @@ static int cin_isinit(void)
s = cin_skipcomment((char_u *)get_cursor_line_ptr());
- if (cin_starts_with(s, "typedef")) {
+ if (cin_starts_with((char *)s, "typedef")) {
s = cin_skipcomment(s + 7);
}
@@ -417,7 +417,7 @@ static int cin_isinit(void)
for (i = 0; i < (int)ARRAY_SIZE(skip); i++) {
l = (int)strlen(skip[i]);
- if (cin_starts_with(s, skip[i])) {
+ if (cin_starts_with((char *)s, skip[i])) {
s = cin_skipcomment(s + l);
l = 0;
break;
@@ -428,11 +428,11 @@ static int cin_isinit(void)
}
}
- if (cin_starts_with(s, "enum")) {
+ if (cin_starts_with((char *)s, "enum")) {
return true;
}
- if (cin_ends_in(s, (char_u *)"=", (char_u *)"{")) {
+ if (cin_ends_in((char *)s, "=", "{")) {
return true;
}
@@ -445,7 +445,7 @@ static int cin_isinit(void)
bool cin_iscase(const char_u *s, bool strict)
{
s = cin_skipcomment(s);
- if (cin_starts_with(s, "case")) {
+ if (cin_starts_with((char *)s, "case")) {
for (s += 4; *s; s++) {
s = cin_skipcomment(s);
if (*s == NUL) {
@@ -473,34 +473,34 @@ bool cin_iscase(const char_u *s, bool strict)
return false;
}
- if (cin_isdefault(s)) {
+ if (cin_isdefault((char *)s)) {
return true;
}
return false;
}
// Recognize a "default" switch label.
-static int cin_isdefault(const char_u *s)
+static int cin_isdefault(const char *s)
{
- return STRNCMP(s, "default", 7) == 0
- && *(s = cin_skipcomment(s + 7)) == ':'
+ return strncmp(s, "default", 7) == 0
+ && *(s = (char *)cin_skipcomment((char_u *)s + 7)) == ':'
&& s[1] != ':';
}
/// Recognize a scope declaration label set in 'cinscopedecls'.
bool cin_isscopedecl(const char_u *p)
{
- const char_u *s = cin_skipcomment(p);
+ const char *s = (char *)cin_skipcomment(p);
const size_t cinsd_len = strlen(curbuf->b_p_cinsd) + 1;
- char_u *cinsd_buf = xmalloc(cinsd_len);
+ char *cinsd_buf = xmalloc(cinsd_len);
bool found = false;
for (char *cinsd = curbuf->b_p_cinsd; *cinsd;) {
- const size_t len = copy_option_part(&cinsd, (char *)cinsd_buf, cinsd_len, ",");
- if (STRNCMP(s, cinsd_buf, len) == 0) {
- const char_u *skip = cin_skipcomment(s + len);
+ const size_t len = copy_option_part(&cinsd, cinsd_buf, cinsd_len, ",");
+ if (strncmp(s, cinsd_buf, len) == 0) {
+ const char_u *skip = cin_skipcomment((char_u *)s + len);
if (*skip == ':' && skip[1] != ':') {
found = true;
break;
@@ -517,19 +517,19 @@ bool cin_isscopedecl(const char_u *p)
#define FIND_NAMESPACE_LIM 20
// Recognize a "namespace" scope declaration.
-static bool cin_is_cpp_namespace(const char_u *s)
+static bool cin_is_cpp_namespace(const char *s)
{
const char_u *p;
bool has_name = false;
bool has_name_start = false;
- s = cin_skipcomment(s);
+ s = (char *)cin_skipcomment((char_u *)s);
- if (STRNCMP(s, "inline", 6) == 0 && (s[6] == NUL || !vim_iswordc(s[6]))) {
- s = cin_skipcomment((char_u *)skipwhite((char *)s + 6));
+ if (strncmp(s, "inline", 6) == 0 && (s[6] == NUL || !vim_iswordc((uint8_t)s[6]))) {
+ s = (char *)cin_skipcomment((char_u *)skipwhite((char *)s + 6));
}
- if (STRNCMP(s, "namespace", 9) == 0 && (s[9] == NUL || !vim_iswordc(s[9]))) {
+ if (strncmp(s, "namespace", 9) == 0 && (s[9] == NUL || !vim_iswordc((uint8_t)s[9]))) {
p = cin_skipcomment((char_u *)skipwhite((char *)s + 9));
while (*p != NUL) {
if (ascii_iswhite(*p)) {
@@ -610,25 +610,25 @@ static int get_indent_nolabel(linenr_T lnum) // XXX
// Also return a pointer to the text (after the label) in "pp".
// label: if (asdf && asdfasdf)
// ^
-static int skip_label(linenr_T lnum, const char_u **pp)
+static int skip_label(linenr_T lnum, const char **pp)
{
- const char_u *l;
+ const char *l;
int amount;
pos_T cursor_save;
cursor_save = curwin->w_cursor;
curwin->w_cursor.lnum = lnum;
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
// XXX
- if (cin_iscase(l, false) || cin_isscopedecl(l) || cin_islabel()) {
+ if (cin_iscase((char_u *)l, false) || cin_isscopedecl((char_u *)l) || cin_islabel()) {
amount = get_indent_nolabel(lnum);
- l = after_label((char_u *)get_cursor_line_ptr());
+ l = (char *)after_label((char_u *)get_cursor_line_ptr());
if (l == NULL) { // just in case
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
}
} else {
amount = get_indent();
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
}
*pp = l;
@@ -643,38 +643,38 @@ static int skip_label(linenr_T lnum, const char_u **pp)
// Returns zero when it doesn't look like a declaration.
static int cin_first_id_amount(void)
{
- char_u *line, *p, *s;
+ char *line, *p, *s;
int len;
pos_T fp;
colnr_T col;
- line = (char_u *)get_cursor_line_ptr();
- p = (char_u *)skipwhite((char *)line);
- len = (int)((char_u *)skiptowhite((char *)p) - p);
- if (len == 6 && STRNCMP(p, "static", 6) == 0) {
- p = (char_u *)skipwhite((char *)p + 6);
- len = (int)((char_u *)skiptowhite((char *)p) - p);
- }
- if (len == 6 && STRNCMP(p, "struct", 6) == 0) {
- p = (char_u *)skipwhite((char *)p + 6);
- } else if (len == 4 && STRNCMP(p, "enum", 4) == 0) {
- p = (char_u *)skipwhite((char *)p + 4);
- } else if ((len == 8 && STRNCMP(p, "unsigned", 8) == 0)
- || (len == 6 && STRNCMP(p, "signed", 6) == 0)) {
- s = (char_u *)skipwhite((char *)p + len);
- if ((STRNCMP(s, "int", 3) == 0 && ascii_iswhite(s[3]))
- || (STRNCMP(s, "long", 4) == 0 && ascii_iswhite(s[4]))
- || (STRNCMP(s, "short", 5) == 0 && ascii_iswhite(s[5]))
- || (STRNCMP(s, "char", 4) == 0 && ascii_iswhite(s[4]))) {
+ line = get_cursor_line_ptr();
+ p = skipwhite(line);
+ len = (int)(skiptowhite(p) - p);
+ if (len == 6 && strncmp(p, "static", 6) == 0) {
+ p = skipwhite(p + 6);
+ len = (int)(skiptowhite(p) - p);
+ }
+ if (len == 6 && strncmp(p, "struct", 6) == 0) {
+ p = skipwhite(p + 6);
+ } else if (len == 4 && strncmp(p, "enum", 4) == 0) {
+ p = skipwhite(p + 4);
+ } else if ((len == 8 && strncmp(p, "unsigned", 8) == 0)
+ || (len == 6 && strncmp(p, "signed", 6) == 0)) {
+ s = skipwhite(p + len);
+ if ((strncmp(s, "int", 3) == 0 && ascii_iswhite(s[3]))
+ || (strncmp(s, "long", 4) == 0 && ascii_iswhite(s[4]))
+ || (strncmp(s, "short", 5) == 0 && ascii_iswhite(s[5]))
+ || (strncmp(s, "char", 4) == 0 && ascii_iswhite(s[4]))) {
p = s;
}
}
for (len = 0; vim_isIDc(p[len]); len++) {}
- if (len == 0 || !ascii_iswhite(p[len]) || cin_nocode(p)) {
+ if (len == 0 || !ascii_iswhite(p[len]) || cin_nocode((char_u *)p)) {
return 0;
}
- p = (char_u *)skipwhite((char *)p + len);
+ p = skipwhite(p + len);
fp.lnum = curwin->w_cursor.lnum;
fp.col = (colnr_T)(p - line);
getvcol(curwin, &fp, &col, NULL, NULL);
@@ -743,9 +743,9 @@ static int cin_ispreproc(const char_u *s)
/// continuation line of a preprocessor statement. Decrease "*lnump" to the
/// start and return the line in "*pp".
/// Put the amount of indent in "*amount".
-static int cin_ispreproc_cont(const char_u **pp, linenr_T *lnump, int *amount)
+static int cin_ispreproc_cont(const char **pp, linenr_T *lnump, int *amount)
{
- const char_u *line = *pp;
+ const char_u *line = (char_u *)(*pp);
linenr_T lnum = *lnump;
int retval = false;
int candidate_amount = *amount;
@@ -770,7 +770,7 @@ static int cin_ispreproc_cont(const char_u **pp, linenr_T *lnump, int *amount)
}
if (lnum != *lnump) {
- *pp = (char_u *)ml_get(*lnump);
+ *pp = ml_get(*lnump);
}
if (retval) {
*amount = candidate_amount;
@@ -809,17 +809,17 @@ static char_u cin_isterminated(const char_u *s, int incl_open, int incl_comma)
s = cin_skipcomment(s);
- if (*s == '{' || (*s == '}' && !cin_iselse(s))) {
+ if (*s == '{' || (*s == '}' && !cin_iselse((char *)s))) {
found_start = *s;
}
if (!found_start) {
- is_else = cin_iselse(s);
+ is_else = cin_iselse((char *)s);
}
while (*s) {
// skip over comments, "" strings and 'c'haracters
- s = skip_string(cin_skipcomment(s));
+ s = (char_u *)skip_string((char *)cin_skipcomment(s));
if (*s == '}' && n_open > 0) {
n_open--;
}
@@ -852,7 +852,7 @@ static char_u cin_isterminated(const char_u *s, int incl_open, int incl_comma)
/// lines here.
/// @param[in] first_lnum Where to start looking.
/// @param[in] min_lnum The line before which we will not be looking.
-static int cin_isfuncdecl(const char_u **sp, linenr_T first_lnum, linenr_T min_lnum)
+static int cin_isfuncdecl(const char **sp, linenr_T first_lnum, linenr_T min_lnum)
{
const char_u *s;
linenr_T lnum = first_lnum;
@@ -864,7 +864,7 @@ static int cin_isfuncdecl(const char_u **sp, linenr_T first_lnum, linenr_T min_l
if (sp == NULL) {
s = (char_u *)ml_get(lnum);
} else {
- s = *sp;
+ s = (char_u *)(*sp);
}
curwin->w_cursor.lnum = lnum;
@@ -956,28 +956,28 @@ static int cin_isfuncdecl(const char_u **sp, linenr_T first_lnum, linenr_T min_l
done:
if (lnum != first_lnum && sp != NULL) {
- *sp = (char_u *)ml_get(first_lnum);
+ *sp = ml_get(first_lnum);
}
return retval;
}
-static int cin_isif(const char_u *p)
+static int cin_isif(const char *p)
{
- return STRNCMP(p, "if", 2) == 0 && !vim_isIDc(p[2]);
+ return strncmp(p, "if", 2) == 0 && !vim_isIDc((uint8_t)p[2]);
}
-static int cin_iselse(const char_u *p)
+static int cin_iselse(const char *p)
{
if (*p == '}') { // accept "} else"
- p = cin_skipcomment(p + 1);
+ p = (char *)cin_skipcomment((char_u *)p + 1);
}
- return STRNCMP(p, "else", 4) == 0 && !vim_isIDc(p[4]);
+ return strncmp(p, "else", 4) == 0 && !vim_isIDc((uint8_t)p[4]);
}
-static int cin_isdo(const char_u *p)
+static int cin_isdo(const char *p)
{
- return STRNCMP(p, "do", 2) == 0 && !vim_isIDc(p[2]);
+ return strncmp(p, "do", 2) == 0 && !vim_isIDc((uint8_t)p[2]);
}
// Check if this is a "while" that should have a matching "do".
@@ -993,7 +993,7 @@ static int cin_iswhileofdo(const char_u *p, linenr_T lnum) // XXX
if (*p == '}') { // accept "} while (cond);"
p = cin_skipcomment(p + 1);
}
- if (cin_starts_with(p, "while")) {
+ if (cin_starts_with((char *)p, "while")) {
cursor_save = curwin->w_cursor;
curwin->w_cursor.lnum = lnum;
curwin->w_cursor.col = 0;
@@ -1015,7 +1015,7 @@ static int cin_iswhileofdo(const char_u *p, linenr_T lnum) // XXX
// Return 0 if there is none.
// Otherwise return !0 and update "*poffset" to point to the place where the
// string was found.
-static int cin_is_if_for_while_before_offset(const char_u *line, int *poffset)
+static int cin_is_if_for_while_before_offset(const char *line, int *poffset)
{
int offset = *poffset;
@@ -1027,19 +1027,19 @@ static int cin_is_if_for_while_before_offset(const char_u *line, int *poffset)
}
offset -= 1;
- if (!STRNCMP(line + offset, "if", 2)) {
+ if (!strncmp(line + offset, "if", 2)) {
goto probablyFound;
}
if (offset >= 1) {
offset -= 1;
- if (!STRNCMP(line + offset, "for", 3)) {
+ if (!strncmp(line + offset, "for", 3)) {
goto probablyFound;
}
if (offset >= 2) {
offset -= 2;
- if (!STRNCMP(line + offset, "while", 5)) {
+ if (!strncmp(line + offset, "while", 5)) {
goto probablyFound;
}
}
@@ -1047,7 +1047,7 @@ static int cin_is_if_for_while_before_offset(const char_u *line, int *poffset)
return 0;
probablyFound:
- if (!offset || !vim_isIDc(line[offset - 1])) {
+ if (!offset || !vim_isIDc((uint8_t)line[offset - 1])) {
*poffset = offset;
return 1;
}
@@ -1088,7 +1088,7 @@ static int cin_iswhileofdo_end(int terminated)
if (*s == '}') { // accept "} while (cond);"
s = cin_skipcomment(s + 1);
}
- if (cin_starts_with(s, "while")) {
+ if (cin_starts_with((char *)s, "while")) {
curwin->w_cursor.lnum = trypos->lnum;
return true;
}
@@ -1106,9 +1106,9 @@ static int cin_iswhileofdo_end(int terminated)
return false;
}
-static int cin_isbreak(const char_u *p)
+static int cin_isbreak(const char *p)
{
- return STRNCMP(p, "break", 5) == 0 && !vim_isIDc(p[5]);
+ return strncmp(p, "break", 5) == 0 && !vim_isIDc((uint8_t)p[5]);
}
// Find the position of a C++ base-class declaration or
@@ -1125,10 +1125,10 @@ static int cin_isbreak(const char_u *p)
static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached)
{
lpos_T *pos = &cached->lpos; // find position
- const char_u *s;
+ const char *s;
int class_or_struct, lookfor_ctor_init, cpp_base_class;
linenr_T lnum = curwin->w_cursor.lnum;
- const char_u *line = (char_u *)get_cursor_line_ptr();
+ const char *line = get_cursor_line_ptr();
if (pos->lnum <= lnum) {
return cached->found; // Use the cached result
@@ -1136,11 +1136,11 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached)
pos->col = 0;
- s = (char_u *)skipwhite((char *)line);
+ s = skipwhite(line);
if (*s == '#') { // skip #define FOO x ? (x) : x
return false;
}
- s = cin_skipcomment(s);
+ s = (char *)cin_skipcomment((char_u *)s);
if (*s == NUL) {
return false;
}
@@ -1160,15 +1160,15 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached)
// somethingelse(3)
// {}
while (lnum > 1) {
- line = (char_u *)ml_get(lnum - 1);
- s = (char_u *)skipwhite((char *)line);
+ line = ml_get(lnum - 1);
+ s = skipwhite(line);
if (*s == '#' || *s == NUL) {
break;
}
while (*s != NUL) {
- s = cin_skipcomment(s);
+ s = (char *)cin_skipcomment((char_u *)s);
if (*s == '{' || *s == '}'
- || (*s == ';' && cin_nocode(s + 1))) {
+ || (*s == ';' && cin_nocode((char_u *)s + 1))) {
break;
}
if (*s != NUL) {
@@ -1182,7 +1182,7 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached)
}
pos->lnum = lnum;
- line = (char_u *)ml_get(lnum);
+ line = ml_get(lnum);
s = line;
for (;;) {
if (*s == NUL) {
@@ -1190,47 +1190,47 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached)
break;
}
// Continue in the cursor line.
- line = (char_u *)ml_get(++lnum);
+ line = ml_get(++lnum);
s = line;
}
if (s == line) {
// don't recognize "case (foo):" as a baseclass */
- if (cin_iscase(s, false)) {
+ if (cin_iscase((char_u *)s, false)) {
break;
}
- s = cin_skipcomment(line);
+ s = (char *)cin_skipcomment((char_u *)line);
if (*s == NUL) {
continue;
}
}
if (s[0] == '"' || (s[0] == 'R' && s[1] == '"')) {
- s = skip_string(s) + 1;
+ s = (char *)skip_string(s) + 1;
} else if (s[0] == ':') {
if (s[1] == ':') {
// skip double colon. It can't be a constructor
// initialization any more
lookfor_ctor_init = false;
- s = cin_skipcomment(s + 2);
+ s = (char *)cin_skipcomment((char_u *)s + 2);
} else if (lookfor_ctor_init || class_or_struct) {
// we have something found, that looks like the start of
// cpp-base-class-declaration or constructor-initialization
cpp_base_class = true;
lookfor_ctor_init = class_or_struct = false;
pos->col = 0;
- s = cin_skipcomment(s + 1);
+ s = (char *)cin_skipcomment((char_u *)s + 1);
} else {
- s = cin_skipcomment(s + 1);
+ s = (char *)cin_skipcomment((char_u *)s + 1);
}
- } else if ((STRNCMP(s, "class", 5) == 0 && !vim_isIDc(s[5]))
- || (STRNCMP(s, "struct", 6) == 0 && !vim_isIDc(s[6]))) {
+ } else if ((strncmp(s, "class", 5) == 0 && !vim_isIDc((uint8_t)s[5]))
+ || (strncmp(s, "struct", 6) == 0 && !vim_isIDc((uint8_t)s[6]))) {
class_or_struct = true;
lookfor_ctor_init = false;
if (*s == 'c') {
- s = cin_skipcomment(s + 5);
+ s = (char *)cin_skipcomment((char_u *)s + 5);
} else {
- s = cin_skipcomment(s + 6);
+ s = (char *)cin_skipcomment((char_u *)s + 6);
}
} else {
if (s[0] == '{' || s[0] == '}' || s[0] == ';') {
@@ -1243,7 +1243,7 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached)
} else if (s[0] == '?') {
// Avoid seeing '() :' after '?' as constructor init.
return false;
- } else if (!vim_isIDc(s[0])) {
+ } else if (!vim_isIDc((uint8_t)s[0])) {
// if it is not an identifier, we are wrong
class_or_struct = false;
lookfor_ctor_init = false;
@@ -1258,11 +1258,11 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached)
}
// When the line ends in a comma don't align with it.
- if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode(s + 1)) {
+ if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode((char_u *)s + 1)) {
pos->col = 0;
}
- s = cin_skipcomment(s + 1);
+ s = (char *)cin_skipcomment((char_u *)s + 1);
}
}
@@ -1285,7 +1285,7 @@ static int get_baseclass_amount(int col)
&& (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) {
amount = get_indent_lnum(trypos->lnum); // XXX
}
- if (!cin_ends_in((char_u *)get_cursor_line_ptr(), (char_u *)",", NULL)) {
+ if (!cin_ends_in(get_cursor_line_ptr(), ",", NULL)) {
amount += curbuf->b_ind_cpp_baseclass;
}
} else {
@@ -1302,20 +1302,20 @@ static int get_baseclass_amount(int col)
/// Return true if string "s" ends with the string "find", possibly followed by
/// white space and comments. Skip strings and comments.
/// Ignore "ignore" after "find" if it's not NULL.
-static int cin_ends_in(const char_u *s, const char_u *find, const char_u *ignore)
+static int cin_ends_in(const char *s, const char *find, const char *ignore)
{
- const char_u *p = s;
- const char_u *r;
+ const char *p = (char *)s;
+ const char *r;
int len = (int)strlen((char *)find);
while (*p != NUL) {
- p = cin_skipcomment(p);
- if (STRNCMP(p, find, len) == 0) {
- r = (char_u *)skipwhite((char *)p + len);
- if (ignore != NULL && STRNCMP(r, ignore, strlen((char *)ignore)) == 0) {
- r = (char_u *)skipwhite((char *)r + strlen((char *)ignore));
+ p = (char *)cin_skipcomment((char_u *)p);
+ if (strncmp(p, find, (size_t)len) == 0) {
+ r = skipwhite((char *)p + len);
+ if (ignore != NULL && strncmp(r, ignore, strlen((char *)ignore)) == 0) {
+ r = skipwhite((char *)r + strlen((char *)ignore));
}
- if (cin_nocode(r)) {
+ if (cin_nocode((char_u *)r)) {
return true;
}
}
@@ -1327,21 +1327,21 @@ static int cin_ends_in(const char_u *s, const char_u *find, const char_u *ignore
}
/// Return true when "s" starts with "word" and then a non-ID character.
-static int cin_starts_with(const char_u *s, const char *word)
+static int cin_starts_with(const char *s, const char *word)
{
- int l = (int)strlen(word);
+ size_t l = strlen(word);
- return STRNCMP(s, word, l) == 0 && !vim_isIDc(s[l]);
+ return strncmp(s, word, l) == 0 && !vim_isIDc((uint8_t)s[l]);
}
/// Recognize a `extern "C"` or `extern "C++"` linkage specifications.
-static int cin_is_cpp_extern_c(const char_u *s)
+static int cin_is_cpp_extern_c(const char *s)
{
const char_u *p;
int has_string_literal = false;
- s = cin_skipcomment(s);
- if (STRNCMP(s, "extern", 6) == 0 && (s[6] == NUL || !vim_iswordc(s[6]))) {
+ s = (char *)cin_skipcomment((char_u *)s);
+ if (strncmp(s, "extern", 6) == 0 && (s[6] == NUL || !vim_iswordc((uint8_t)s[6]))) {
p = cin_skipcomment((char_u *)skipwhite((char *)s + 6));
while (*p != NUL) {
if (ascii_iswhite(*p)) {
@@ -1384,7 +1384,7 @@ static int cin_skip2pos(pos_T *trypos)
if (cin_iscomment(p)) {
p = cin_skipcomment(p);
} else {
- new_p = skip_string(p);
+ new_p = (char_u *)skip_string((char *)p);
if (new_p == p) {
p++;
} else {
@@ -1524,7 +1524,7 @@ static int find_last_paren(const char_u *l, int start, int end)
for (i = 0; l[i] != NUL; i++) {
i = (int)(cin_skipcomment(l + i) - l); // ignore parens in comments
- i = (int)(skip_string(l + i) - l); // ignore parens in quotes
+ i = (int)(skip_string((char *)l + i) - (char *)l); // ignore parens in quotes
if (l[i] == start) {
open_count++;
} else if (l[i] == end) {
@@ -1844,7 +1844,7 @@ int get_c_indent(void)
int scope_amount;
int cur_amount = MAXCOL;
colnr_T col;
- char_u *theline;
+ char *theline;
char *linecopy;
pos_T *trypos;
pos_T *comment_pos;
@@ -1857,8 +1857,8 @@ int get_c_indent(void)
#define BRACE_AT_START 2 // '{' is at start of line
#define BRACE_AT_END 3 // '{' is at end of line
linenr_T ourscope;
- const char_u *l;
- const char_u *look;
+ const char *l;
+ const char *look;
char_u terminated;
int lookfor;
#define LOOKFOR_INITIAL 0
@@ -1913,7 +1913,7 @@ int get_c_indent(void)
linecopy[curwin->w_cursor.col] = NUL;
}
- theline = (char_u *)skipwhite(linecopy);
+ theline = skipwhite(linecopy);
// move the cursor to the start of the line
@@ -1938,8 +1938,8 @@ int get_c_indent(void)
// #defines and so on go at the left when included in 'cinkeys',
// excluding pragmas when customized in 'cinoptions'
if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', true))) {
- const char_u *const directive = (char_u *)skipwhite((char *)theline + 1);
- if (curbuf->b_ind_pragma == 0 || STRNCMP(directive, "pragma", 6) != 0) {
+ const char *const directive = skipwhite(theline + 1);
+ if (curbuf->b_ind_pragma == 0 || strncmp(directive, "pragma", 6) != 0) {
amount = curbuf->b_ind_hash_comment;
goto theend;
}
@@ -1954,7 +1954,7 @@ int get_c_indent(void)
}
// If we're inside a "//" comment and there is a "//" comment in a
// previous line, lineup with that one.
- if (cin_islinecomment(theline)) {
+ if (cin_islinecomment((char_u *)theline)) {
pos_T linecomment_pos;
trypos = find_line_comment(); // XXX
@@ -1976,7 +1976,7 @@ int get_c_indent(void)
}
// If we're inside a comment and not looking at the start of the
// comment, try using the 'comments' option.
- if (!cin_iscomment(theline) && comment_pos != NULL) { // XXX
+ if (!cin_iscomment((char_u *)theline) && comment_pos != NULL) { // XXX
int lead_start_len = 2;
int lead_middle_len = 1;
char lead_start[COM_MAX_LEN]; // start-comment string
@@ -2026,22 +2026,22 @@ int get_c_indent(void)
} else if (what == COM_END) {
// If our line starts with the middle comment string, line it
// up with the comment opener per the 'comments' option.
- if (STRNCMP(theline, lead_middle, lead_middle_len) == 0
- && STRNCMP(theline, lead_end, strlen(lead_end)) != 0) {
+ if (strncmp(theline, lead_middle, (size_t)lead_middle_len) == 0
+ && strncmp(theline, lead_end, strlen(lead_end)) != 0) {
done = true;
if (curwin->w_cursor.lnum > 1) {
// If the start comment string matches in the previous
// line, use the indent of that line plus offset. If
// the middle comment string matches in the previous
// line, use the indent of that line. XXX
- look = (char_u *)skipwhite(ml_get(curwin->w_cursor.lnum - 1));
- if (STRNCMP(look, lead_start, lead_start_len) == 0) {
+ look = skipwhite(ml_get(curwin->w_cursor.lnum - 1));
+ if (strncmp(look, lead_start, (size_t)lead_start_len) == 0) {
amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
- } else if (STRNCMP(look, lead_middle, lead_middle_len) == 0) {
+ } else if (strncmp(look, lead_middle, (size_t)lead_middle_len) == 0) {
amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
break;
- } else if (STRNCMP(ml_get(comment_pos->lnum) + comment_pos->col,
- lead_start, lead_start_len) != 0) {
+ } else if (strncmp(ml_get(comment_pos->lnum) + comment_pos->col,
+ lead_start, (size_t)lead_start_len) != 0) {
// If the start comment string doesn't match with the
// start of the comment, skip this entry. XXX
continue;
@@ -2057,8 +2057,8 @@ int get_c_indent(void)
// If our line starts with the end comment string, line it up
// with the middle comment
- if (STRNCMP(theline, lead_middle, lead_middle_len) != 0
- && STRNCMP(theline, lead_end, strlen(lead_end)) == 0) {
+ if (strncmp(theline, lead_middle, (size_t)lead_middle_len) != 0
+ && strncmp(theline, lead_end, strlen(lead_end)) == 0) {
amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
// XXX
if (off != 0) {
@@ -2096,7 +2096,7 @@ int get_c_indent(void)
if (amount == -1) { // use the comment opener
if (!curbuf->b_ind_in_comment2) {
start = (char_u *)ml_get(comment_pos->lnum);
- look = start + comment_pos->col + 2; // skip / and *
+ look = (char *)start + comment_pos->col + 2; // skip / and *
if (*look != NUL) { // if something after it
comment_pos->col = (colnr_T)((char_u *)skipwhite((char *)look) - start);
}
@@ -2111,7 +2111,7 @@ int get_c_indent(void)
goto theend;
}
// Are we looking at a ']' that has a match?
- if (*skipwhite((char *)theline) == ']'
+ if (*skipwhite(theline) == ']'
&& (trypos = find_match_char('[', curbuf->b_ind_maxparen)) != NULL) {
// align with the line containing the '['.
amount = get_indent_lnum(trypos->lnum);
@@ -2145,8 +2145,8 @@ int get_c_indent(void)
} else {
amount = -1;
for (lnum = cur_curpos.lnum - 1; lnum > our_paren_pos.lnum; lnum--) {
- l = (char_u *)skipwhite(ml_get(lnum));
- if (cin_nocode(l)) { // skip comment lines
+ l = skipwhite(ml_get(lnum));
+ if (cin_nocode((char_u *)l)) { // skip comment lines
continue;
}
if (cin_ispreproc_cont(&l, &lnum, &amount)) {
@@ -2207,11 +2207,11 @@ int get_c_indent(void)
line = (char_u *)ml_get(outermost.lnum);
is_if_for_while =
- cin_is_if_for_while_before_offset(line, &outermost.col);
+ cin_is_if_for_while_before_offset((char *)line, &outermost.col);
}
amount = skip_label(our_paren_pos.lnum, &look);
- look = (char_u *)skipwhite((char *)look);
+ look = skipwhite((char *)look);
if (*look == '(') {
linenr_T save_lnum = curwin->w_cursor.lnum;
char_u *line;
@@ -2221,7 +2221,7 @@ int get_c_indent(void)
// our matching '('.
curwin->w_cursor.lnum = our_paren_pos.lnum;
line = (char_u *)get_cursor_line_ptr();
- look_col = (int)(look - line);
+ look_col = (int)(look - (char *)line);
curwin->w_cursor.col = look_col + 1;
if ((trypos = findmatchlimit(NULL, ')', 0,
curbuf->b_ind_maxparen))
@@ -2232,7 +2232,7 @@ int get_c_indent(void)
}
curwin->w_cursor.lnum = save_lnum;
- look = (char_u *)ml_get(our_paren_pos.lnum) + look_col;
+ look = ml_get(our_paren_pos.lnum) + look_col;
}
if (theline[0] == ')' || (curbuf->b_ind_unclosed == 0
&& is_if_for_while == 0)
@@ -2247,9 +2247,9 @@ int get_c_indent(void)
// lines).
if (theline[0] != ')') {
cur_amount = MAXCOL;
- l = (char_u *)ml_get(our_paren_pos.lnum);
+ l = ml_get(our_paren_pos.lnum);
if (curbuf->b_ind_unclosed_wrapped
- && cin_ends_in(l, (char_u *)"(", NULL)) {
+ && cin_ends_in(l, "(", NULL)) {
// look for opening unmatched paren, indent one level
// for each additional level
n = 1;
@@ -2352,7 +2352,7 @@ int get_c_indent(void)
}
// add extra indent for a comment
- if (cin_iscomment(theline)) {
+ if (cin_iscomment((char_u *)theline)) {
amount += curbuf->b_ind_comment;
}
} else {
@@ -2370,7 +2370,7 @@ int get_c_indent(void)
// If the brace was at the start of the line, we use that;
// otherwise, check out the indentation of the line as
// a whole and then add the "imaginary indent" to that.
- look = (char_u *)skipwhite((char *)start);
+ look = skipwhite((char *)start);
if (*look == '{') {
getvcol(curwin, trypos, &col, NULL, NULL);
amount = col;
@@ -2409,7 +2409,7 @@ int get_c_indent(void)
}
// For Javascript check if the line starts with "key:".
- bool js_cur_has_key = curbuf->b_ind_js ? cin_has_js_key(theline) : false;
+ bool js_cur_has_key = curbuf->b_ind_js ? cin_has_js_key((char_u *)theline) : false;
// If we're looking at a closing brace, that's where
// we want to be. Otherwise, add the amount of room
@@ -2426,7 +2426,7 @@ int get_c_indent(void)
lookfor = LOOKFOR_INITIAL;
if (cin_iselse(theline)) {
lookfor = LOOKFOR_IF;
- } else if (cin_iswhileofdo(theline, cur_curpos.lnum)) { // XXX
+ } else if (cin_iswhileofdo((char_u *)theline, cur_curpos.lnum)) { // XXX
lookfor = LOOKFOR_DO;
}
if (lookfor != LOOKFOR_INITIAL) {
@@ -2456,8 +2456,8 @@ int get_c_indent(void)
if (start_brace == BRACE_AT_END) { // '{' is at end of line
amount += curbuf->b_ind_open_imag;
- l = (char_u *)skipwhite(get_cursor_line_ptr());
- if (cin_is_cpp_namespace(l)) {
+ l = skipwhite(get_cursor_line_ptr());
+ if (cin_is_cpp_namespace((char *)l)) {
amount += curbuf->b_ind_cpp_namespace;
} else if (cin_is_cpp_extern_c(l)) {
amount += curbuf->b_ind_cpp_extern_c;
@@ -2473,10 +2473,10 @@ int get_c_indent(void)
lookfor_break = false;
- if (cin_iscase(theline, false)) { // it's a switch() label
+ if (cin_iscase((char_u *)theline, false)) { // it's a switch() label
lookfor = LOOKFOR_CASE; // find a previous switch() label
amount += curbuf->b_ind_case;
- } else if (cin_isscopedecl(theline)) { // private:, ...
+ } else if (cin_isscopedecl((char_u *)theline)) { // private:, ...
lookfor = LOOKFOR_SCOPEDECL; // class decl is this block
amount += curbuf->b_ind_scopedecl;
} else {
@@ -2529,7 +2529,7 @@ int get_c_indent(void)
break;
}
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
// If we're in a comment or raw string now, skip to
// the start of it.
@@ -2547,11 +2547,11 @@ int get_c_indent(void)
continue;
}
- if (cin_nocode(l)) {
+ if (cin_nocode((char_u *)l)) {
continue;
}
- terminated = cin_isterminated(l, false, true);
+ terminated = cin_isterminated((char_u *)l, false, true);
// If we are at top level and the line looks like a
// function declaration, we are done
@@ -2586,11 +2586,11 @@ int get_c_indent(void)
// will take us back to the start of the line.
// XXX
trypos = NULL;
- if (find_last_paren(l, '(', ')')) {
+ if (find_last_paren((char_u *)l, '(', ')')) {
trypos = find_match_paren(curbuf->b_ind_maxparen);
}
- if (trypos == NULL && find_last_paren(l, '{', '}')) {
+ if (trypos == NULL && find_last_paren((char_u *)l, '{', '}')) {
trypos = find_start_brace();
}
@@ -2640,7 +2640,7 @@ int get_c_indent(void)
break;
}
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
// If we're in a comment or raw string now, skip
// to the start of it.
@@ -2657,7 +2657,7 @@ int get_c_indent(void)
}
// Finally the actual check for "namespace".
- if (cin_is_cpp_namespace(l)) {
+ if (cin_is_cpp_namespace((char *)l)) {
amount += curbuf->b_ind_cpp_namespace
- added_to_amount;
break;
@@ -2666,7 +2666,7 @@ int get_c_indent(void)
break;
}
- if (cin_nocode(l)) {
+ if (cin_nocode((char_u *)l)) {
continue;
}
}
@@ -2683,12 +2683,12 @@ int get_c_indent(void)
continue;
}
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
// If this is a switch() label, may line up relative to that.
// If this is a C++ scope declaration, do the same.
- bool iscase = cin_iscase(l, false);
- if (iscase || cin_isscopedecl(l)) {
+ bool iscase = cin_iscase((char_u *)l, false);
+ if (iscase || cin_isscopedecl((char_u *)l)) {
// we are only looking for cpp base class
// declaration/initialization any longer
if (lookfor == LOOKFOR_CPP_BASECLASS) {
@@ -2757,7 +2757,7 @@ int get_c_indent(void)
// -> y = y + 1;
if (n) {
amount = n;
- l = after_label((char_u *)get_cursor_line_ptr());
+ l = (char *)after_label((char_u *)get_cursor_line_ptr());
if (l != NULL && cin_is_cinword((char *)l)) {
if (theline[0] == '{') {
amount += curbuf->b_ind_open_extra;
@@ -2786,7 +2786,7 @@ int get_c_indent(void)
// Looking for a switch() label or C++ scope declaration,
// ignore other lines, skip {}-blocks.
if (lookfor == LOOKFOR_CASE || lookfor == LOOKFOR_SCOPEDECL) {
- if (find_last_paren(l, '{', '}')
+ if (find_last_paren((char_u *)l, '{', '}')
&& (trypos = find_start_brace()) != NULL) {
curwin->w_cursor.lnum = trypos->lnum + 1;
curwin->w_cursor.col = 0;
@@ -2796,8 +2796,8 @@ int get_c_indent(void)
// Ignore jump labels with nothing after them.
if (!curbuf->b_ind_js && cin_islabel()) {
- l = after_label((char_u *)get_cursor_line_ptr());
- if (l == NULL || cin_nocode(l)) {
+ l = (char *)after_label((char_u *)get_cursor_line_ptr());
+ if (l == NULL || cin_nocode((char_u *)l)) {
continue;
}
}
@@ -2806,9 +2806,9 @@ int get_c_indent(void)
// Ignore comment and empty lines.
// (need to get the line again, cin_islabel() may have
// unlocked it)
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)
- || cin_nocode(l)) {
+ || cin_nocode((char_u *)l)) {
continue;
}
@@ -2818,7 +2818,7 @@ int get_c_indent(void)
n = 0;
if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0) {
n = cin_is_cpp_baseclass(&cache_cpp_baseclass);
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
}
if (n) {
if (lookfor == LOOKFOR_UNTERM) {
@@ -2840,7 +2840,7 @@ int get_c_indent(void)
} else if (lookfor == LOOKFOR_CPP_BASECLASS) {
// only look, whether there is a cpp base class
// declaration or initialization before the opening brace.
- if (cin_isterminated(l, true, false)) {
+ if (cin_isterminated((char_u *)l, true, false)) {
break;
} else {
continue;
@@ -2856,7 +2856,7 @@ int get_c_indent(void)
// Otherwise check whether it is an enumeration or structure
// initialisation (not indented) or a variable declaration
// (indented).
- terminated = cin_isterminated(l, false, true);
+ terminated = cin_isterminated((char_u *)l, false, true);
if (js_cur_has_key) {
js_cur_has_key = false; // only check the first line
@@ -2871,7 +2871,7 @@ int get_c_indent(void)
lookfor = LOOKFOR_JS_KEY;
}
}
- if (lookfor == LOOKFOR_JS_KEY && cin_has_js_key(l)) {
+ if (lookfor == LOOKFOR_JS_KEY && cin_has_js_key((char_u *)l)) {
amount = get_indent();
break;
}
@@ -2908,7 +2908,7 @@ int get_c_indent(void)
// Position the cursor over the rightmost paren, so that
// matching it will take us back to the start of the line.
// Ignore a match before the start of the block.
- (void)find_last_paren(l, '(', ')');
+ (void)find_last_paren((char_u *)l, '(', ')');
trypos = find_match_paren(corr_ind_maxparen(&cur_curpos));
if (trypos != NULL && (trypos->lnum < tryposBrace->lnum
|| (trypos->lnum == tryposBrace->lnum
@@ -2919,7 +2919,7 @@ int get_c_indent(void)
// If we are looking for ',', we also look for matching
// braces.
if (trypos == NULL && terminated == ','
- && find_last_paren(l, '{', '}')) {
+ && find_last_paren((char_u *)l, '{', '}')) {
trypos = find_start_brace();
}
@@ -2929,8 +2929,8 @@ int get_c_indent(void)
// case xx: if ( asdf &&
// asdf)
curwin->w_cursor = *trypos;
- l = (char_u *)get_cursor_line_ptr();
- if (cin_iscase(l, false) || cin_isscopedecl(l)) {
+ l = get_cursor_line_ptr();
+ if (cin_iscase((char_u *)l, false) || cin_isscopedecl((char_u *)l)) {
curwin->w_cursor.lnum++;
curwin->w_cursor.col = 0;
continue;
@@ -2944,7 +2944,7 @@ int get_c_indent(void)
// here;
if (terminated == ',') {
while (curwin->w_cursor.lnum > 1) {
- l = (char_u *)ml_get(curwin->w_cursor.lnum - 1);
+ l = ml_get(curwin->w_cursor.lnum - 1);
if (*l == NUL || l[strlen((char *)l) - 1] != '\\') {
break;
}
@@ -2988,7 +2988,7 @@ int get_c_indent(void)
// Check if we are after an "if", "while", etc.
// Also allow " } else".
- if (cin_is_cinword((char *)l) || cin_iselse((char_u *)skipwhite((char *)l))) {
+ if (cin_is_cinword((char *)l) || cin_iselse(skipwhite((char *)l))) {
// Found an unterminated line after an if (), line up
// with the last one.
// if (cond)
@@ -3030,8 +3030,8 @@ int get_c_indent(void)
// do
// x = 1;
// -> here
- l = (char_u *)skipwhite(get_cursor_line_ptr());
- if (cin_isdo(l)) {
+ l = skipwhite(get_cursor_line_ptr());
+ if (cin_isdo((char *)l)) {
if (whilelevel == 0) {
break;
}
@@ -3042,13 +3042,13 @@ int get_c_indent(void)
// one between the "if" and the matching "else".
// Need to use the scope of this "else". XXX
// If whilelevel != 0 continue looking for a "do {".
- if (cin_iselse(l) && whilelevel == 0) {
+ if (cin_iselse((char *)l) && whilelevel == 0) {
// If we're looking at "} else", let's make sure we
// find the opening brace of the enclosing scope,
// not the one from "if () {".
if (*l == '}') {
curwin->w_cursor.col =
- (colnr_T)(l - (char_u *)get_cursor_line_ptr()) + 1;
+ (colnr_T)(l - get_cursor_line_ptr()) + 1;
}
if ((trypos = find_start_brace()) == NULL
@@ -3101,7 +3101,7 @@ int get_c_indent(void)
// line up with this line, remember its indent
// 100 + // NOLINT(whitespace/tab)
// -> here; // NOLINT(whitespace/tab)
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
amount = cur_amount;
n = (int)strlen((char *)l);
@@ -3202,15 +3202,15 @@ int get_c_indent(void)
// Skip single break line, if before a switch label. It
// may be lined up with the case label.
if (lookfor == LOOKFOR_NOBREAK
- && cin_isbreak((char_u *)skipwhite(get_cursor_line_ptr()))) {
+ && cin_isbreak(skipwhite(get_cursor_line_ptr()))) {
lookfor = LOOKFOR_ANY;
continue;
}
// Handle "do {" line.
if (whilelevel > 0) {
- l = cin_skipcomment((char_u *)get_cursor_line_ptr());
- if (cin_isdo(l)) {
+ l = (char *)cin_skipcomment((char_u *)get_cursor_line_ptr());
+ if (cin_isdo((char *)l)) {
amount = get_indent(); // XXX
whilelevel--;
continue;
@@ -3259,16 +3259,16 @@ int get_c_indent(void)
// asdfasdf);
// here;
term_again:
- l = (char_u *)get_cursor_line_ptr();
- if (find_last_paren(l, '(', ')')
+ l = get_cursor_line_ptr();
+ if (find_last_paren((char_u *)l, '(', ')')
&& (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) {
// Check if we are on a case label now. This is
// handled above.
// case xx: if ( asdf &&
// asdf)
curwin->w_cursor = *trypos;
- l = (char_u *)get_cursor_line_ptr();
- if (cin_iscase(l, false) || cin_isscopedecl(l)) {
+ l = get_cursor_line_ptr();
+ if (cin_iscase((char_u *)l, false) || cin_isscopedecl((char_u *)l)) {
curwin->w_cursor.lnum++;
curwin->w_cursor.col = 0;
continue;
@@ -3283,7 +3283,7 @@ term_again:
// case 2:
// stat;
// }
- iscase = curbuf->b_ind_keep_case_label && cin_iscase(l, false);
+ iscase = curbuf->b_ind_keep_case_label && cin_iscase((char_u *)l, false);
// Get indent and pointer to text for current line,
// ignoring any jump label.
@@ -3293,7 +3293,7 @@ term_again:
amount += curbuf->b_ind_open_extra;
}
// See remark above: "Only add b_ind_open_extra.."
- l = (char_u *)skipwhite((char *)l);
+ l = skipwhite((char *)l);
if (*l == '{') {
amount -= curbuf->b_ind_open_extra;
}
@@ -3307,7 +3307,7 @@ term_again:
// If whilelevel != 0 continue looking for a "do {".
if (lookfor == LOOKFOR_TERM
&& *l != '}'
- && cin_iselse(l)
+ && cin_iselse((char *)l)
&& whilelevel == 0) {
if ((trypos = find_start_brace()) == NULL
|| find_match(LOOKFOR_IF, trypos->lnum)
@@ -3319,14 +3319,14 @@ term_again:
// If we're at the end of a block, skip to the start of
// that block.
- l = (char_u *)get_cursor_line_ptr();
- if (find_last_paren(l, '{', '}') // XXX
+ l = get_cursor_line_ptr();
+ if (find_last_paren((char_u *)l, '{', '}') // XXX
&& (trypos = find_start_brace()) != NULL) {
curwin->w_cursor = *trypos;
// if not "else {" check for terminated again
// but skip block for "} else {"
- l = cin_skipcomment((char_u *)get_cursor_line_ptr());
- if (*l == '}' || !cin_iselse(l)) {
+ l = (char *)cin_skipcomment((char_u *)get_cursor_line_ptr());
+ if (*l == '}' || !cin_iselse((char *)l)) {
goto term_again;
}
curwin->w_cursor.lnum++;
@@ -3339,7 +3339,7 @@ term_again:
}
// add extra indent for a comment
- if (cin_iscomment(theline)) {
+ if (cin_iscomment((char_u *)theline)) {
amount += curbuf->b_ind_comment;
}
// subtract extra left-shift for jump labels
@@ -3371,13 +3371,13 @@ term_again:
// current line is terminated, ie. ends in ';', or if the current line
// contains { or }: "void f() {\n if (1)"
if (cur_curpos.lnum < curbuf->b_ml.ml_line_count
- && !cin_nocode(theline)
- && vim_strchr((char *)theline, '{') == NULL
- && vim_strchr((char *)theline, '}') == NULL
- && !cin_ends_in(theline, (char_u *)":", NULL)
- && !cin_ends_in(theline, (char_u *)",", NULL)
+ && !cin_nocode((char_u *)theline)
+ && vim_strchr(theline, '{') == NULL
+ && vim_strchr(theline, '}') == NULL
+ && !cin_ends_in(theline, ":", NULL)
+ && !cin_ends_in(theline, ",", NULL)
&& cin_isfuncdecl(NULL, cur_curpos.lnum + 1, cur_curpos.lnum + 1)
- && !cin_isterminated(theline, false, true)) {
+ && !cin_isterminated((char_u *)theline, false, true)) {
amount = curbuf->b_ind_func_type;
goto theend;
}
@@ -3389,7 +3389,7 @@ term_again:
curwin->w_cursor.lnum--;
curwin->w_cursor.col = 0;
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
// If we're in a comment or raw string now, skip to the start
// of it.
@@ -3405,7 +3405,7 @@ term_again:
n = 0;
if (curbuf->b_ind_cpp_baseclass != 0) {
n = cin_is_cpp_baseclass(&cache_cpp_baseclass);
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
}
if (n) {
// XXX
@@ -3420,7 +3420,7 @@ term_again:
continue;
}
- if (cin_nocode(l)) {
+ if (cin_nocode((char_u *)l)) {
continue;
}
@@ -3434,10 +3434,10 @@ term_again:
// ...
// } foo,
// bar;
- if (cin_ends_in(l, (char_u *)",", NULL)
- || (*l != NUL && (n = l[strlen((char *)l) - 1]) == '\\')) {
+ if (cin_ends_in(l, ",", NULL)
+ || (*l != NUL && (n = (uint8_t)l[strlen((char *)l) - 1]) == '\\')) {
// take us back to opening paren
- if (find_last_paren(l, '(', ')')
+ if (find_last_paren((char_u *)l, '(', ')')
&& (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) {
curwin->w_cursor = *trypos;
}
@@ -3448,7 +3448,7 @@ term_again:
// bla",
// here;
while (n == 0 && curwin->w_cursor.lnum > 1) {
- l = (char_u *)ml_get(curwin->w_cursor.lnum - 1);
+ l = ml_get(curwin->w_cursor.lnum - 1);
if (*l == NUL || l[strlen((char *)l) - 1] != '\\') {
break;
}
@@ -3472,7 +3472,7 @@ term_again:
if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0)) { // XXX
break;
}
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
// Finding the closing '}' of a previous function. Put
// current line at the left margin. For when 'cino' has "fs".
@@ -3485,7 +3485,7 @@ term_again:
// comments) align at column 0. For example:
// char *string_array[] = { "foo",
// / * x * / "b};ar" }; / * foobar * /
- if (cin_ends_in(l, (char_u *)"};", NULL)) {
+ if (cin_ends_in(l, "};", NULL)) {
break;
}
@@ -3493,7 +3493,7 @@ term_again:
// array constant:
// something = [
// 234, <- extra indent
- if (cin_ends_in(l, (char_u *)"[", NULL)) {
+ if (cin_ends_in(l, "[", NULL)) {
amount = get_indent() + ind_continuation;
break;
}
@@ -3501,18 +3501,18 @@ term_again:
// Find a line only has a semicolon that belongs to a previous
// line ending in '}', e.g. before an #endif. Don't increase
// indent then.
- if (*(look = (char_u *)skipwhite((char *)l)) == ';' && cin_nocode(look + 1)) {
+ if (*(look = skipwhite((char *)l)) == ';' && cin_nocode((char_u *)look + 1)) {
pos_T curpos_save = curwin->w_cursor;
while (curwin->w_cursor.lnum > 1) {
- look = (char_u *)ml_get(--curwin->w_cursor.lnum);
- if (!(cin_nocode(look)
+ look = ml_get(--curwin->w_cursor.lnum);
+ if (!(cin_nocode((char_u *)look)
|| cin_ispreproc_cont(&look, &curwin->w_cursor.lnum, &amount))) {
break;
}
}
if (curwin->w_cursor.lnum > 0
- && cin_ends_in(look, (char_u *)"}", NULL)) {
+ && cin_ends_in(look, "}", NULL)) {
break;
}
@@ -3532,13 +3532,13 @@ term_again:
// int foo,
// bar;
// indent_to_0 here;
- if (cin_ends_in(l, (char_u *)";", NULL)) {
- l = (char_u *)ml_get(curwin->w_cursor.lnum - 1);
- if (cin_ends_in(l, (char_u *)",", NULL)
+ if (cin_ends_in(l, ";", NULL)) {
+ l = ml_get(curwin->w_cursor.lnum - 1);
+ if (cin_ends_in(l, ",", NULL)
|| (*l != NUL && l[strlen((char *)l) - 1] == '\\')) {
break;
}
- l = (char_u *)get_cursor_line_ptr();
+ l = get_cursor_line_ptr();
}
// Doesn't look like anything interesting -- so just
@@ -3546,7 +3546,7 @@ term_again:
//
// Position the cursor over the rightmost paren, so that
// matching it will take us back to the start of the line.
- (void)find_last_paren(l, '(', ')');
+ (void)find_last_paren((char_u *)l, '(', ')');
if ((trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL) {
curwin->w_cursor = *trypos;
@@ -3556,7 +3556,7 @@ term_again:
}
// add extra indent for a comment
- if (cin_iscomment(theline)) {
+ if (cin_iscomment((char_u *)theline)) {
amount += curbuf->b_ind_comment;
}
@@ -3566,7 +3566,7 @@ term_again:
// char *foo = "asdf{backslash}
// here";
if (cur_curpos.lnum > 1) {
- l = (char_u *)ml_get(cur_curpos.lnum - 1);
+ l = ml_get(cur_curpos.lnum - 1);
if (*l != NUL && l[strlen((char *)l) - 1] == '\\') {
cur_amount = cin_get_equal_amount(cur_curpos.lnum - 1);
if (cur_amount > 0) {
@@ -3614,9 +3614,9 @@ static int find_match(int lookfor, linenr_T ourscope)
curwin->w_cursor.col = 0;
look = cin_skipcomment((char_u *)get_cursor_line_ptr());
- if (!cin_iselse(look)
- && !cin_isif(look)
- && !cin_isdo(look) // XXX
+ if (!cin_iselse((char *)look)
+ && !cin_isif((char *)look)
+ && !cin_isdo((char *)look) // XXX
&& !cin_iswhileofdo(look, curwin->w_cursor.lnum)) {
continue;
}
@@ -3646,9 +3646,9 @@ static int find_match(int lookfor, linenr_T ourscope)
// then we need to go back to another if, so
// increment elselevel
look = cin_skipcomment((char_u *)get_cursor_line_ptr());
- if (cin_iselse(look)) {
+ if (cin_iselse((char *)look)) {
mightbeif = cin_skipcomment(look + 4);
- if (!cin_isif(mightbeif)) {
+ if (!cin_isif((char *)mightbeif)) {
elselevel++; // NOLINT(readability/braces)
}
continue;
@@ -3663,7 +3663,7 @@ static int find_match(int lookfor, linenr_T ourscope)
// If it's an "if" decrement elselevel
look = cin_skipcomment((char_u *)get_cursor_line_ptr());
- if (cin_isif(look)) {
+ if (cin_isif((char *)look)) {
elselevel--; // NOLINT(readability/braces)
// When looking for an "if" ignore "while"s that
// get in the way.
@@ -3673,7 +3673,7 @@ static int find_match(int lookfor, linenr_T ourscope)
}
// If it's a "do" decrement whilelevel
- if (cin_isdo(look)) {
+ if (cin_isdo((char *)look)) {
whilelevel--;
}
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c
index 6531da6419..222d3228ba 100644
--- a/src/nvim/insexpand.c
+++ b/src/nvim/insexpand.c
@@ -893,7 +893,7 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons
/// @param match completion match
/// @param str character string to check
/// @param len length of "str"
-static bool ins_compl_equal(compl_T *match, char_u *str, size_t len)
+static bool ins_compl_equal(compl_T *match, char *str, size_t len)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
if (match->cp_flags & CP_EQUAL) {
@@ -902,7 +902,7 @@ static bool ins_compl_equal(compl_T *match, char_u *str, size_t len)
if (match->cp_flags & CP_ICASE) {
return STRNICMP(match->cp_str, str, len) == 0;
}
- return STRNCMP(match->cp_str, str, len) == 0;
+ return strncmp(match->cp_str, str, len) == 0;
}
/// Reduce the longest common string for match "match".
@@ -1151,7 +1151,7 @@ static int ins_compl_build_pum(void)
do {
if (!match_at_original_text(compl)
&& (compl_leader == NULL
- || ins_compl_equal(compl, (char_u *)compl_leader, (size_t)lead_len))) {
+ || ins_compl_equal(compl, compl_leader, (size_t)lead_len))) {
compl_match_arraysize++;
}
compl = compl->cp_next;
@@ -1176,7 +1176,7 @@ static int ins_compl_build_pum(void)
do {
if (!match_at_original_text(compl)
&& (compl_leader == NULL
- || ins_compl_equal(compl, (char_u *)compl_leader, (size_t)lead_len))) {
+ || ins_compl_equal(compl, compl_leader, (size_t)lead_len))) {
if (!shown_match_ok) {
if (compl == compl_shown_match || did_find_shown_match) {
// This item is the shown match or this is the
@@ -1823,7 +1823,7 @@ void ins_compl_addfrommatch(void)
for (cp = compl_shown_match->cp_next; cp != NULL
&& !is_first_match(cp); cp = cp->cp_next) {
if (compl_leader == NULL
- || ins_compl_equal(cp, (char_u *)compl_leader, strlen(compl_leader))) {
+ || ins_compl_equal(cp, compl_leader, strlen(compl_leader))) {
p = cp->cp_str;
break;
}
@@ -2755,6 +2755,7 @@ static void get_complete_info(list_T *what_list, dict_T *retdict)
tv_dict_add_str(di, S_LEN("kind"), EMPTY_IF_NULL(match->cp_text[CPT_KIND]));
tv_dict_add_str(di, S_LEN("info"), EMPTY_IF_NULL(match->cp_text[CPT_INFO]));
if (match->cp_user_data.v_type == VAR_UNKNOWN) {
+ // Add an empty string for backwards compatibility
tv_dict_add_str(di, S_LEN("user_data"), "");
} else {
tv_dict_add_tv(di, S_LEN("user_data"), &match->cp_user_data);
@@ -3403,7 +3404,7 @@ static int ins_compl_get_exp(pos_T *ini)
static void ins_compl_update_shown_match(void)
{
while (!ins_compl_equal(compl_shown_match,
- (char_u *)compl_leader, strlen(compl_leader))
+ compl_leader, strlen(compl_leader))
&& compl_shown_match->cp_next != NULL
&& !is_first_match(compl_shown_match->cp_next)) {
compl_shown_match = compl_shown_match->cp_next;
@@ -3412,10 +3413,10 @@ static void ins_compl_update_shown_match(void)
// If we didn't find it searching forward, and compl_shows_dir is
// backward, find the last match.
if (compl_shows_dir_backward()
- && !ins_compl_equal(compl_shown_match, (char_u *)compl_leader, strlen(compl_leader))
+ && !ins_compl_equal(compl_shown_match, compl_leader, strlen(compl_leader))
&& (compl_shown_match->cp_next == NULL
|| is_first_match(compl_shown_match->cp_next))) {
- while (!ins_compl_equal(compl_shown_match, (char_u *)compl_leader, strlen(compl_leader))
+ while (!ins_compl_equal(compl_shown_match, compl_leader, strlen(compl_leader))
&& compl_shown_match->cp_prev != NULL
&& !is_first_match(compl_shown_match->cp_prev)) {
compl_shown_match = compl_shown_match->cp_prev;
@@ -3560,7 +3561,7 @@ static int find_next_completion_match(bool allow_get_expansion, int todo, bool a
if (!match_at_original_text(compl_shown_match)
&& compl_leader != NULL
&& !ins_compl_equal(compl_shown_match,
- (char_u *)compl_leader, strlen(compl_leader))) {
+ compl_leader, strlen(compl_leader))) {
todo++;
} else {
// Remember a matching item.
diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c
index 90539d5578..f3795ab276 100644
--- a/src/nvim/keycodes.c
+++ b/src/nvim/keycodes.c
@@ -570,7 +570,7 @@ char_u *get_special_key_name(int c, int modifiers)
/// @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 **const srcp, const size_t src_len, char_u *const dst,
+unsigned int trans_special(const char **const srcp, const size_t src_len, char_u *const dst,
const int flags, const bool escape_ks, bool *const did_simplify)
FUNC_ATTR_NONNULL_ARG(1, 3) FUNC_ATTR_WARN_UNUSED_RESULT
{
@@ -623,7 +623,7 @@ unsigned int special_to_buf(int key, int modifiers, bool escape_ks, char_u *dst)
/// @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 **const srcp, const size_t src_len, int *const modp,
+int find_special_key(const char **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)
{
@@ -631,7 +631,7 @@ int find_special_key(const char_u **const srcp, const size_t src_len, int *const
const char_u *end_of_name;
const char_u *src;
const char_u *bp;
- const char_u *const end = *srcp + src_len - 1;
+ const char_u *const end = (char_u *)(*srcp) + src_len - 1;
const bool in_string = flags & FSK_IN_STRING;
int modifiers;
int bit;
@@ -643,7 +643,7 @@ int find_special_key(const char_u **const srcp, const size_t src_len, int *const
return 0;
}
- src = *srcp;
+ src = (char_u *)(*srcp);
if (src[0] != '<') {
return 0;
}
@@ -751,7 +751,7 @@ int find_special_key(const char_u **const srcp, const size_t src_len, int *const
}
*modp = modifiers;
- *srcp = end_of_name;
+ *srcp = (char *)end_of_name;
return key;
} // else { ELOG("unknown key: '%s'", src); }
}
@@ -885,10 +885,10 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co
{
ssize_t i;
size_t slen;
- char_u key;
+ char key;
size_t dlen = 0;
- const char_u *src;
- const char_u *const end = (char_u *)from + from_len - 1;
+ const char *src;
+ const char *const end = from + from_len - 1;
char *result; // buffer for resulting string
const bool do_backslash = !(cpo_flags & FLAG_CPO_BSLASH); // backslash is a special character
@@ -901,7 +901,7 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co
const size_t buf_len = allocated ? from_len * 6 + 1 : 128;
result = allocated ? xmalloc(buf_len) : *bufp;
- src = (char_u *)from;
+ src = from;
// Check for #n at start only: function key n
if ((flags & REPTERM_FROM_PART) && from_len > 1 && src[0] == '#'
@@ -911,7 +911,7 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co
if (src[1] == '0') {
result[dlen++] = ';'; // #0 is F10 is "k;"
} else {
- result[dlen++] = (char)src[1]; // #3 is F3 is "k3"
+ result[dlen++] = src[1]; // #3 is F3 is "k3"
}
src += 2;
}
@@ -923,7 +923,7 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co
}
// Check for special <> keycodes, like "<C-S-LeftMouse>"
if (do_special && ((flags & REPTERM_DO_LT) || ((end - src) >= 3
- && STRNCMP(src, "<lt>", 4) != 0))) {
+ && 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) {
@@ -993,7 +993,7 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co
src++; // skip CTRL-V or backslash
if (src > end) {
if (flags & REPTERM_FROM_PART) {
- result[dlen++] = (char)key;
+ result[dlen++] = key;
}
break;
}
@@ -1003,12 +1003,12 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co
for (i = utfc_ptr2len_len((char *)src, (int)(end - src) + 1); i > 0; i--) {
// If the character is K_SPECIAL, replace it with K_SPECIAL
// KS_SPECIAL KE_FILLER.
- if (*src == K_SPECIAL) {
+ if (*src == (char)K_SPECIAL) {
result[dlen++] = (char)K_SPECIAL;
result[dlen++] = (char)KS_SPECIAL;
result[dlen++] = KE_FILLER;
} else {
- result[dlen++] = (char)(*src);
+ result[dlen++] = *src;
}
src++;
}
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 1c8fe3e28e..590d6fa920 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -205,8 +205,8 @@ static int nlua_luv_cfpcall(lua_State *lstate, int nargs, int nresult, int flags
if (status) {
if (status == LUA_ERRMEM && !(flags & LUVF_CALLBACK_NOEXIT)) {
// consider out of memory errors unrecoverable, just like xmalloc()
- mch_errmsg(e_outofmem);
- mch_errmsg("\n");
+ os_errmsg(e_outofmem);
+ os_errmsg("\n");
preserve_exit();
}
const char *error = lua_tostring(lstate, -1);
@@ -258,8 +258,8 @@ static int nlua_luv_thread_common_cfpcall(lua_State *lstate, int nargs, int nres
if (status == LUA_ERRMEM && !(flags & LUVF_CALLBACK_NOEXIT)) {
// Terminate this thread, as the main thread may be able to continue
// execution.
- mch_errmsg(e_outofmem);
- mch_errmsg("\n");
+ os_errmsg(e_outofmem);
+ os_errmsg("\n");
lua_close(lstate);
#ifdef MSWIN
ExitThread(0);
@@ -598,8 +598,8 @@ static bool nlua_init_packages(lua_State *lstate)
lua_getglobal(lstate, "require");
lua_pushstring(lstate, "vim._init_packages");
if (nlua_pcall(lstate, 1, 0)) {
- mch_errmsg((char *)lua_tostring(lstate, -1));
- mch_errmsg("\n");
+ os_errmsg((char *)lua_tostring(lstate, -1));
+ os_errmsg("\n");
return false;
}
@@ -779,12 +779,12 @@ void nlua_init(void)
lua_State *lstate = luaL_newstate();
if (lstate == NULL) {
- mch_errmsg(_("E970: Failed to initialize lua interpreter\n"));
+ os_errmsg(_("E970: Failed to initialize lua interpreter\n"));
os_exit(1);
}
luaL_openlibs(lstate);
if (!nlua_state_init(lstate)) {
- mch_errmsg(_("E970: Failed to initialize builtin lua modules\n"));
+ os_errmsg(_("E970: Failed to initialize builtin lua modules\n"));
os_exit(1);
}
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 78b59887e7..a7f07af1a8 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -278,6 +278,8 @@ int main(int argc, char **argv)
// argument list "global_alist".
command_line_scan(&params);
+ open_script_files(&params);
+
nlua_init();
TIME_MSG("init lua interpreter");
@@ -769,15 +771,15 @@ void preserve_exit(void)
really_exiting = true;
// Ignore SIGHUP while we are already exiting. #9274
signal_reject_deadly();
- mch_errmsg(IObuff);
- mch_errmsg("\n");
+ os_errmsg(IObuff);
+ os_errmsg("\n");
ui_flush();
ml_close_notmod(); // close all not-modified buffers
FOR_ALL_BUFFERS(buf) {
if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) {
- mch_errmsg("Vim: preserving files...\r\n");
+ os_errmsg("Vim: preserving files...\r\n");
ui_flush();
ml_sync_all(false, false, true); // preserve all swap files
break;
@@ -786,7 +788,7 @@ void preserve_exit(void)
ml_close_all(false); // close all memfiles, without deleting
- mch_errmsg("Vim: Finished.\r\n");
+ os_errmsg("Vim: Finished.\r\n");
getout(1);
}
@@ -868,15 +870,15 @@ static void remote_request(mparm_T *params, int remote_args, char *server_addr,
Object o = nlua_exec(s, a, &err);
api_free_array(a);
if (ERROR_SET(&err)) {
- mch_errmsg(err.msg);
- mch_errmsg("\n");
+ os_errmsg(err.msg);
+ os_errmsg("\n");
os_exit(2);
}
if (o.type == kObjectTypeDictionary) {
rvobj.data.dictionary = o.data.dictionary;
} else {
- mch_errmsg("vim._cs_remote returned unexpected value\n");
+ os_errmsg("vim._cs_remote returned unexpected value\n");
os_exit(2);
}
@@ -886,28 +888,28 @@ static void remote_request(mparm_T *params, int remote_args, char *server_addr,
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");
+ os_errmsg("vim._cs_remote returned an unexpected type for 'errmsg'\n");
os_exit(2);
}
- mch_errmsg(rvobj.data.dictionary.items[i].value.data.string.data);
- mch_errmsg("\n");
+ os_errmsg(rvobj.data.dictionary.items[i].value.data.string.data);
+ os_errmsg("\n");
os_exit(2);
} else if (strcmp(rvobj.data.dictionary.items[i].key.data, "tabbed") == 0) {
if (rvobj.data.dictionary.items[i].value.type != kObjectTypeBoolean) {
- mch_errmsg("vim._cs_remote returned an unexpected type for 'tabbed'\n");
+ os_errmsg("vim._cs_remote returned an unexpected type for 'tabbed'\n");
os_exit(2);
}
tabbed = rvobj.data.dictionary.items[i].value.data.boolean ? kTrue : kFalse;
} else if (strcmp(rvobj.data.dictionary.items[i].key.data, "should_exit") == 0) {
if (rvobj.data.dictionary.items[i].value.type != kObjectTypeBoolean) {
- mch_errmsg("vim._cs_remote returned an unexpected type for 'should_exit'\n");
+ os_errmsg("vim._cs_remote returned an unexpected type for 'should_exit'\n");
os_exit(2);
}
should_exit = rvobj.data.dictionary.items[i].value.data.boolean ? kTrue : kFalse;
}
}
if (should_exit == kNone || tabbed == kNone) {
- mch_errmsg("vim._cs_remote didn't return a value for should_exit or tabbed, bailing\n");
+ os_errmsg("vim._cs_remote didn't return a value for should_exit or tabbed, bailing\n");
os_exit(2);
}
api_free_object(o);
@@ -929,7 +931,7 @@ static bool edit_stdin(bool explicit, mparm_T *parmp)
&& !embedded_mode
&& (!exmode_active || parmp->input_neverscript)
&& !parmp->input_isatty
- && scriptin[0] == NULL; // `-s -` was not given.
+ && parmp->scriptin == NULL; // `-s -` was not given.
return explicit || implicit;
}
@@ -1277,37 +1279,17 @@ static void command_line_scan(mparm_T *parmp)
set_option_value_give_err("shadafile", 0L, argv[0], 0);
break;
- case 's': { // "-s {scriptin}" read from script file
- if (scriptin[0] != NULL) {
+ case 's': // "-s {scriptin}" read from script file
+ if (parmp->scriptin != NULL) {
scripterror:
vim_snprintf((char *)IObuff, IOSIZE,
_("Attempt to open script file again: \"%s %s\"\n"),
argv[-1], argv[0]);
- mch_errmsg(IObuff);
+ os_errmsg(IObuff);
os_exit(2);
}
- int error;
- if (strequal(argv[0], "-")) {
- const int stdin_dup_fd = os_dup(STDIN_FILENO);
-#ifdef MSWIN
- // Replace the original stdin with the console input handle.
- os_replace_stdin_to_conin();
-#endif
- FileDescriptor *const stdin_dup = file_open_fd_new(&error, stdin_dup_fd,
- kFileReadOnly|kFileNonBlocking);
- assert(stdin_dup != NULL);
- scriptin[0] = stdin_dup;
- } else if ((scriptin[0] = file_open_new(&error, argv[0],
- kFileReadOnly|kFileNonBlocking, 0)) == NULL) {
- vim_snprintf((char *)IObuff, IOSIZE,
- _("Cannot open for reading: \"%s\": %s\n"),
- argv[0], os_strerror(error));
- mch_errmsg(IObuff);
- os_exit(2);
- }
- save_typebuf();
+ parmp->scriptin = argv[0];
break;
- }
case 't': // "-t {tag}"
parmp->tagname = argv[0];
@@ -1329,17 +1311,11 @@ scripterror:
}
FALLTHROUGH;
case 'W': // "-W {scriptout}" overwrite script file
- if (scriptout != NULL) {
+ if (parmp->scriptout != NULL) {
goto scripterror;
}
- if ((scriptout = os_fopen(argv[0], c == 'w' ? APPENDBIN : WRITEBIN))
- == NULL) {
- mch_errmsg(_("Cannot open for script output: \""));
- mch_errmsg(argv[0]);
- mch_errmsg("\"\n");
- os_exit(2);
- }
- break;
+ parmp->scriptout = argv[0];
+ parmp->scriptout_append = (c == 'w');
}
}
} else { // File name argument.
@@ -1548,6 +1524,45 @@ static void read_stdin(void)
check_swap_exists_action();
}
+static void open_script_files(mparm_T *parmp)
+{
+ if (parmp->scriptin) {
+ int error;
+ if (strequal(parmp->scriptin, "-")) {
+ const int stdin_dup_fd = os_dup(STDIN_FILENO);
+#ifdef MSWIN
+ // Replace the original stdin with the console input handle.
+ os_replace_stdin_to_conin();
+#endif
+ FileDescriptor *const stdin_dup = file_open_fd_new(&error, stdin_dup_fd,
+ kFileReadOnly|kFileNonBlocking);
+ assert(stdin_dup != NULL);
+ scriptin[0] = stdin_dup;
+ } else {
+ scriptin[0] = file_open_new(&error, parmp->scriptin,
+ kFileReadOnly|kFileNonBlocking, 0);
+ if (scriptin[0] == NULL) {
+ vim_snprintf((char *)IObuff, IOSIZE,
+ _("Cannot open for reading: \"%s\": %s\n"),
+ parmp->scriptin, os_strerror(error));
+ os_errmsg(IObuff);
+ os_exit(2);
+ }
+ }
+ save_typebuf();
+ }
+
+ if (parmp->scriptout) {
+ scriptout = os_fopen(parmp->scriptout, parmp->scriptout_append ? APPENDBIN : WRITEBIN);
+ if (scriptout == NULL) {
+ os_errmsg(_("Cannot open for script output: \""));
+ os_errmsg(parmp->scriptout);
+ os_errmsg("\"\n");
+ os_exit(2);
+ }
+ }
+}
+
// Create the requested number of windows and edit buffers in them.
// Also does recovery if "recoverymode" set.
static void create_windows(mparm_T *parmp)
@@ -1972,6 +1987,41 @@ static bool do_user_initialization(void)
return do_exrc;
}
+// Read initialization commands from ".nvim.lua", ".nvimrc", or ".exrc" in
+// current directory. This is only done if the 'exrc' option is set.
+// Only do this if VIMRC_FILE is not the same as vimrc file sourced in
+// do_user_initialization.
+static void do_exrc_initialization(void)
+{
+ char *str;
+
+ if (os_path_exists(VIMRC_LUA_FILE)) {
+ str = nlua_read_secure(VIMRC_LUA_FILE);
+ if (str != NULL) {
+ Error err = ERROR_INIT;
+ nlua_exec(cstr_as_string(str), (Array)ARRAY_DICT_INIT, &err);
+ xfree(str);
+ if (ERROR_SET(&err)) {
+ semsg("Error detected while processing %s:", VIMRC_LUA_FILE);
+ semsg_multiline(err.msg);
+ api_clear_error(&err);
+ }
+ }
+ } else if (os_path_exists(VIMRC_FILE)) {
+ str = nlua_read_secure(VIMRC_FILE);
+ if (str != NULL) {
+ do_source_str(str, VIMRC_FILE);
+ xfree(str);
+ }
+ } else if (os_path_exists(EXRC_FILE)) {
+ str = nlua_read_secure(EXRC_FILE);
+ if (str != NULL) {
+ do_source_str(str, EXRC_FILE);
+ xfree(str);
+ }
+ }
+}
+
/// Source startup scripts
static void source_startup_scripts(const mparm_T *const parmp)
FUNC_ATTR_NONNULL_ALL
@@ -1990,21 +2040,7 @@ static void source_startup_scripts(const mparm_T *const parmp)
do_system_initialization();
if (do_user_initialization()) {
- // Read initialization commands from ".nvimrc" or ".exrc" in current
- // directory. This is only done if the 'exrc' option is set.
- // Only do this if VIMRC_FILE is not the same as vimrc file sourced in
- // do_user_initialization.
- char *str = nlua_read_secure(VIMRC_FILE);
- if (str != NULL) {
- do_source_str(str, VIMRC_FILE);
- xfree(str);
- } else {
- str = nlua_read_secure(EXRC_FILE);
- if (str != NULL) {
- do_source_str(str, EXRC_FILE);
- xfree(str);
- }
- }
+ do_exrc_initialization();
}
}
TIME_MSG("sourcing vimrc file(s)");
@@ -2048,17 +2084,17 @@ static void mainerr(const char *errstr, const char *str)
signal_stop(); // kill us with CTRL-C here, if you like
- mch_errmsg(prgname);
- mch_errmsg(": ");
- mch_errmsg(_(errstr));
+ os_errmsg(prgname);
+ os_errmsg(": ");
+ os_errmsg(_(errstr));
if (str != NULL) {
- mch_errmsg(": \"");
- mch_errmsg((char *)str);
- mch_errmsg("\"");
+ os_errmsg(": \"");
+ os_errmsg((char *)str);
+ os_errmsg("\"");
}
- mch_errmsg(_("\nMore info with \""));
- mch_errmsg(prgname);
- mch_errmsg(" -h\"\n");
+ os_errmsg(_("\nMore info with \""));
+ os_errmsg(prgname);
+ os_errmsg(" -h\"\n");
os_exit(1);
}
@@ -2068,7 +2104,7 @@ static void version(void)
{
// TODO(bfred): not like this?
nlua_init();
- info_message = true; // use mch_msg(), not mch_errmsg()
+ info_message = true; // use os_msg(), not os_errmsg()
list_version();
msg_putchar('\n');
msg_didout = false;
@@ -2079,47 +2115,47 @@ static void usage(void)
{
signal_stop(); // kill us with CTRL-C here, if you like
- mch_msg(_("Usage:\n"));
- mch_msg(_(" nvim [options] [file ...] Edit file(s)\n"));
- mch_msg(_(" nvim [options] -t <tag> Edit file where tag is defined\n"));
- mch_msg(_(" nvim [options] -q [errorfile] Edit file with first error\n"));
- mch_msg(_("\nOptions:\n"));
- mch_msg(_(" -- Only file names after this\n"));
- mch_msg(_(" + Start at end of file\n"));
- mch_msg(_(" --cmd <cmd> Execute <cmd> before any config\n"));
- mch_msg(_(" +<cmd>, -c <cmd> Execute <cmd> after config and first file\n"));
- mch_msg("\n");
- mch_msg(_(" -b Binary mode\n"));
- mch_msg(_(" -d Diff mode\n"));
- mch_msg(_(" -e, -E Ex mode\n"));
- mch_msg(_(" -es, -Es Silent (batch) mode\n"));
- mch_msg(_(" -h, --help Print this help message\n"));
- mch_msg(_(" -i <shada> Use this shada file\n"));
- mch_msg(_(" -m Modifications (writing files) not allowed\n"));
- mch_msg(_(" -M Modifications in text not allowed\n"));
- mch_msg(_(" -n No swap file, use memory only\n"));
- mch_msg(_(" -o[N] Open N windows (default: one per file)\n"));
- mch_msg(_(" -O[N] Open N vertical windows (default: one per file)\n"));
- mch_msg(_(" -p[N] Open N tab pages (default: one per file)\n"));
- mch_msg(_(" -r, -L List swap files\n"));
- mch_msg(_(" -r <file> Recover edit state for this file\n"));
- mch_msg(_(" -R Read-only mode\n"));
- mch_msg(_(" -S <session> Source <session> after loading the first file\n"));
- mch_msg(_(" -s <scriptin> Read Normal mode commands from <scriptin>\n"));
- mch_msg(_(" -u <config> Use this config file\n"));
- mch_msg(_(" -v, --version Print version information\n"));
- mch_msg(_(" -V[N][file] Verbose [level][file]\n"));
- mch_msg("\n");
- mch_msg(_(" --api-info Write msgpack-encoded API metadata to stdout\n"));
- mch_msg(_(" --clean \"Factory defaults\" (skip user config and plugins, shada)\n"));
- mch_msg(_(" --embed Use stdin/stdout as a msgpack-rpc channel\n"));
- mch_msg(_(" --headless Don't start a user interface\n"));
- mch_msg(_(" --listen <address> Serve RPC API from this address\n"));
- mch_msg(_(" --noplugin Don't load plugins\n"));
- mch_msg(_(" --remote[-subcommand] Execute commands remotely on a server\n"));
- mch_msg(_(" --server <address> Specify RPC server to send commands to\n"));
- mch_msg(_(" --startuptime <file> Write startup timing messages to <file>\n"));
- mch_msg(_("\nSee \":help startup-options\" for all options.\n"));
+ os_msg(_("Usage:\n"));
+ os_msg(_(" nvim [options] [file ...] Edit file(s)\n"));
+ os_msg(_(" nvim [options] -t <tag> Edit file where tag is defined\n"));
+ os_msg(_(" nvim [options] -q [errorfile] Edit file with first error\n"));
+ os_msg(_("\nOptions:\n"));
+ os_msg(_(" -- Only file names after this\n"));
+ os_msg(_(" + Start at end of file\n"));
+ os_msg(_(" --cmd <cmd> Execute <cmd> before any config\n"));
+ os_msg(_(" +<cmd>, -c <cmd> Execute <cmd> after config and first file\n"));
+ os_msg("\n");
+ os_msg(_(" -b Binary mode\n"));
+ os_msg(_(" -d Diff mode\n"));
+ os_msg(_(" -e, -E Ex mode\n"));
+ os_msg(_(" -es, -Es Silent (batch) mode\n"));
+ os_msg(_(" -h, --help Print this help message\n"));
+ os_msg(_(" -i <shada> Use this shada file\n"));
+ os_msg(_(" -m Modifications (writing files) not allowed\n"));
+ os_msg(_(" -M Modifications in text not allowed\n"));
+ os_msg(_(" -n No swap file, use memory only\n"));
+ os_msg(_(" -o[N] Open N windows (default: one per file)\n"));
+ os_msg(_(" -O[N] Open N vertical windows (default: one per file)\n"));
+ os_msg(_(" -p[N] Open N tab pages (default: one per file)\n"));
+ os_msg(_(" -r, -L List swap files\n"));
+ os_msg(_(" -r <file> Recover edit state for this file\n"));
+ os_msg(_(" -R Read-only mode\n"));
+ os_msg(_(" -S <session> Source <session> after loading the first file\n"));
+ os_msg(_(" -s <scriptin> Read Normal mode commands from <scriptin>\n"));
+ os_msg(_(" -u <config> Use this config file\n"));
+ os_msg(_(" -v, --version Print version information\n"));
+ os_msg(_(" -V[N][file] Verbose [level][file]\n"));
+ os_msg("\n");
+ os_msg(_(" --api-info Write msgpack-encoded API metadata to stdout\n"));
+ os_msg(_(" --clean \"Factory defaults\" (skip user config and plugins, shada)\n"));
+ os_msg(_(" --embed Use stdin/stdout as a msgpack-rpc channel\n"));
+ os_msg(_(" --headless Don't start a user interface\n"));
+ os_msg(_(" --listen <address> Serve RPC API from this address\n"));
+ os_msg(_(" --noplugin Don't load plugins\n"));
+ os_msg(_(" --remote[-subcommand] Execute commands remotely on a server\n"));
+ os_msg(_(" --server <address> Specify RPC server to send commands to\n"));
+ os_msg(_(" --startuptime <file> Write startup timing messages to <file>\n"));
+ os_msg(_("\nSee \":help startup-options\" for all options.\n"));
}
// Check the result of the ATTENTION dialog:
diff --git a/src/nvim/main.h b/src/nvim/main.h
index 780022a9b1..4cf8dfe026 100644
--- a/src/nvim/main.h
+++ b/src/nvim/main.h
@@ -42,6 +42,9 @@ typedef struct {
char *listen_addr; // --listen {address}
int remote; // --remote-[subcmd] {file1} {file2}
char *server_addr; // --server {address}
+ char *scriptin; // -s {filename}
+ char *scriptout; // -w/-W {filename}
+ bool scriptout_append; // append (-w) instead of overwrite (-W)
} mparm_T;
#ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c
index 07f6a211e4..3522e0de36 100644
--- a/src/nvim/mapping.c
+++ b/src/nvim/mapping.c
@@ -158,7 +158,7 @@ static void showmap(mapblock_T *mp, bool local)
{
size_t len = 1;
- if (message_filtered((char *)mp->m_keys) && message_filtered(mp->m_str)
+ if (message_filtered(mp->m_keys) && message_filtered(mp->m_str)
&& (mp->m_desc == NULL || message_filtered(mp->m_desc))) {
return;
}
@@ -182,7 +182,7 @@ static void showmap(mapblock_T *mp, bool local)
}
// Display the LHS. Get length of what we write.
- len = (size_t)msg_outtrans_special((char *)mp->m_keys, true, 0);
+ len = (size_t)msg_outtrans_special(mp->m_keys, true, 0);
do {
msg_putchar(' '); // pad with blanks
len++;
@@ -462,7 +462,7 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table,
}
}
- mp->m_keys = (uint8_t *)xstrdup(keys);
+ mp->m_keys = xstrdup(keys);
mp->m_str = args->rhs;
mp->m_orig_str = (char *)args->orig_rhs;
mp->m_luaref = args->rhs_lua;
@@ -471,7 +471,7 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table,
args->orig_rhs = NULL;
args->rhs_lua = LUA_NOREF;
}
- mp->m_keylen = (int)strlen((char *)mp->m_keys);
+ mp->m_keylen = (int)strlen(mp->m_keys);
mp->m_noremap = noremap;
mp->m_nowait = args->nowait;
mp->m_silent = args->silent;
@@ -497,7 +497,7 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table,
mp->m_next = *abbr_table;
*abbr_table = mp;
} else {
- const int n = MAP_HASH(mp->m_mode, mp->m_keys[0]);
+ const int n = MAP_HASH(mp->m_mode, (uint8_t)mp->m_keys[0]);
mp->m_next = map_table[n];
map_table[n] = mp;
}
@@ -516,7 +516,7 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table,
static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T *buf)
{
mapblock_T *mp, **mpp;
- const char_u *p;
+ const char *p;
int n;
int retval = 0;
mapblock_T **abbr_table;
@@ -553,7 +553,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
goto theend;
}
- const char_u *lhs = (char_u *)&args->lhs;
+ const char *lhs = (char *)&args->lhs;
const bool did_simplify = args->alt_lhs_len != 0;
// The following is done twice if we have two versions of keys
@@ -567,11 +567,11 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
if (!did_simplify) {
break;
}
- lhs = (char_u *)&args->alt_lhs;
+ lhs = (char *)&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;
+ lhs = (char *)&args->alt_lhs;
len = (int)args->alt_lhs_len;
}
@@ -589,13 +589,13 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
// vi-compatible way.
int same = -1;
- const int first = vim_iswordp(lhs);
+ const int first = vim_iswordp((char_u *)lhs);
int last = first;
- p = lhs + utfc_ptr2len((char *)lhs);
+ p = (char *)lhs + utfc_ptr2len((char *)lhs);
n = 1;
- while (p < lhs + len) {
+ while (p < (char *)lhs + len) {
n++; // nr of (multi-byte) chars
- last = vim_iswordp(p); // type of last char
+ last = vim_iswordp((char_u *)p); // type of last char
if (same == -1 && last != first) {
same = n - 1; // count of same char type
}
@@ -640,7 +640,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
// check entries with the same mode
if ((mp->m_mode & mode) != 0
&& mp->m_keylen == len
- && STRNCMP(mp->m_keys, lhs, (size_t)len) == 0) {
+ && strncmp(mp->m_keys, lhs, (size_t)len) == 0) {
if (is_abbrev) {
semsg(_("E224: global abbreviation already exists for %s"),
mp->m_keys);
@@ -674,7 +674,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
did_local = true;
} else {
n = mp->m_keylen;
- if (STRNCMP(mp->m_keys, lhs, (size_t)(n < len ? n : len)) == 0) {
+ if (strncmp(mp->m_keys, lhs, (size_t)(n < len ? n : len)) == 0) {
showmap(mp, true);
did_local = true;
}
@@ -695,7 +695,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
int hash_start, hash_end;
if (has_lhs || is_abbrev) {
// just use one hash
- hash_start = is_abbrev ? 0 : MAP_HASH(mode, lhs[0]);
+ hash_start = is_abbrev ? 0 : MAP_HASH(mode, (uint8_t)lhs[0]);
hash_end = hash_start + 1;
} else {
// need to loop over all hash lists
@@ -718,12 +718,12 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
} else { // do we have a match?
if (round) { // second round: Try unmap "rhs" string
n = (int)strlen(mp->m_str);
- p = (char_u *)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 (strncmp(p, lhs, (size_t)(n < len ? n : len)) == 0) {
if (maptype == MAPTYPE_UNMAP) {
// Delete entry.
// Only accept a full match. For abbreviations
@@ -805,7 +805,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
}
// May need to put this entry into another hash list.
- int new_hash = MAP_HASH(mp->m_mode, mp->m_keys[0]);
+ int new_hash = MAP_HASH(mp->m_mode, (uint8_t)mp->m_keys[0]);
if (!is_abbrev && new_hash != hash) {
*mpp = mp->m_next;
mp->m_next = map_table[new_hash];
@@ -1032,7 +1032,7 @@ void map_clear_mode(buf_T *buf, int mode, bool local, bool abbr)
continue;
}
// May need to put this entry into another hash list.
- new_hash = MAP_HASH(mp->m_mode, mp->m_keys[0]);
+ new_hash = MAP_HASH(mp->m_mode, (uint8_t)mp->m_keys[0]);
if (!abbr && new_hash != hash) {
*mpp = mp->m_next;
if (local) {
@@ -1325,7 +1325,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char ***file)
}
for (; mp; mp = mp->m_next) {
if (mp->m_mode & expand_mapmodes) {
- p = (char *)translate_mapping(mp->m_keys, CPO_TO_CPO_FLAGS);
+ p = (char *)translate_mapping((char_u *)mp->m_keys, CPO_TO_CPO_FLAGS);
if (p != NULL && vim_regexec(regmatch, p, (colnr_T)0)) {
if (round == 1) {
count++;
@@ -1387,7 +1387,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char ***file)
// Then there must be white space before the abbr.
//
// Return true if there is an abbreviation, false if not.
-bool check_abbr(int c, char_u *ptr, int col, int mincol)
+bool check_abbr(int c, char *ptr, int col, int mincol)
{
int len;
int scol; // starting column of the abbr.
@@ -1418,25 +1418,25 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol)
{
bool vim_abbr;
- char_u *p = mb_prevptr(ptr, ptr + col);
+ char_u *p = mb_prevptr((char_u *)ptr, (char_u *)ptr + col);
if (!vim_iswordp(p)) {
vim_abbr = true; // Vim added abbr.
} else {
vim_abbr = false; // vi compatible abbr.
- if (p > ptr) {
- is_id = vim_iswordp(mb_prevptr(ptr, p));
+ if (p > (char_u *)ptr) {
+ is_id = vim_iswordp(mb_prevptr((char_u *)ptr, p));
}
}
clen = 1;
- while (p > ptr + mincol) {
- p = mb_prevptr(ptr, p);
+ while (p > (char_u *)ptr + mincol) {
+ p = mb_prevptr((char_u *)ptr, p);
if (ascii_isspace(*p) || (!vim_abbr && is_id != vim_iswordp(p))) {
p += utfc_ptr2len((char *)p);
break;
}
clen++;
}
- scol = (int)(p - ptr);
+ scol = (int)(p - (char_u *)ptr);
}
if (scol < mincol) {
@@ -1455,20 +1455,20 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol)
mp->m_next == NULL ? (mp = mp2, mp2 = NULL) :
(mp = mp->m_next)) {
int qlen = mp->m_keylen;
- char *q = (char *)mp->m_keys;
+ char *q = mp->m_keys;
int match;
if (strchr((const char *)mp->m_keys, K_SPECIAL) != NULL) {
// Might have K_SPECIAL escaped mp->m_keys.
- q = xstrdup((char *)mp->m_keys);
+ q = xstrdup(mp->m_keys);
vim_unescape_ks((char_u *)q);
qlen = (int)strlen(q);
}
// find entries with right mode and keys
match = (mp->m_mode & State)
&& qlen == len
- && !STRNCMP(q, ptr, (size_t)len);
- if (q != (char *)mp->m_keys) {
+ && !strncmp(q, ptr, (size_t)len);
+ if (q != mp->m_keys) {
xfree(q);
}
if (match) {
@@ -1797,7 +1797,7 @@ int makemap(FILE *fd, buf_T *buf)
}
if (putc(' ', fd) < 0
- || put_escstr(fd, mp->m_keys, 0) == FAIL
+ || put_escstr(fd, (char_u *)mp->m_keys, 0) == FAIL
|| putc(' ', fd) < 0
|| put_escstr(fd, (char_u *)mp->m_str, 1) == FAIL
|| put_eol(fd) < 0) {
@@ -1954,15 +1954,15 @@ char *check_map(char *keys, int mode, int exact, int ign_mod, int abbr, mapblock
for (; mp != NULL; mp = mp->m_next) {
// skip entries with wrong mode, wrong length and not matching ones
if ((mp->m_mode & mode) && (!exact || mp->m_keylen == len)) {
- char_u *s = mp->m_keys;
+ char *s = mp->m_keys;
int keylen = mp->m_keylen;
if (ign_mod && keylen >= 3
- && s[0] == K_SPECIAL && s[1] == KS_MODIFIER) {
+ && (uint8_t)s[0] == K_SPECIAL && (uint8_t)s[1] == KS_MODIFIER) {
s += 3;
keylen -= 3;
}
minlen = keylen < len ? keylen : len;
- if (STRNCMP(s, keys, minlen) == 0) {
+ if (strncmp(s, keys, (size_t)minlen) == 0) {
if (mp_ptr != NULL) {
*mp_ptr = mp;
}
@@ -2015,7 +2015,7 @@ static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhs
FUNC_ATTR_NONNULL_ARG(1)
{
Dictionary dict = ARRAY_DICT_INIT;
- char *const lhs = str2special_save((const char *)mp->m_keys, compatible, !compatible);
+ char *const lhs = str2special_save(mp->m_keys, compatible, !compatible);
char *const mapmode = map_mode_to_chars(mp->m_mode);
varnumber_T noremap_value;
diff --git a/src/nvim/memory.c b/src/nvim/memory.c
index 8bc871344c..a65f45c012 100644
--- a/src/nvim/memory.c
+++ b/src/nvim/memory.c
@@ -14,6 +14,7 @@
#include "nvim/api/extmark.h"
#include "nvim/arglist.h"
#include "nvim/ascii.h"
+#include "nvim/buffer_updates.h"
#include "nvim/context.h"
#include "nvim/decoration_provider.h"
#include "nvim/eval.h"
@@ -121,8 +122,8 @@ void *xmalloc(size_t size)
{
void *ret = try_malloc(size);
if (!ret) {
- mch_errmsg(e_outofmem);
- mch_errmsg("\n");
+ os_errmsg(e_outofmem);
+ os_errmsg("\n");
preserve_exit();
}
return ret;
@@ -152,8 +153,8 @@ void *xcalloc(size_t count, size_t size)
try_to_free_memory();
ret = calloc(allocated_count, allocated_size);
if (!ret) {
- mch_errmsg(e_outofmem);
- mch_errmsg("\n");
+ os_errmsg(e_outofmem);
+ os_errmsg("\n");
preserve_exit();
}
}
@@ -174,8 +175,8 @@ void *xrealloc(void *ptr, size_t size)
try_to_free_memory();
ret = realloc(ptr, allocated_size);
if (!ret) {
- mch_errmsg(e_outofmem);
- mch_errmsg("\n");
+ os_errmsg(e_outofmem);
+ os_errmsg("\n");
preserve_exit();
}
}
@@ -194,7 +195,7 @@ void *xmallocz(size_t size)
{
size_t total_size = size + 1;
if (total_size < size) {
- mch_errmsg(_("Vim: Data too large to fit into virtual memory space\n"));
+ os_errmsg(_("Vim: Data too large to fit into virtual memory space\n"));
preserve_exit();
}
@@ -812,6 +813,11 @@ void free_all_mem(void)
bufref_T bufref;
set_bufref(&bufref, buf);
nextbuf = buf->b_next;
+
+ // Since options (in addition to other stuff) have been freed above we need to ensure no
+ // callbacks are called, so free them before closing the buffer.
+ buf_free_callbacks(buf);
+
close_buffer(NULL, buf, DOBUF_WIPE, false, false);
// Didn't work, try next one.
buf = bufref_valid(&bufref) ? nextbuf : firstbuf;
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 81adca8b1c..041e5ed6c3 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -214,7 +214,7 @@ void msg_grid_validate(void)
}
/// Displays the string 's' on the status line
-/// When terminal not initialized (yet) mch_errmsg(..) is used.
+/// When terminal not initialized (yet) os_errmsg(..) is used.
///
/// @return true if wait_return() not called
int msg(char *s)
@@ -764,7 +764,7 @@ static bool emsg_multiline(const char *s, bool multiline)
/// emsg() - display an error message
///
/// Rings the bell, if appropriate, and calls message() to do the real work
-/// When terminal not initialized (yet) mch_errmsg(..) is used.
+/// When terminal not initialized (yet) os_errmsg(..) is used.
///
/// @return true if wait_return() not called
bool emsg(const char *s)
@@ -2726,9 +2726,9 @@ static void msg_puts_printf(const char *str, const ptrdiff_t maxlen)
memcpy(p, s, (size_t)len);
*(p + len) = '\0';
if (info_message) {
- mch_msg(buf);
+ os_msg(buf);
} else {
- mch_errmsg(buf);
+ os_errmsg(buf);
}
}
@@ -3003,7 +3003,7 @@ static int do_more_prompt(int typed_char)
}
#if defined(MSWIN)
-void mch_errmsg(char *str)
+void os_errmsg(char *str)
{
assert(str != NULL);
wchar_t *utf16str;
@@ -3017,7 +3017,7 @@ void mch_errmsg(char *str)
}
/// Give a message. To be used when the UI is not initialized yet.
-void mch_msg(char *str)
+void os_msg(char *str)
{
assert(str != NULL);
wchar_t *utf16str;
diff --git a/src/nvim/move.c b/src/nvim/move.c
index 60d2506e70..227e19bca3 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -937,41 +937,39 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp,
bool existing_row = (pos->lnum > 0
&& pos->lnum <= wp->w_buffer->b_ml.ml_line_count);
- if (is_folded) {
- row += local ? 0 : wp->w_winrow + wp->w_winrow_off;
- coloff = (local ? 0 : wp->w_wincol + wp->w_wincol_off) + 1;
- } else if ((local || visible_row) && existing_row) {
- colnr_T off;
- colnr_T col;
- int width;
-
- getvcol(wp, pos, &scol, &ccol, &ecol);
-
- // similar to what is done in validate_cursor_col()
- col = scol;
- off = win_col_off(wp);
- col += off;
- width = wp->w_width - off + win_col_off2(wp);
-
- // long line wrapping, adjust row
- if (wp->w_p_wrap && col >= (colnr_T)wp->w_width && width > 0) {
- // use same formula as what is used in curs_columns()
- rowoff = visible_row ? ((col - wp->w_width) / width + 1) : 0;
- col -= rowoff * width;
- }
-
- col -= wp->w_leftcol;
-
- if (col >= 0 && col < wp->w_width && row + rowoff <= wp->w_height) {
- coloff = col - scol + (local ? 0 : wp->w_wincol + wp->w_wincol_off) + 1;
+ if ((local || visible_row) && existing_row) {
+ const colnr_T off = win_col_off(wp);
+ if (is_folded) {
row += local ? 0 : wp->w_winrow + wp->w_winrow_off;
+ coloff = (local ? 0 : wp->w_wincol + wp->w_wincol_off) + 1 + off;
} else {
- // character is left, right or below of the window
- scol = ccol = ecol = 0;
- if (local) {
- coloff = col < 0 ? -1 : wp->w_width_inner + 1;
+ getvcol(wp, pos, &scol, &ccol, &ecol);
+
+ // similar to what is done in validate_cursor_col()
+ colnr_T col = scol;
+ col += off;
+ int width = wp->w_width - off + win_col_off2(wp);
+
+ // long line wrapping, adjust row
+ if (wp->w_p_wrap && col >= (colnr_T)wp->w_width && width > 0) {
+ // use same formula as what is used in curs_columns()
+ rowoff = visible_row ? ((col - wp->w_width) / width + 1) : 0;
+ col -= rowoff * width;
+ }
+
+ col -= wp->w_leftcol;
+
+ if (col >= 0 && col < wp->w_width && row + rowoff <= wp->w_height) {
+ coloff = col - scol + (local ? 0 : wp->w_wincol + wp->w_wincol_off) + 1;
+ row += local ? 0 : wp->w_winrow + wp->w_winrow_off;
} else {
- row = rowoff = 0;
+ // character is left, right or below of the window
+ scol = ccol = ecol = 0;
+ if (local) {
+ coloff = col < 0 ? -1 : wp->w_width_inner + 1;
+ } else {
+ row = rowoff = 0;
+ }
}
}
}
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index dac7e6f90b..d6fa1f5a16 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -2751,7 +2751,7 @@ static int nv_zg_zw(cmdarg_T *cap, int nchar)
return FAIL;
}
assert(len <= INT_MAX);
- spell_add_word((char_u *)ptr, (int)len,
+ spell_add_word(ptr, (int)len,
nchar == 'w' || nchar == 'W' ? SPELL_ADD_BAD : SPELL_ADD_GOOD,
(nchar == 'G' || nchar == 'W') ? 0 : (int)cap->count1,
undo);
diff --git a/src/nvim/option.c b/src/nvim/option.c
index b1feac7d1b..1a6707f128 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -560,9 +560,7 @@ static char *find_dup_item(char *origval, const char *newval, uint32_t flags)
/// Used for 'lines' and 'columns'.
void set_number_default(char *name, long val)
{
- int opt_idx;
-
- opt_idx = findoption(name);
+ int opt_idx = findoption(name);
if (opt_idx >= 0) {
options[opt_idx].def_val = (char *)(intptr_t)val;
}
@@ -726,12 +724,10 @@ void set_helplang_default(const char *lang)
/// machine.
void set_title_defaults(void)
{
- int idx1;
-
// If GUI is (going to be) used, we can always set the window title and
// icon name. Saves a bit of time, because the X11 display server does
// not need to be contacted.
- idx1 = findoption("title");
+ int idx1 = findoption("title");
if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) {
options[idx1].def_val = 0;
p_title = 0;
@@ -770,7 +766,6 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar,
char *save_arg = NULL;
char *s = NULL;
char_u *oldval = NULL; // previous value if *varp
- char *newval;
char *origval = NULL;
char_u *origval_l = NULL;
char_u *origval_g = NULL;
@@ -778,8 +773,6 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar,
char *saved_origval_l = NULL;
char *saved_origval_g = NULL;
char *saved_newval = NULL;
- unsigned newlen;
- int comma;
char whichwrap[80];
// When using ":set opt=val" for a global option
@@ -812,6 +805,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar,
origval = (char *)oldval;
}
+ char *newval;
if (nextchar == '&') { // set to default val
newval = options[opt_idx].def_val;
// expand environment variables and ~ since the default value was
@@ -903,9 +897,9 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar,
// backslashes.
// get a bit too much
- newlen = (unsigned)strlen(arg) + 1;
+ size_t newlen = strlen(arg) + 1;
if (op != OP_NONE) {
- newlen += (unsigned)strlen(origval) + 1;
+ newlen += strlen(origval) + 1;
}
newval = xmalloc(newlen);
s = newval;
@@ -975,7 +969,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar,
// concatenate the two strings; add a ',' if needed
if (op == OP_ADDING || op == OP_PREPENDING) {
- comma = ((flags & P_COMMA) && *origval != NUL && *newval != NUL);
+ int comma = ((flags & P_COMMA) && *origval != NUL && *newval != NUL);
if (op == OP_ADDING) {
len = (int)strlen(origval);
// Strip a trailing comma, would get 2.
@@ -1118,21 +1112,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar,
/// @return FAIL if an error is detected, OK otherwise
int do_set(char *arg, int opt_flags)
{
- int opt_idx;
- char *errmsg;
- char errbuf[80];
- char *startarg;
- int prefix; // 1: nothing, 0: "no", 2: "inv" in front of name
- char_u nextchar; // next non-white char after option name
- int afterchar; // character just after option name
- int len;
- int i;
- varnumber_T value;
- int key;
- uint32_t flags; // flags for current option
- char *varp = NULL; // pointer to variable for current option
int did_show = false; // already showed one value
- set_op_T op = 0;
if (*arg == NUL) {
showoptions(0, opt_flags);
@@ -1140,9 +1120,11 @@ int do_set(char *arg, int opt_flags)
goto theend;
}
+ char errbuf[80];
+
while (*arg != NUL) { // loop to process all options
- errmsg = NULL;
- startarg = arg; // remember for error message
+ char *errmsg = NULL;
+ char *startarg = arg; // remember for error message
if (strncmp(arg, "all", 3) == 0 && !isalpha(arg[3])
&& !(opt_flags & OPT_MODELINE)) {
@@ -1162,7 +1144,7 @@ int do_set(char *arg, int opt_flags)
did_show = true;
}
} else {
- prefix = 1;
+ int prefix = 1; // 1: nothing, 0: "no", 2: "inv" in front of name
if (strncmp(arg, "no", 2) == 0) {
prefix = 0;
arg += 2;
@@ -1172,7 +1154,9 @@ int do_set(char *arg, int opt_flags)
}
// find end of name
- key = 0;
+ int key = 0;
+ int len;
+ int opt_idx;
if (*arg == '<') {
opt_idx = -1;
// look out for <t_>;>
@@ -1212,14 +1196,14 @@ int do_set(char *arg, int opt_flags)
}
// remember character after option name
- afterchar = (uint8_t)arg[len];
+ int afterchar = (uint8_t)arg[len];
// skip white space, allow ":set ai ?"
while (ascii_iswhite(arg[len])) {
len++;
}
- op = OP_NONE;
+ set_op_T op = OP_NONE;
if (arg[len] != NUL && arg[len + 1] == '=') {
if (arg[len] == '+') {
op = OP_ADDING; // "+="
@@ -1232,13 +1216,16 @@ int do_set(char *arg, int opt_flags)
len++;
}
}
- nextchar = (uint8_t)arg[len];
+ char_u nextchar = (uint8_t)arg[len]; // next non-white char after option name
if (opt_idx == -1 && key == 0) { // found a mismatch: skip
errmsg = e_unknown_option;
goto skip;
}
+ uint32_t flags; // flags for current option
+ char *varp = NULL; // pointer to variable for current option
+
if (opt_idx >= 0) {
if (options[opt_idx].var == NULL) { // hidden option: skip
// Only give an error message when requesting the value of
@@ -1352,6 +1339,7 @@ int do_set(char *arg, int opt_flags)
}
} else {
int value_checked = false;
+ varnumber_T value;
if (flags & P_BOOL) { // boolean
if (nextchar == '=' || nextchar == ':') {
@@ -1428,6 +1416,7 @@ int do_set(char *arg, int opt_flags)
goto skip;
}
} else if (*arg == '-' || ascii_isdigit(*arg)) {
+ int i;
// Allow negative, octal and hex numbers.
vim_str2nr(arg, NULL, &i, STR2NR_ALL, &value, NULL, 0, true);
if (i == 0 || (arg[i] != NUL && !ascii_iswhite(arg[i]))) {
@@ -1476,7 +1465,7 @@ skip:
// - skip until a blank found, taking care of backslashes
// - skip blanks
// - skip one "=val" argument (for hidden options ":set gfn =xx")
- for (i = 0; i < 2; i++) {
+ for (int i = 0; i < 2; i++) {
while (*arg != NUL && !ascii_iswhite(*arg)) {
if (*arg++ == '\\' && *arg != NUL) {
arg++;
@@ -1491,7 +1480,7 @@ skip:
if (errmsg != NULL) {
STRLCPY(IObuff, _(errmsg), IOSIZE);
- i = (int)strlen(IObuff) + 2;
+ int i = (int)strlen(IObuff) + 2;
if (i + (arg - startarg) < IOSIZE) {
// append the argument with the error
STRCAT(IObuff, ": ");
@@ -1516,11 +1505,11 @@ theend:
if (silent_mode && did_show) {
// After displaying option values in silent mode.
silent_mode = false;
- info_message = true; // use mch_msg(), not mch_errmsg()
+ info_message = true; // use os_msg(), not os_errmsg()
msg_putchar('\n');
ui_flush();
silent_mode = true;
- info_message = false; // use mch_msg(), not mch_errmsg()
+ info_message = false; // use os_msg(), not os_errmsg()
}
return OK;
@@ -1632,9 +1621,7 @@ void set_options_bin(int oldval, int newval, int opt_flags)
/// number, return -1.
int get_shada_parameter(int type)
{
- char_u *p;
-
- p = find_shada_parameter(type);
+ char_u *p = find_shada_parameter(type);
if (p != NULL && ascii_isdigit(*p)) {
return atoi((char *)p);
}
@@ -2661,14 +2648,13 @@ void check_redraw(uint32_t flags)
int findoption_len(const char *const arg, const size_t len)
{
const char *s;
- const char *p;
static int quick_tab[27] = { 0, 0 }; // quick access table
// For first call: Initialize the quick-access table.
// It contains the index for the first option that starts with a certain
// letter. There are 26 letters, plus the first "t_" option.
if (quick_tab[1] == 0) {
- p = options[0].fullname;
+ const char *p = options[0].fullname;
for (uint16_t i = 1; (s = options[i].fullname) != NULL; i++) {
if (s[0] != p[0]) {
if (s[0] == 't' && s[1] == '_') {
@@ -3033,10 +3019,7 @@ char *set_option_value(const char *const name, const long number, const char *co
return NULL; // Fail silently; many old vimrcs set t_xx options.
}
- int opt_idx;
- char_u *varp;
-
- opt_idx = findoption(name);
+ int opt_idx = findoption(name);
if (opt_idx < 0) {
semsg(_("E355: Unknown option: %s"), name);
} else {
@@ -3054,7 +3037,7 @@ char *set_option_value(const char *const name, const long number, const char *co
return set_string_option(opt_idx, s, opt_flags);
}
- varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags);
+ char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags);
if (varp != NULL) { // hidden option is not changed
if (number == 0 && string != NULL) {
int idx;
@@ -3125,16 +3108,15 @@ bool is_string_option(const char *name)
int find_key_option_len(const char_u *arg_arg, size_t len, bool has_lt)
{
int key = 0;
- int modifiers;
- const char_u *arg = arg_arg;
+ const char *arg = (char *)arg_arg;
// Don't use get_special_key_code() for t_xx, we don't want it to call
// add_termcap_entry().
if (len >= 4 && arg[0] == 't' && arg[1] == '_') {
- key = TERMCAP2KEY(arg[2], arg[3]);
+ key = TERMCAP2KEY((uint8_t)arg[2], (uint8_t)arg[3]);
} else if (has_lt) {
arg--; // put arg at the '<'
- modifiers = 0;
+ int modifiers = 0;
key = find_special_key(&arg, len + 1, &modifiers,
FSK_KEYCODE | FSK_KEEP_X_KEY | FSK_SIMPLIFY, NULL);
if (modifiers) { // can't handle modifiers here
@@ -3155,16 +3137,6 @@ static int find_key_option(const char *arg, bool has_lt)
/// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL
static void showoptions(int all, int opt_flags)
{
- vimoption_T *p;
- int col;
- char_u *varp;
- int item_count;
- int run;
- int row, rows;
- int cols;
- int i;
- int len;
-
#define INC 20
#define GAP 3
@@ -3183,16 +3155,16 @@ static void showoptions(int all, int opt_flags)
// 1. display the short items
// 2. display the long items (only strings and numbers)
// When "opt_flags" has OPT_ONECOLUMN do everything in run 2.
- for (run = 1; run <= 2 && !got_int; run++) {
+ for (int run = 1; run <= 2 && !got_int; run++) {
// collect the items in items[]
- item_count = 0;
- for (p = &options[0]; p->fullname != NULL; p++) {
+ int item_count = 0;
+ for (vimoption_T *p = &options[0]; p->fullname != NULL; p++) {
// apply :filter /pat/
if (message_filtered(p->fullname)) {
continue;
}
- varp = NULL;
+ char_u *varp = NULL;
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) != 0) {
if (p->indir != PV_NONE) {
varp = (char_u *)get_varp_scope(p, opt_flags);
@@ -3202,6 +3174,7 @@ static void showoptions(int all, int opt_flags)
}
if (varp != NULL
&& (all == 1 || (all == 0 && !optval_default(p, varp)))) {
+ int len;
if (opt_flags & OPT_ONECOLUMN) {
len = Columns;
} else if (p->flags & P_BOOL) {
@@ -3217,13 +3190,15 @@ static void showoptions(int all, int opt_flags)
}
}
+ int rows;
+
// display the items
if (run == 1) {
assert(Columns <= INT_MAX - GAP
&& Columns + GAP >= INT_MIN + 3
&& (Columns + GAP - 3) / INC >= INT_MIN
&& (Columns + GAP - 3) / INC <= INT_MAX);
- cols = (Columns + GAP - 3) / INC;
+ int cols = (Columns + GAP - 3) / INC;
if (cols == 0) {
cols = 1;
}
@@ -3231,13 +3206,13 @@ static void showoptions(int all, int opt_flags)
} else { // run == 2
rows = item_count;
}
- for (row = 0; row < rows && !got_int; row++) {
+ for (int row = 0; row < rows && !got_int; row++) {
msg_putchar('\n'); // go to next line
if (got_int) { // 'q' typed in more
break;
}
- col = 0;
- for (i = row; i < item_count; i += rows) {
+ int col = 0;
+ for (int i = row; i < item_count; i += rows) {
msg_col = col; // make columns
showoneopt(items[i], opt_flags);
col += INC;
@@ -3299,7 +3274,7 @@ static void showoneopt(vimoption_T *p, int opt_flags)
int save_silent = silent_mode;
silent_mode = false;
- info_message = true; // use mch_msg(), not mch_errmsg()
+ info_message = true; // use os_msg(), not os_errmsg()
char_u *varp = (char_u *)get_varp_scope(p, opt_flags);
@@ -3346,14 +3321,6 @@ static void showoneopt(vimoption_T *p, int opt_flags)
/// Return FAIL on error, OK otherwise.
int makeset(FILE *fd, int opt_flags, int local_only)
{
- vimoption_T *p;
- char *varp; // currently used value
- char_u *varp_fresh; // local value
- char_u *varp_local = NULL; // fresh value
- char *cmd;
- int round;
- int pri;
-
// Some options are never written:
// - Options that don't have a default (terminal name, columns, lines).
// - Terminal options.
@@ -3361,8 +3328,8 @@ int makeset(FILE *fd, int opt_flags, int local_only)
//
// Do the loop over "options[]" twice: once for options with the
// P_PRI_MKRC flag and once without.
- for (pri = 1; pri >= 0; pri--) {
- for (p = &options[0]; p->fullname; p++) {
+ for (int pri = 1; pri >= 0; pri--) {
+ for (vimoption_T *p = &options[0]; p->fullname; p++) {
if (!(p->flags & P_NO_MKRC)
&& ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0))) {
// skip global option when only doing locals
@@ -3376,7 +3343,7 @@ int makeset(FILE *fd, int opt_flags, int local_only)
continue;
}
- varp = get_varp_scope(p, opt_flags);
+ char *varp = get_varp_scope(p, opt_flags); // currently used value
// Hidden options are never written.
if (!varp) {
continue;
@@ -3391,7 +3358,8 @@ int makeset(FILE *fd, int opt_flags, int local_only)
continue;
}
- round = 2;
+ int round = 2;
+ char_u *varp_local = NULL; // fresh value
if (p->indir != PV_NONE) {
if (p->var == VAR_WIN) {
// skip window-local option when only doing globals
@@ -3401,7 +3369,7 @@ int makeset(FILE *fd, int opt_flags, int local_only)
// When fresh value of window-local option is not at the
// default, need to write it too.
if (!(opt_flags & OPT_GLOBAL) && !local_only) {
- varp_fresh = (char_u *)get_varp_scope(p, OPT_GLOBAL);
+ char_u *varp_fresh = (char_u *)get_varp_scope(p, OPT_GLOBAL); // local value
if (!optval_default(p, varp_fresh)) {
round = 1;
varp_local = (char_u *)varp;
@@ -3414,6 +3382,7 @@ int makeset(FILE *fd, int opt_flags, int local_only)
// Round 1: fresh value for window-local options.
// Round 2: other values
for (; round <= 2; varp = (char *)varp_local, round++) {
+ char *cmd;
if (round == 1 || (opt_flags & OPT_GLOBAL)) {
cmd = "set";
} else {
@@ -3477,10 +3446,8 @@ int makefoldset(FILE *fd)
static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_t flags)
{
- char_u *s;
char_u *buf = NULL;
char_u *part = NULL;
- char *p;
if (fprintf(fd, "%s %s=", cmd, name) < 0) {
return FAIL;
@@ -3490,7 +3457,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_
// options some characters have to be escaped with
// CTRL-V or backslash
if (valuep == &p_pt) {
- s = (char_u *)(*valuep);
+ char_u *s = (char_u *)(*valuep);
while (*s != NUL) {
if (put_escstr(fd, (char_u *)str2special((const char **)&s, false, false), 2) == FAIL) {
return FAIL;
@@ -3514,7 +3481,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_
if (put_eol(fd) == FAIL) {
goto fail;
}
- p = (char *)buf;
+ char *p = (char *)buf;
while (*p != NUL) {
// for each comma separated option part, append value to
// the option, :set rtp+=value
@@ -4266,7 +4233,6 @@ void buf_copy_options(buf_T *buf, int flags)
{
int should_copy = true;
char_u *save_p_isk = NULL; // init for GCC
- int dont_do_help;
int did_isk = false;
// Skip this when the option defaults have not been set yet. Happens when
@@ -4297,7 +4263,7 @@ void buf_copy_options(buf_T *buf, int flags)
// Don't copy the options specific to a help buffer when
// BCO_NOHELP is given or the options were initialized already
// (jumping back to a help file with CTRL-T or CTRL-O)
- dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) || buf->b_p_initialized;
+ bool dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) || buf->b_p_initialized;
if (dont_do_help) { // don't free b_p_isk
save_p_isk = (char_u *)buf->b_p_isk;
buf->b_p_isk = NULL;
@@ -4567,13 +4533,10 @@ static int expand_option_flags = 0;
/// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL
void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
{
- char nextchar;
uint32_t flags = 0; // init for GCC
int opt_idx = 0; // init for GCC
char *p;
- char *s;
int is_term_option = false;
- int key;
expand_option_flags = opt_flags;
@@ -4588,7 +4551,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
return;
}
while (p > arg) {
- s = p;
+ char *s = p;
// count number of backslashes before ' ' or ','
if (*p == ' ' || *p == ',') {
while (s > arg && *(s - 1) == '\\') {
@@ -4612,13 +4575,16 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
}
xp->xp_pattern = p;
arg = p;
+
+ char nextchar;
+
if (*arg == '<') {
while (*p != '>') {
if (*p++ == NUL) { // expand terminal option name
return;
}
}
- key = get_special_key_code((char_u *)arg + 1);
+ int key = get_special_key_code((char_u *)arg + 1);
if (key == 0) { // unknown name
xp->xp_context = EXPAND_NOTHING;
return;
@@ -4721,7 +4687,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
for (p = arg + strlen(arg) - 1; p > xp->xp_pattern; p--) {
// count number of backslashes before ' ' or ','
if (*p == ' ' || *p == ',') {
- s = p;
+ char *s = p;
while (s > xp->xp_pattern && *(s - 1) == '\\') {
s--;
}
@@ -4744,17 +4710,15 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***file)
{
int num_normal = 0; // Nr of matching non-term-code settings
- int match;
int count = 0;
- char *str;
- int loop;
static char *(names[]) = { "all" };
int ic = regmatch->rm_ic; // remember the ignore-case flag
// do this loop twice:
// loop == 0: count the number of matching options
// loop == 1: copy the matching options into allocated memory
- for (loop = 0; loop <= 1; loop++) {
+ for (int loop = 0; loop <= 1; loop++) {
+ int match;
regmatch->rm_ic = ic;
if (xp->xp_context != EXPAND_BOOL_SETTINGS) {
for (match = 0; match < (int)ARRAY_SIZE(names);
@@ -4768,6 +4732,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi
}
}
}
+ char *str;
for (size_t opt_idx = 0; (str = options[opt_idx].fullname) != NULL;
opt_idx++) {
if (options[opt_idx].var == NULL) {
@@ -5090,15 +5055,12 @@ void reset_option_was_set(const char *name)
/// fill_breakat_flags() -- called when 'breakat' changes value.
void fill_breakat_flags(void)
{
- char_u *p;
- int i;
-
- for (i = 0; i < 256; i++) {
+ for (int i = 0; i < 256; i++) {
breakat_flags[i] = false;
}
if (p_breakat != NULL) {
- for (p = (char_u *)p_breakat; *p; p++) {
+ for (char_u *p = (char_u *)p_breakat; *p; p++) {
breakat_flags[*p] = true;
}
}
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 1cf8ab3253..3c2fb1797b 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -2690,7 +2690,7 @@ return {
full_name='verbose', abbreviation='vbs',
short_desc=N_("give informative messages"),
type='number', scope={'global'},
- varname='p_verbose',
+ varname='p_verbose', redraw={'ui_option'},
defaults={if_true=0}
},
{
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index d6afb1b62a..5d2ac1e102 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -266,7 +266,7 @@ size_t input_enqueue(String keys)
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, FSK_KEYCODE, true, NULL);
+ = trans_special((const char **)&ptr, (size_t)(end - ptr), buf, FSK_KEYCODE, true, NULL);
if (new_size) {
new_size = handle_mouse_event(&ptr, buf, new_size);
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index c1359d6ece..d647780847 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -144,7 +144,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in
bool is_fish_shell =
#if defined(UNIX)
- STRNCMP(invocation_path_tail((char_u *)p_sh, NULL), "fish", 4) == 0;
+ strncmp((char *)invocation_path_tail((char_u *)p_sh, NULL), "fish", 4) == 0;
#else
false;
#endif
diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c
index 1865d6789e..57dc2eb797 100644
--- a/src/nvim/os/users.c
+++ b/src/nvim/os/users.c
@@ -222,7 +222,7 @@ int match_user(char *name)
if (strcmp(((char **)ga_users.ga_data)[i], name) == 0) {
return 2; // full match
}
- if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) {
+ if (strncmp(((char **)ga_users.ga_data)[i], name, (size_t)n) == 0) {
result = 1; // partial match
}
}
diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c
index 3521703fba..074a8b7936 100644
--- a/src/nvim/os_unix.c
+++ b/src/nvim/os_unix.c
@@ -19,21 +19,21 @@
// Return a pointer to the ACL of file "fname" in allocated memory.
// Return NULL if the ACL is not available for whatever reason.
-vim_acl_T mch_get_acl(const char_u *fname)
+vim_acl_T os_get_acl(const char_u *fname)
{
vim_acl_T ret = NULL;
return ret;
}
// Set the ACL of file "fname" to "acl" (unless it's NULL).
-void mch_set_acl(const char_u *fname, vim_acl_T aclent)
+void os_set_acl(const char_u *fname, vim_acl_T aclent)
{
if (aclent == NULL) {
return;
}
}
-void mch_free_acl(vim_acl_T aclent)
+void os_free_acl(vim_acl_T aclent)
{
if (aclent == NULL) {
return;
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index 7335345161..aa5bcbc404 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -233,7 +233,7 @@ static int get_char_class(char **pp)
if ((*pp)[1] == ':') {
for (i = 0; i < (int)ARRAY_SIZE(class_names); i++) {
- if (STRNCMP(*pp + 2, class_names[i], strlen(class_names[i])) == 0) {
+ if (strncmp(*pp + 2, class_names[i], strlen(class_names[i])) == 0) {
*pp += strlen(class_names[i]) + 2;
return i;
}
@@ -1380,7 +1380,7 @@ static int cstrncmp(char *s1, char *s2, int *n)
int result;
if (!rex.reg_ic) {
- result = STRNCMP(s1, s2, *n);
+ result = strncmp(s1, s2, (size_t)(*n));
} else {
assert(*n >= 0);
result = mb_strnicmp(s1, s2, (size_t)(*n));
@@ -2303,12 +2303,12 @@ static char_u regname[][30] = {
regprog_T *vim_regcomp(char *expr_arg, int re_flags)
{
regprog_T *prog = NULL;
- char_u *expr = (char_u *)expr_arg;
+ char *expr = expr_arg;
regexp_engine = (int)p_re;
// Check for prefix "\%#=", that sets the regexp engine
- if (STRNCMP(expr, "\\%#=", 4) == 0) {
+ if (strncmp(expr, "\\%#=", 4) == 0) {
int newengine = expr[4] - '0';
if (newengine == AUTOMATIC_ENGINE
@@ -2338,10 +2338,10 @@ regprog_T *vim_regcomp(char *expr_arg, int re_flags)
//
const int called_emsg_before = called_emsg;
if (regexp_engine != BACKTRACKING_ENGINE) {
- prog = nfa_regengine.regcomp(expr,
+ prog = nfa_regengine.regcomp((char_u *)expr,
re_flags + (regexp_engine == AUTOMATIC_ENGINE ? RE_AUTO : 0));
} else {
- prog = bt_regengine.regcomp(expr, re_flags);
+ prog = bt_regengine.regcomp((char_u *)expr, re_flags);
}
// Check for error compiling regexp with initial engine.
@@ -2365,8 +2365,8 @@ regprog_T *vim_regcomp(char *expr_arg, int re_flags)
// But don't try if an error message was given.
if (regexp_engine == AUTOMATIC_ENGINE && called_emsg == called_emsg_before) {
regexp_engine = BACKTRACKING_ENGINE;
- report_re_switch(expr);
- prog = bt_regengine.regcomp(expr, re_flags);
+ report_re_switch((char_u *)expr);
+ prog = bt_regengine.regcomp((char_u *)expr, re_flags);
}
}
diff --git a/src/nvim/regexp_bt.c b/src/nvim/regexp_bt.c
index 19b89bef74..4e2fa54c26 100644
--- a/src/nvim/regexp_bt.c
+++ b/src/nvim/regexp_bt.c
@@ -3539,8 +3539,8 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
#ifdef REGEXP_DEBUG
if (scan != NULL && regnarrate) {
- mch_errmsg((char *)regprop(scan));
- mch_errmsg("(\n");
+ os_errmsg((char *)regprop(scan));
+ os_errmsg("(\n");
}
#endif
@@ -3566,18 +3566,18 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
#ifdef REGEXP_DEBUG
if (regnarrate) {
- mch_errmsg((char *)regprop(scan));
- mch_errmsg("...\n");
+ os_errmsg((char *)regprop(scan));
+ os_errmsg("...\n");
if (re_extmatch_in != NULL) {
int i;
- mch_errmsg(_("External submatches:\n"));
+ os_errmsg(_("External submatches:\n"));
for (i = 0; i < NSUBEXP; i++) {
- mch_errmsg(" \"");
+ os_errmsg(" \"");
if (re_extmatch_in->matches[i] != NULL) {
- mch_errmsg((char *)re_extmatch_in->matches[i]);
+ os_errmsg((char *)re_extmatch_in->matches[i]);
}
- mch_errmsg("\"\n");
+ os_errmsg("\"\n");
}
}
}
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 13a0526fd2..995522b51e 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -130,7 +130,7 @@ typedef struct matchinf_S {
langp_T *mi_lp; // info for language and region
// pointers to original text to be checked
- char_u *mi_word; // start of word being checked
+ char *mi_word; // start of word being checked
char_u *mi_end; // end of matching word so far
char_u *mi_fend; // next char to be added to mi_fword
char_u *mi_cend; // char after what was used for
@@ -173,7 +173,7 @@ typedef struct spelload_S {
#define SY_MAXLEN 30
typedef struct syl_item_S {
- char_u sy_chars[SY_MAXLEN]; // the sequence of chars
+ char sy_chars[SY_MAXLEN]; // the sequence of chars
int sy_len;
} syl_item_T;
@@ -252,7 +252,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou
}
// Find the normal end of the word (until the next non-word character).
- mi.mi_word = ptr;
+ mi.mi_word = (char *)ptr;
mi.mi_fend = ptr;
if (spell_iswordp(mi.mi_fend, wp)) {
bool this_upper = false; // init for gcc
@@ -387,7 +387,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou
// at which any word would be valid.
mi.mi_lp = LANGP_ENTRY(wp->w_s->b_langp, 0);
if (mi.mi_lp->lp_slang->sl_fidxs != NULL) {
- p = mi.mi_word;
+ p = (char_u *)mi.mi_word;
fp = (char_u *)mi.mi_fword;
for (;;) {
MB_PTR_ADV(p);
@@ -435,7 +435,7 @@ static void find_word(matchinf_T *mip, int mode)
{
int wlen = 0;
int flen;
- char_u *ptr;
+ char *ptr;
slang_T *slang = mip->mi_lp->lp_slang;
char_u *byts;
idx_T *idxs;
@@ -453,7 +453,7 @@ static void find_word(matchinf_T *mip, int mode)
}
} else {
// Check for case-folded in case-folded tree.
- ptr = (char_u *)mip->mi_fword;
+ ptr = mip->mi_fword;
flen = mip->mi_fwordlen; // available case-folded bytes
byts = slang->sl_fbyts;
idxs = slang->sl_fidxs;
@@ -518,7 +518,7 @@ static void find_word(matchinf_T *mip, int mode)
}
// Perform a binary search in the list of accepted bytes.
- c = ptr[wlen];
+ c = (uint8_t)ptr[wlen];
if (c == TAB) { // <Tab> is handled like <Space>
c = ' ';
}
@@ -562,7 +562,7 @@ static void find_word(matchinf_T *mip, int mode)
}
}
- char_u *p;
+ char *p;
bool word_ends;
// Verify that one of the possible endings is valid. Try the longest
@@ -572,10 +572,10 @@ static void find_word(matchinf_T *mip, int mode)
arridx = endidx[endidxcnt];
wlen = endlen[endidxcnt];
- if (utf_head_off((char *)ptr, (char *)ptr + wlen) > 0) {
+ if (utf_head_off(ptr, ptr + wlen) > 0) {
continue; // not at first byte of character
}
- if (spell_iswordp(ptr + wlen, mip->mi_win)) {
+ if (spell_iswordp((char_u *)ptr + wlen, mip->mi_win)) {
if (slang->sl_compprog == NULL && !slang->sl_nobreak) {
continue; // next char is a word character
}
@@ -592,8 +592,8 @@ static void find_word(matchinf_T *mip, int mode)
// when folding case. This can be slow, take a shortcut when the
// case-folded word is equal to the keep-case word.
p = mip->mi_word;
- if (STRNCMP(ptr, p, wlen) != 0) {
- for (char_u *s = ptr; s < ptr + wlen; MB_PTR_ADV(s)) {
+ if (strncmp(ptr, p, (size_t)wlen) != 0) {
+ for (char *s = ptr; s < ptr + wlen; MB_PTR_ADV(s)) {
MB_PTR_ADV(p);
}
wlen = (int)(p - mip->mi_word);
@@ -612,11 +612,11 @@ static void find_word(matchinf_T *mip, int mode)
// For keep-case tree the case is always right. For prefixes we
// don't bother to check.
if (mode == FIND_FOLDWORD) {
- if (mip->mi_cend != mip->mi_word + wlen) {
+ if (mip->mi_cend != (char_u *)mip->mi_word + wlen) {
// mi_capflags was set for a different word length, need
// to do it again.
- mip->mi_cend = mip->mi_word + wlen;
- mip->mi_capflags = captype(mip->mi_word, mip->mi_cend);
+ mip->mi_cend = (char_u *)mip->mi_word + wlen;
+ mip->mi_capflags = captype((char_u *)mip->mi_word, mip->mi_cend);
}
if (mip->mi_capflags == WF_KEEPCAP
@@ -629,7 +629,7 @@ static void find_word(matchinf_T *mip, int mode)
// mip->mi_prefarridx that find_prefix() filled.
c = valid_word_prefix(mip->mi_prefcnt, mip->mi_prefarridx,
(int)flags,
- mip->mi_word + mip->mi_cprefixlen, slang,
+ (char_u *)mip->mi_word + mip->mi_cprefixlen, slang,
false);
if (c == 0) {
continue;
@@ -664,7 +664,7 @@ static void find_word(matchinf_T *mip, int mode)
// For multi-byte chars check character length against
// COMPOUNDMIN.
if (slang->sl_compminlen > 0
- && mb_charlen_len(mip->mi_word + mip->mi_compoff,
+ && mb_charlen_len((char_u *)mip->mi_word + mip->mi_compoff,
wlen - mip->mi_compoff) < slang->sl_compminlen) {
continue;
}
@@ -703,16 +703,16 @@ static void find_word(matchinf_T *mip, int mode)
// Need to check the caps type of the appended compound
// word.
- if (STRNCMP(ptr, mip->mi_word, mip->mi_compoff) != 0) {
+ if (strncmp(ptr, mip->mi_word, (size_t)mip->mi_compoff) != 0) {
// case folding may have changed the length
p = mip->mi_word;
- for (char_u *s = ptr; s < ptr + mip->mi_compoff; MB_PTR_ADV(s)) {
+ for (char *s = ptr; s < ptr + mip->mi_compoff; MB_PTR_ADV(s)) {
MB_PTR_ADV(p);
}
} else {
p = mip->mi_word + mip->mi_compoff;
}
- capflags = captype(p, mip->mi_word + wlen);
+ capflags = captype((char_u *)p, (char_u *)mip->mi_word + wlen);
if (capflags == WF_KEEPCAP || (capflags == WF_ALLCAP
&& (flags & WF_FIXCAP) != 0)) {
continue;
@@ -724,7 +724,7 @@ static void find_word(matchinf_T *mip, int mode)
// accept a no-caps word, even when the dictionary
// word specifies ONECAP.
MB_PTR_BACK(mip->mi_word, p);
- if (spell_iswordp_nmw(p, mip->mi_win)
+ if (spell_iswordp_nmw((char_u *)p, mip->mi_win)
? capflags == WF_ONECAP
: (flags & WF_ONECAP) != 0
&& capflags != WF_ONECAP) {
@@ -744,7 +744,7 @@ static void find_word(matchinf_T *mip, int mode)
if (slang->sl_compsylmax < MAXWLEN) {
// "fword" is only needed for checking syllables.
if (ptr == mip->mi_word) {
- (void)spell_casefold(mip->mi_win, ptr, wlen, fword, MAXWLEN);
+ (void)spell_casefold(mip->mi_win, (char_u *)ptr, wlen, fword, MAXWLEN);
} else {
STRLCPY(fword, ptr, endlen[endidxcnt] + 1);
}
@@ -786,12 +786,12 @@ static void find_word(matchinf_T *mip, int mode)
// byte length in keep-case word. Length may change when
// folding case. This can be slow, take a shortcut when
// the case-folded word is equal to the keep-case word.
- p = (char_u *)mip->mi_fword;
- if (STRNCMP(ptr, p, wlen) != 0) {
- for (char_u *s = ptr; s < ptr + wlen; MB_PTR_ADV(s)) {
+ p = mip->mi_fword;
+ if (strncmp(ptr, p, (size_t)wlen) != 0) {
+ for (char *s = ptr; s < ptr + wlen; MB_PTR_ADV(s)) {
MB_PTR_ADV(p);
}
- mip->mi_compoff = (int)(p - (char_u *)mip->mi_fword);
+ mip->mi_compoff = (int)(p - mip->mi_fword);
}
}
#if 0
@@ -878,16 +878,16 @@ static void find_word(matchinf_T *mip, int mode)
if (nobreak_result == SP_BAD) {
if (mip->mi_result2 > res) {
mip->mi_result2 = res;
- mip->mi_end2 = mip->mi_word + wlen;
+ mip->mi_end2 = (char_u *)mip->mi_word + wlen;
} else if (mip->mi_result2 == res
- && mip->mi_end2 < mip->mi_word + wlen) {
- mip->mi_end2 = mip->mi_word + wlen;
+ && mip->mi_end2 < (char_u *)mip->mi_word + wlen) {
+ mip->mi_end2 = (char_u *)mip->mi_word + wlen;
}
} else if (mip->mi_result > res) {
mip->mi_result = res;
- mip->mi_end = mip->mi_word + wlen;
- } else if (mip->mi_result == res && mip->mi_end < mip->mi_word + wlen) {
- mip->mi_end = mip->mi_word + wlen;
+ mip->mi_end = (char_u *)mip->mi_word + wlen;
+ } else if (mip->mi_result == res && mip->mi_end < (char_u *)mip->mi_word + wlen) {
+ mip->mi_end = (char_u *)mip->mi_word + wlen;
}
if (mip->mi_result == SP_OK) {
@@ -908,16 +908,16 @@ static void find_word(matchinf_T *mip, int mode)
/// end of ptr[wlen] and the second part matches after it.
///
/// @param gap &sl_comppat
-bool match_checkcompoundpattern(char_u *ptr, int wlen, garray_T *gap)
+bool match_checkcompoundpattern(char *ptr, int wlen, garray_T *gap)
{
for (int i = 0; i + 1 < gap->ga_len; i += 2) {
char *p = ((char **)gap->ga_data)[i + 1];
- if (STRNCMP(ptr + wlen, p, strlen(p)) == 0) {
+ if (strncmp(ptr + wlen, p, strlen(p)) == 0) {
// Second part matches at start of following compound word, now
// check if first part matches at end of previous word.
p = ((char **)gap->ga_data)[i];
int len = (int)strlen(p);
- if (len <= wlen && STRNCMP(ptr + wlen - len, p, len) == 0) {
+ if (len <= wlen && strncmp(ptr + wlen - len, p, (size_t)len) == 0) {
return true;
}
}
@@ -1111,7 +1111,7 @@ static void find_prefix(matchinf_T *mip, int mode)
// Case-folded length may differ from original length.
mip->mi_cprefixlen = nofold_len((char_u *)mip->mi_fword, mip->mi_prefixlen,
- mip->mi_word);
+ (char_u *)mip->mi_word);
find_word(mip, FIND_PREFIX);
if (len == 0) {
@@ -1809,7 +1809,7 @@ static int count_syllables(slang_T *slang, const char_u *word)
return 0;
}
- for (const char_u *p = word; *p != NUL; p += len) {
+ for (const char *p = (char *)word; *p != NUL; p += len) {
// When running into a space reset counter.
if (*p == ' ') {
len = 1;
@@ -1822,7 +1822,7 @@ static int count_syllables(slang_T *slang, const char_u *word)
for (int i = 0; i < slang->sl_syl_items.ga_len; i++) {
syl_item_T *syl = ((syl_item_T *)slang->sl_syl_items.ga_data) + i;
if (syl->sy_len > len
- && STRNCMP(p, syl->sy_chars, syl->sy_len) == 0) {
+ && strncmp(p, syl->sy_chars, (size_t)syl->sy_len) == 0) {
len = syl->sy_len;
}
}
@@ -1831,8 +1831,8 @@ static int count_syllables(slang_T *slang, const char_u *word)
skip = false;
} else {
// No recognized syllable item, at least a syllable char then?
- int c = utf_ptr2char((char *)p);
- len = utfc_ptr2len((char *)p);
+ int c = utf_ptr2char(p);
+ len = utfc_ptr2len(p);
if (vim_strchr((char *)slang->sl_syllable, c) == NULL) {
skip = false; // No, search for next syllable
} else if (!skip) {
diff --git a/src/nvim/spell_defs.h b/src/nvim/spell_defs.h
index 1484d8cef2..265e4b2819 100644
--- a/src/nvim/spell_defs.h
+++ b/src/nvim/spell_defs.h
@@ -72,8 +72,8 @@ typedef int idx_T;
// si_repsal, sl_rep, and si_sal. Not for sl_sal!
// One replacement: from "ft_from" to "ft_to".
typedef struct fromto_S {
- uint8_t *ft_from;
- uint8_t *ft_to;
+ char *ft_from;
+ char *ft_to;
} fromto_T;
// Info from "SAL" entries in ".aff" file used in sl_sal.
diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c
index 69847bfa10..f2c335c69a 100644
--- a/src/nvim/spellfile.c
+++ b/src/nvim/spellfile.c
@@ -899,7 +899,7 @@ void suggest_load_files(void)
slang_T *slang;
char *dotp;
FILE *fd;
- char_u buf[MAXWLEN];
+ char buf[MAXWLEN];
int i;
time_t timestamp;
int wcount;
@@ -929,9 +929,9 @@ void suggest_load_files(void)
// <SUGHEADER>: <fileID> <versionnr> <timestamp>
for (i = 0; i < VIMSUGMAGICL; i++) {
- buf[i] = (char_u)getc(fd); // <fileID>
+ buf[i] = (char)getc(fd); // <fileID>
}
- if (STRNCMP(buf, VIMSUGMAGIC, VIMSUGMAGICL) != 0) {
+ if (strncmp(buf, VIMSUGMAGIC, VIMSUGMAGICL) != 0) {
semsg(_("E778: This does not look like a .sug file: %s"),
slang->sl_fname);
goto nextone;
@@ -1147,14 +1147,14 @@ static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first)
for (; gap->ga_len < cnt; ++gap->ga_len) {
int c;
ftp = &((fromto_T *)gap->ga_data)[gap->ga_len];
- ftp->ft_from = read_cnt_string(fd, 1, &c);
+ ftp->ft_from = (char *)read_cnt_string(fd, 1, &c);
if (c < 0) {
return c;
}
if (c == 0) {
return SP_FORMERROR;
}
- ftp->ft_to = read_cnt_string(fd, 1, &c);
+ ftp->ft_to = (char *)read_cnt_string(fd, 1, &c);
if (c <= 0) {
xfree(ftp->ft_from);
if (c < 0) {
@@ -1170,8 +1170,8 @@ static int read_rep_section(FILE *fd, garray_T *gap, int16_t *first)
}
for (int i = 0; i < gap->ga_len; i++) {
ftp = &((fromto_T *)gap->ga_data)[i];
- if (first[*ftp->ft_from] == -1) {
- first[*ftp->ft_from] = (int16_t)i;
+ if (first[(uint8_t)(*ftp->ft_from)] == -1) {
+ first[(uint8_t)(*ftp->ft_from)] = (int16_t)i;
}
}
return 0;
@@ -3057,9 +3057,9 @@ static void add_fromto(spellinfo_T *spin, garray_T *gap, char *from, char *to)
fromto_T *ftp = GA_APPEND_VIA_PTR(fromto_T, gap);
(void)spell_casefold(curwin, (char_u *)from, (int)strlen(from), word, MAXWLEN);
- ftp->ft_from = (char_u *)getroom_save(spin, (char *)word);
+ ftp->ft_from = getroom_save(spin, (char *)word);
(void)spell_casefold(curwin, (char_u *)to, (int)strlen(to), word, MAXWLEN);
- ftp->ft_to = (char_u *)getroom_save(spin, (char *)word);
+ ftp->ft_to = getroom_save(spin, (char *)word);
}
/// Converts a boolean argument in a SAL line to true or false;
@@ -4360,7 +4360,7 @@ static int rep_compare(const void *s1, const void *s2)
fromto_T *p1 = (fromto_T *)s1;
fromto_T *p2 = (fromto_T *)s2;
- return strcmp((char *)p1->ft_from, (char *)p2->ft_from);
+ return strcmp(p1->ft_from, p2->ft_from);
}
/// Write the Vim .spl file "fname".
@@ -4516,8 +4516,8 @@ static int write_vim_spell(spellinfo_T *spin, char *fname)
assert(gap->ga_len >= 0);
for (size_t i = 0; i < (size_t)gap->ga_len; i++) {
fromto_T *ftp = &((fromto_T *)gap->ga_data)[i];
- l += 1 + strlen((char *)ftp->ft_from); // count <*fromlen> and <*from>
- l += 1 + strlen((char *)ftp->ft_to); // count <*tolen> and <*to>
+ l += 1 + strlen(ftp->ft_from); // count <*fromlen> and <*from>
+ l += 1 + strlen(ftp->ft_to); // count <*tolen> and <*to>
}
if (round == 2) {
l++; // count <salflags>
@@ -4544,7 +4544,7 @@ static int write_vim_spell(spellinfo_T *spin, char *fname)
// <sal> : <salfromlen> <salfrom> <saltolen> <salto>
fromto_T *ftp = &((fromto_T *)gap->ga_data)[i];
for (unsigned int rr = 1; rr <= 2; rr++) {
- char *p = rr == 1 ? (char *)ftp->ft_from : (char *)ftp->ft_to;
+ char *p = rr == 1 ? ftp->ft_from : ftp->ft_to;
l = strlen(p);
assert(l < INT_MAX);
putc((int)l, fd);
@@ -5516,7 +5516,7 @@ static void spell_message(const spellinfo_T *spin, char *str)
// ":[count]spellrare {word}"
void ex_spell(exarg_T *eap)
{
- spell_add_word((char_u *)eap->arg, (int)strlen(eap->arg),
+ spell_add_word(eap->arg, (int)strlen(eap->arg),
eap->cmdidx == CMD_spellwrong ? SPELL_ADD_BAD :
eap->cmdidx == CMD_spellrare ? SPELL_ADD_RARE : SPELL_ADD_GOOD,
eap->forceit ? 0 : (int)eap->line2,
@@ -5528,19 +5528,19 @@ void ex_spell(exarg_T *eap)
/// @param what SPELL_ADD_ values
/// @param idx "zG" and "zW": zero, otherwise index in 'spellfile'
/// @param bool // true for "zug", "zuG", "zuw" and "zuW"
-void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo)
+void spell_add_word(char *word, int len, SpellAddType what, int idx, bool undo)
{
FILE *fd = NULL;
buf_T *buf = NULL;
bool new_spf = false;
char *fname;
char_u *fnamebuf = NULL;
- char_u line[MAXWLEN * 2];
+ char line[MAXWLEN * 2];
long fpos, fpos_next = 0;
int i;
char_u *spf;
- if (!valid_spell_word((char *)word, (char *)word + len)) {
+ if (!valid_spell_word(word, word + len)) {
emsg(_(e_illegal_character_in_word));
return;
}
@@ -5603,8 +5603,8 @@ void spell_add_word(char_u *word, int len, SpellAddType what, int idx, bool undo
if (fpos_next < 0) {
break; // should never happen
}
- if (STRNCMP(word, line, len) == 0
- && (line[len] == '/' || line[len] < ' ')) {
+ if (strncmp(word, line, (size_t)len) == 0
+ && (line[len] == '/' || (uint8_t)line[len] < ' ')) {
// Found duplicate word. Remove it by writing a '#' at
// the start of the line. Mixing reading and writing
// doesn't work for all systems, close the file first.
diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c
index 76410e5225..6bdcfe5ffe 100644
--- a/src/nvim/spellsuggest.c
+++ b/src/nvim/spellsuggest.c
@@ -75,7 +75,7 @@ typedef struct suginfo_S {
int su_badlen; ///< length of detected bad word in line
int su_badflags; ///< caps flags for bad word
char_u su_badword[MAXWLEN]; ///< bad word truncated at su_badlen
- char_u su_fbadword[MAXWLEN]; ///< su_badword case-folded
+ char su_fbadword[MAXWLEN]; ///< su_badword case-folded
char_u su_sal_badword[MAXWLEN]; ///< su_badword soundfolded
hashtab_T su_banned; ///< table with banned words
slang_T *su_sallang; ///< default language for sound folding
@@ -744,7 +744,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma
su->su_badlen = MAXWLEN - 1; // just in case
}
STRLCPY(su->su_badword, su->su_badptr, su->su_badlen + 1);
- (void)spell_casefold(curwin, (char_u *)su->su_badptr, su->su_badlen, su->su_fbadword,
+ (void)spell_casefold(curwin, (char_u *)su->su_badptr, su->su_badlen, (char_u *)su->su_fbadword,
MAXWLEN);
// TODO(vim): make this work if the case-folded text is longer than the
@@ -1004,20 +1004,20 @@ static void spell_find_cleanup(suginfo_T *su)
/// Try finding suggestions by recognizing specific situations.
static void suggest_try_special(suginfo_T *su)
{
- int c;
+ char c;
char_u word[MAXWLEN];
// Recognize a word that is repeated: "the the".
char *p = skiptowhite((char *)su->su_fbadword);
size_t len = (size_t)(p - (char *)su->su_fbadword);
p = skipwhite(p);
- if (strlen(p) == len && STRNCMP(su->su_fbadword, p, len) == 0) {
+ if (strlen(p) == len && strncmp(su->su_fbadword, p, len) == 0) {
// Include badflags: if the badword is onecap or allcap
// use that for the goodword too: "The the" -> "The".
c = su->su_fbadword[len];
su->su_fbadword[len] = NUL;
- make_case_word(su->su_fbadword, word, su->su_badflags);
- su->su_fbadword[len] = (char_u)c;
+ make_case_word((char_u *)su->su_fbadword, word, su->su_badflags);
+ su->su_fbadword[len] = c;
// Give a soundalike score of 0, compute the score as if deleting one
// character.
@@ -1106,7 +1106,7 @@ static void suggest_try_change(suginfo_T *su)
#ifdef SUGGEST_PROFILE
prof_init();
#endif
- suggest_trie_walk(su, lp, (char_u *)fword, false);
+ suggest_trie_walk(su, lp, fword, false);
#ifdef SUGGEST_PROFILE
prof_report("try_change");
#endif
@@ -1146,9 +1146,9 @@ static void suggest_try_change(suginfo_T *su)
/// word splitting for now
/// "similar_chars()"
/// use "slang->sl_repsal" instead of "lp->lp_replang->sl_rep"
-static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool soundfold)
+static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soundfold)
{
- char_u tword[MAXWLEN]; // good word collected so far
+ char tword[MAXWLEN]; // good word collected so far
trystate_T stack[MAXWLEN];
char preword[MAXWLEN * 3] = { 0 }; // word found with proper case;
// concatenation of prefix compound
@@ -1168,7 +1168,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
garray_T *gap;
idx_T arridx;
int len;
- char_u *p;
+ char *p;
fromto_T *ftp;
int fl = 0, tl;
int repextra = 0; // extra bytes in fword[] from REP item
@@ -1258,7 +1258,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
if (depth < MAXWLEN - 1 && (byts[arridx] == 0 || n == STATE_NOPREFIX)) {
// Set su->su_badflags to the caps type at this position.
// Use the caps type until here for the prefix itself.
- n = nofold_len(fword, sp->ts_fidx, (char_u *)su->su_badptr);
+ n = nofold_len((char_u *)fword, sp->ts_fidx, (char_u *)su->su_badptr);
flags = badword_captype((char_u *)su->su_badptr, (char_u *)su->su_badptr + n);
su->su_badflags = badword_captype((char_u *)su->su_badptr + n,
(char_u *)su->su_badptr + su->su_badlen);
@@ -1276,7 +1276,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// Move the prefix to preword[] with the right case
// and make find_keepcap_word() works.
tword[sp->ts_twordlen] = NUL;
- make_case_word(tword + sp->ts_splitoff,
+ make_case_word((char_u *)tword + sp->ts_splitoff,
(char_u *)preword + sp->ts_prewordlen, flags);
sp->ts_prewordlen = (char_u)strlen(preword);
sp->ts_splitoff = sp->ts_twordlen;
@@ -1305,7 +1305,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
fword_ends = (fword[sp->ts_fidx] == NUL
|| (soundfold
? ascii_iswhite(fword[sp->ts_fidx])
- : !spell_iswordp(fword + sp->ts_fidx, curwin)));
+ : !spell_iswordp((char_u *)fword + sp->ts_fidx, curwin)));
tword[sp->ts_twordlen] = NUL;
if (sp->ts_prefixdepth <= PFD_NOTSPECIAL
@@ -1320,7 +1320,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
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);
+ (char_u *)tword + sp->ts_splitoff, slang, false);
if (c == 0) {
break;
}
@@ -1357,7 +1357,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// need to check if a correct word follows.
if (sp->ts_fidx - sp->ts_splitfidx
== sp->ts_twordlen - sp->ts_splitoff
- && STRNCMP(fword + sp->ts_splitfidx,
+ && strncmp(fword + sp->ts_splitfidx,
tword + sp->ts_splitoff,
sp->ts_fidx - sp->ts_splitfidx) == 0) {
preword[sp->ts_prewordlen] = NUL;
@@ -1386,7 +1386,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// For multi-byte chars check character length against
// COMPOUNDMIN.
if (slang->sl_compminlen > 0
- && mb_charlen(tword + sp->ts_splitoff)
+ && mb_charlen((char_u *)tword + sp->ts_splitoff)
< slang->sl_compminlen) {
break;
}
@@ -1398,17 +1398,17 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
sp->ts_twordlen - sp->ts_splitoff + 1);
// Verify CHECKCOMPOUNDPATTERN rules.
- if (match_checkcompoundpattern((char_u *)preword, sp->ts_prewordlen,
+ if (match_checkcompoundpattern(preword, sp->ts_prewordlen,
&slang->sl_comppat)) {
compound_ok = false;
}
if (compound_ok) {
- p = (char_u *)preword;
- while (*skiptowhite((char *)p) != NUL) {
- p = (char_u *)skipwhite(skiptowhite((char *)p));
+ p = preword;
+ while (*skiptowhite(p) != NUL) {
+ p = skipwhite(skiptowhite(p));
}
- if (fword_ends && !can_compound(slang, (char *)p, compflags + sp->ts_compsplit)) {
+ if (fword_ends && !can_compound(slang, p, compflags + sp->ts_compsplit)) {
// Compound is not allowed. But it may still be
// possible if we add another (short) word.
compound_ok = false;
@@ -1416,7 +1416,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
}
// Get pointer to last char of previous word.
- p = (char_u *)preword + sp->ts_prewordlen;
+ p = preword + sp->ts_prewordlen;
MB_PTR_BACK(preword, p);
}
}
@@ -1441,10 +1441,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// When appending a compound word after a word character don't
// use Onecap.
- if (p != NULL && spell_iswordp_nmw(p, curwin)) {
+ if (p != NULL && spell_iswordp_nmw((char_u *)p, curwin)) {
c &= ~WF_ONECAP;
}
- make_case_word(tword + sp->ts_splitoff,
+ make_case_word((char_u *)tword + sp->ts_splitoff,
(char_u *)preword + sp->ts_prewordlen, c);
}
@@ -1508,10 +1508,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// char, e.g., "thes," -> "these".
p = fword + sp->ts_fidx;
MB_PTR_BACK(fword, p);
- if (!spell_iswordp(p, curwin) && *preword != NUL) {
- p = (char_u *)preword + strlen(preword);
+ if (!spell_iswordp((char_u *)p, curwin) && *preword != NUL) {
+ p = preword + strlen(preword);
MB_PTR_BACK(preword, p);
- if (spell_iswordp(p, curwin)) {
+ if (spell_iswordp((char_u *)p, curwin)) {
newscore += SCORE_NONWORD;
}
}
@@ -1533,7 +1533,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// upper or lower case, add both.
c = captype((char_u *)preword, NULL);
if (c == 0 || c == WF_ALLCAP) {
- make_case_word(tword + sp->ts_splitoff,
+ make_case_word((char_u *)tword + sp->ts_splitoff,
(char_u *)preword + sp->ts_prewordlen,
c == 0 ? WF_ALLCAP : 0);
@@ -1582,7 +1582,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
&& sp->ts_twordlen - sp->ts_splitoff
>= slang->sl_compminlen
&& (slang->sl_compminlen == 0
- || mb_charlen(tword + sp->ts_splitoff)
+ || mb_charlen((char_u *)tword + sp->ts_splitoff)
>= slang->sl_compminlen)
&& (slang->sl_compsylmax < MAXWLEN
|| sp->ts_complen + 1 - sp->ts_compsplit
@@ -1621,12 +1621,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
&& (flags & WF_NEEDCOMP)) {
break;
}
- p = (char_u *)preword;
- while (*skiptowhite((char *)p) != NUL) {
- p = (char_u *)skipwhite(skiptowhite((char *)p));
+ p = preword;
+ while (*skiptowhite(p) != NUL) {
+ p = skipwhite(skiptowhite(p));
}
if (sp->ts_complen > sp->ts_compsplit
- && !can_compound(slang, (char *)p, compflags + sp->ts_compsplit)) {
+ && !can_compound(slang, p, compflags + sp->ts_compsplit)) {
break;
}
@@ -1673,7 +1673,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// non-word character with a space. Always skip a
// character when the word ends. But only when the
// good word can end.
- if (((!try_compound && !spell_iswordp_nmw(fword
+ if (((!try_compound && !spell_iswordp_nmw((char_u *)fword
+ sp->ts_fidx,
curwin))
|| fword_ends)
@@ -1681,7 +1681,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
&& goodword_ends) {
int l;
- l = utfc_ptr2len((char *)fword + sp->ts_fidx);
+ l = utfc_ptr2len(fword + sp->ts_fidx);
if (fword_ends) {
// Copy the skipped character to preword.
memmove(preword + sp->ts_prewordlen, fword + sp->ts_fidx, (size_t)l);
@@ -1705,7 +1705,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// set su->su_badflags to the caps type at this
// position
- n = nofold_len(fword, sp->ts_fidx, (char_u *)su->su_badptr);
+ n = nofold_len((char_u *)fword, sp->ts_fidx, (char_u *)su->su_badptr);
su->su_badflags = badword_captype((char_u *)su->su_badptr + n,
(char_u *)su->su_badptr + su->su_badlen);
@@ -1774,7 +1774,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// when the byte was already changed. And don't try when we
// just deleted this byte, accepting it is always cheaper than
// delete + substitute.
- if (c == fword[sp->ts_fidx]
+ if (c == (uint8_t)fword[sp->ts_fidx]
|| (sp->ts_tcharlen > 0
&& sp->ts_isdiff != DIFF_NONE)) {
newscore = 0;
@@ -1784,7 +1784,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
if ((newscore == 0
|| (sp->ts_fidx >= sp->ts_fidxtry
&& ((sp->ts_flags & TSF_DIDDEL) == 0
- || c != fword[sp->ts_delidx])))
+ || c != (uint8_t)fword[sp->ts_delidx])))
&& TRY_DEEPER(su, stack, depth, newscore)) {
go_deeper(stack, depth, newscore);
#ifdef DEBUG_TRIEWALK
@@ -1803,7 +1803,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
if (fword[sp->ts_fidx] != NUL) {
sp->ts_fidx++;
}
- tword[sp->ts_twordlen++] = (char_u)c;
+ tword[sp->ts_twordlen++] = (char)c;
sp->ts_arridx = idxs[arridx];
if (newscore == SCORE_SUBST) {
sp->ts_isdiff = DIFF_YES;
@@ -1829,14 +1829,14 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// Correct ts_fidx for the byte length of the
// character (we didn't check that before).
sp->ts_fidx = (char_u)(sp->ts_fcharstart
- + utfc_ptr2len((char *)fword + sp->ts_fcharstart));
+ + utfc_ptr2len(fword + sp->ts_fcharstart));
// For changing a composing character adjust
// the score from SCORE_SUBST to
// SCORE_SUBCOMP.
if (utf_iscomposing(utf_ptr2char((char *)tword + sp->ts_twordlen
- sp->ts_tcharlen))
- && utf_iscomposing(utf_ptr2char((char *)fword
+ && utf_iscomposing(utf_ptr2char(fword
+ sp->ts_fcharstart))) {
sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP;
} else if (!soundfold
@@ -1844,15 +1844,15 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
&& similar_chars(slang,
utf_ptr2char((char *)tword + sp->ts_twordlen -
sp->ts_tcharlen),
- utf_ptr2char((char *)fword + sp->ts_fcharstart))) {
+ utf_ptr2char(fword + sp->ts_fcharstart))) {
// For a similar character adjust score from
// SCORE_SUBST to SCORE_SIMILAR.
sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR;
}
} else if (sp->ts_isdiff == DIFF_INSERT
&& sp->ts_twordlen > sp->ts_tcharlen) {
- p = tword + sp->ts_twordlen - sp->ts_tcharlen;
- c = utf_ptr2char((char *)p);
+ p = (char *)tword + sp->ts_twordlen - sp->ts_tcharlen;
+ c = utf_ptr2char(p);
if (utf_iscomposing(c)) {
// Inserting a composing char doesn't
// count that much.
@@ -1864,7 +1864,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// tree (might seem illogical but does
// give better scores).
MB_PTR_BACK(tword, p);
- if (c == utf_ptr2char((char *)p)) {
+ if (c == utf_ptr2char(p)) {
sp->ts_score -= SCORE_INS - SCORE_INSDUP;
}
}
@@ -1915,12 +1915,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// score if the same character is following "nn" -> "n". It's
// a bit illogical for soundfold tree but it does give better
// results.
- c = utf_ptr2char((char *)fword + sp->ts_fidx);
+ c = utf_ptr2char(fword + sp->ts_fidx);
stack[depth].ts_fidx =
- (char_u)(stack[depth].ts_fidx + utfc_ptr2len((char *)fword + sp->ts_fidx));
+ (char_u)(stack[depth].ts_fidx + utfc_ptr2len(fword + sp->ts_fidx));
if (utf_iscomposing(c)) {
stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP;
- } else if (c == utf_ptr2char((char *)fword + stack[depth].ts_fidx)) {
+ } else if (c == utf_ptr2char(fword + stack[depth].ts_fidx)) {
stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP;
}
@@ -1980,7 +1980,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
} else {
newscore = SCORE_INS;
}
- if (c != fword[sp->ts_fidx]
+ if (c != (uint8_t)fword[sp->ts_fidx]
&& TRY_DEEPER(su, stack, depth, newscore)) {
go_deeper(stack, depth, newscore);
#ifdef DEBUG_TRIEWALK
@@ -1990,7 +1990,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
#endif
depth++;
sp = &stack[depth];
- tword[sp->ts_twordlen++] = (char_u)c;
+ tword[sp->ts_twordlen++] = (char)c;
sp->ts_arridx = idxs[n];
fl = MB_BYTE2LEN(c);
if (fl > 1) {
@@ -2007,7 +2007,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// soundfold words (illogical but does give a better
// score).
if (sp->ts_twordlen >= 2
- && tword[sp->ts_twordlen - 2] == c) {
+ && (uint8_t)tword[sp->ts_twordlen - 2] == c) {
sp->ts_score -= SCORE_INS - SCORE_INSDUP;
}
}
@@ -2019,7 +2019,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// We change "fword" here, it's changed back afterwards at
// STATE_UNSWAP.
p = fword + sp->ts_fidx;
- c = *p;
+ c = (uint8_t)(*p);
if (c == NUL) {
// End of word, can't swap or replace.
PROF_STORE(sp->ts_state)
@@ -2029,20 +2029,20 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// Don't swap if the first character is not a word character.
// SWAP3 etc. also don't make sense then.
- if (!soundfold && !spell_iswordp(p, curwin)) {
+ if (!soundfold && !spell_iswordp((char_u *)p, curwin)) {
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
break;
}
- n = utf_ptr2len((char *)p);
- c = utf_ptr2char((char *)p);
+ n = utf_ptr2len(p);
+ c = utf_ptr2char(p);
if (p[n] == NUL) {
c2 = NUL;
- } else if (!soundfold && !spell_iswordp(p + n, curwin)) {
+ } else if (!soundfold && !spell_iswordp((char_u *)p + n, curwin)) {
c2 = c; // don't swap non-word char
} else {
- c2 = utf_ptr2char((char *)p + n);
+ c2 = utf_ptr2char(p + n);
}
// When the second character is NUL we can't swap.
@@ -2072,7 +2072,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
depth++;
fl = utf_char2len(c2);
memmove(p, p + n, (size_t)fl);
- utf_char2bytes(c, (char *)p + fl);
+ utf_char2bytes(c, p + fl);
stack[depth].ts_fidxtry = (char_u)(sp->ts_fidx + n + fl);
} else {
// If this swap doesn't work then SWAP3 won't either.
@@ -2084,10 +2084,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
case STATE_UNSWAP:
// Undo the STATE_SWAP swap: "21" -> "12".
p = fword + sp->ts_fidx;
- n = utfc_ptr2len((char *)p);
- c = utf_ptr2char((char *)p + n);
- memmove(p + utfc_ptr2len((char *)p + n), p, (size_t)n);
- utf_char2bytes(c, (char *)p);
+ n = utfc_ptr2len(p);
+ c = utf_ptr2char(p + n);
+ memmove(p + utfc_ptr2len(p + n), p, (size_t)n);
+ utf_char2bytes(c, p);
FALLTHROUGH;
@@ -2095,14 +2095,14 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// Swap two bytes, skipping one: "123" -> "321". We change
// "fword" here, it's changed back afterwards at STATE_UNSWAP3.
p = fword + sp->ts_fidx;
- n = utf_ptr2len((char *)p);
- c = utf_ptr2char((char *)p);
- fl = utf_ptr2len((char *)p + n);
- c2 = utf_ptr2char((char *)p + n);
- if (!soundfold && !spell_iswordp(p + n + fl, curwin)) {
+ n = utf_ptr2len(p);
+ c = utf_ptr2char(p);
+ fl = utf_ptr2len(p + n);
+ c2 = utf_ptr2char(p + n);
+ if (!soundfold && !spell_iswordp((char_u *)p + n + fl, curwin)) {
c3 = c; // don't swap non-word char
} else {
- c3 = utf_ptr2char((char *)p + n + fl);
+ c3 = utf_ptr2char(p + n + fl);
}
// When characters are identical: "121" then SWAP3 result is
@@ -2128,8 +2128,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
depth++;
tl = utf_char2len(c3);
memmove(p, p + n + fl, (size_t)tl);
- utf_char2bytes(c2, (char *)p + tl);
- utf_char2bytes(c, (char *)p + fl + tl);
+ utf_char2bytes(c2, p + tl);
+ utf_char2bytes(c, p + fl + tl);
stack[depth].ts_fidxtry = (char_u)(sp->ts_fidx + n + fl + tl);
} else {
PROF_STORE(sp->ts_state)
@@ -2140,17 +2140,17 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
case STATE_UNSWAP3:
// Undo STATE_SWAP3: "321" -> "123"
p = fword + sp->ts_fidx;
- n = utfc_ptr2len((char *)p);
- c2 = utf_ptr2char((char *)p + n);
- fl = utfc_ptr2len((char *)p + n);
- c = utf_ptr2char((char *)p + n + fl);
- tl = utfc_ptr2len((char *)p + n + fl);
+ n = utfc_ptr2len(p);
+ c2 = utf_ptr2char(p + n);
+ fl = utfc_ptr2len(p + n);
+ c = utf_ptr2char(p + n + fl);
+ tl = utfc_ptr2len(p + n + fl);
memmove(p + fl + tl, p, (size_t)n);
- utf_char2bytes(c, (char *)p);
- utf_char2bytes(c2, (char *)p + tl);
+ utf_char2bytes(c, p);
+ utf_char2bytes(c2, p + tl);
p = p + tl;
- if (!soundfold && !spell_iswordp(p, curwin)) {
+ if (!soundfold && !spell_iswordp((char_u *)p, curwin)) {
// Middle char is not a word char, skip the rotate. First and
// third char were already checked at swap and swap3.
PROF_STORE(sp->ts_state)
@@ -2172,12 +2172,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
sp->ts_state = STATE_UNROT3L;
depth++;
p = fword + sp->ts_fidx;
- n = utf_ptr2len((char *)p);
- c = utf_ptr2char((char *)p);
- fl = utf_ptr2len((char *)p + n);
- fl += utf_ptr2len((char *)p + n + fl);
+ n = utf_ptr2len(p);
+ c = utf_ptr2char(p);
+ fl = utf_ptr2len(p + n);
+ fl += utf_ptr2len(p + n + fl);
memmove(p, p + n, (size_t)fl);
- utf_char2bytes(c, (char *)p + fl);
+ utf_char2bytes(c, p + fl);
stack[depth].ts_fidxtry = (char_u)(sp->ts_fidx + n + fl);
} else {
PROF_STORE(sp->ts_state)
@@ -2188,12 +2188,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
case STATE_UNROT3L:
// Undo ROT3L: "231" -> "123"
p = fword + sp->ts_fidx;
- n = utfc_ptr2len((char *)p);
- n += utfc_ptr2len((char *)p + n);
- c = utf_ptr2char((char *)p + n);
- tl = utfc_ptr2len((char *)p + n);
+ n = utfc_ptr2len(p);
+ n += utfc_ptr2len(p + n);
+ c = utf_ptr2char(p + n);
+ tl = utfc_ptr2len(p + n);
memmove(p + tl, p, (size_t)n);
- utf_char2bytes(c, (char *)p);
+ utf_char2bytes(c, p);
// Rotate three bytes right: "123" -> "312". We change "fword"
// here, it's changed back afterwards at STATE_UNROT3R.
@@ -2209,12 +2209,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
sp->ts_state = STATE_UNROT3R;
depth++;
p = fword + sp->ts_fidx;
- n = utf_ptr2len((char *)p);
- n += utf_ptr2len((char *)p + n);
- c = utf_ptr2char((char *)p + n);
- tl = utf_ptr2len((char *)p + n);
+ n = utf_ptr2len(p);
+ n += utf_ptr2len(p + n);
+ c = utf_ptr2char(p + n);
+ tl = utf_ptr2len(p + n);
memmove(p + tl, p, (size_t)n);
- utf_char2bytes(c, (char *)p);
+ utf_char2bytes(c, p);
stack[depth].ts_fidxtry = (char_u)(sp->ts_fidx + n + tl);
} else {
PROF_STORE(sp->ts_state)
@@ -2225,12 +2225,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
case STATE_UNROT3R:
// Undo ROT3R: "312" -> "123"
p = fword + sp->ts_fidx;
- c = utf_ptr2char((char *)p);
- tl = utfc_ptr2len((char *)p);
- n = utfc_ptr2len((char *)p + tl);
- n += utfc_ptr2len((char *)p + tl + n);
+ c = utf_ptr2char(p);
+ tl = utfc_ptr2len(p);
+ n = utfc_ptr2len(p + tl);
+ n += utfc_ptr2len(p + tl + n);
memmove(p, p + tl, (size_t)n);
- utf_char2bytes(c, (char *)p + n);
+ utf_char2bytes(c, p + n);
FALLTHROUGH;
@@ -2251,9 +2251,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// Use the first byte to quickly find the first entry that may
// match. If the index is -1 there is none.
if (soundfold) {
- sp->ts_curi = slang->sl_repsal_first[fword[sp->ts_fidx]];
+ sp->ts_curi = slang->sl_repsal_first[(uint8_t)fword[sp->ts_fidx]];
} else {
- sp->ts_curi = lp->lp_replang->sl_rep_first[fword[sp->ts_fidx]];
+ sp->ts_curi = lp->lp_replang->sl_rep_first[(uint8_t)fword[sp->ts_fidx]];
}
if (sp->ts_curi < 0) {
@@ -2284,7 +2284,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
sp->ts_curi = (int16_t)gap->ga_len;
break;
}
- if (STRNCMP(ftp->ft_from, p, strlen((char *)ftp->ft_from)) == 0
+ if (strncmp(ftp->ft_from, p, strlen(ftp->ft_from)) == 0
&& TRY_DEEPER(su, stack, depth, SCORE_REP)) {
go_deeper(stack, depth, SCORE_REP);
#ifdef DEBUG_TRIEWALK
@@ -2298,8 +2298,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// Change the "from" to the "to" string.
depth++;
- fl = (int)strlen((char *)ftp->ft_from);
- tl = (int)strlen((char *)ftp->ft_to);
+ fl = (int)strlen(ftp->ft_from);
+ tl = (int)strlen(ftp->ft_to);
if (fl != tl) {
STRMOVE(p + tl, (char *)p + fl);
repextra += tl - fl;
@@ -2327,8 +2327,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
gap = &lp->lp_replang->sl_rep;
}
ftp = (fromto_T *)gap->ga_data + sp->ts_curi - 1;
- fl = (int)strlen((char *)ftp->ft_from);
- tl = (int)strlen((char *)ftp->ft_to);
+ fl = (int)strlen(ftp->ft_from);
+ tl = (int)strlen(ftp->ft_to);
p = fword + sp->ts_fidx;
if (fl != tl) {
STRMOVE(p + fl, (char *)p + tl);
@@ -2747,7 +2747,7 @@ static void suggest_try_soundalike(suginfo_T *su)
#ifdef SUGGEST_PROFILE
prof_init();
#endif
- suggest_trie_walk(su, lp, salword, true);
+ suggest_trie_walk(su, lp, (char *)salword, true);
#ifdef SUGGEST_PROFILE
prof_report("soundalike");
#endif
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index cfe821715c..a96134be8f 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -185,7 +185,7 @@ char *vim_strsave_shellescape(const char *string, bool do_special, bool do_newli
length++; // insert backslash
}
}
- if (do_special && find_cmdline_var(p, &l) >= 0) {
+ if (do_special && find_cmdline_var((char *)p, &l) >= 0) {
length++; // insert backslash
p += l - 1;
}
@@ -234,7 +234,7 @@ char *vim_strsave_shellescape(const char *string, bool do_special, bool do_newli
*d++ = *p++;
continue;
}
- if (do_special && find_cmdline_var((char_u *)p, &l) >= 0) {
+ if (do_special && find_cmdline_var(p, &l) >= 0) {
*d++ = '\\'; // insert backslash
while (--l != SIZE_MAX) { // copy the var
*d++ = *p++;
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index 10a0c9c18c..106e92d43c 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -1439,8 +1439,8 @@ static bool send_mouse_event(Terminal *term, int c)
int direction = c == K_MOUSEDOWN ? MSCR_DOWN : MSCR_UP;
if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) {
scroll_redraw(direction, curwin->w_botline - curwin->w_topline);
- } else {
- scroll_redraw(direction, 3L);
+ } else if (p_mousescroll_vert > 0) {
+ scroll_redraw(direction, p_mousescroll_vert);
}
curwin->w_redr_status = true;
diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim
index 2151076cb9..bb8e7cd5c5 100644
--- a/src/nvim/testdir/test_cursor_func.vim
+++ b/src/nvim/testdir/test_cursor_func.vim
@@ -138,8 +138,12 @@ func Test_screenpos_fold()
redraw
call assert_equal(2, screenpos(1, 2, 1).row)
call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 3, 1))
- call assert_equal(3, screenpos(1, 4, 1).row)
- call assert_equal(3, screenpos(1, 5, 1).row)
+ call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 4, 1))
+ call assert_equal(#{col: 1, row: 3, endcol: 1, curscol: 1}, screenpos(1, 5, 1))
+ setlocal number
+ call assert_equal(#{col: 5, row: 3, endcol: 5, curscol: 5}, screenpos(1, 3, 1))
+ call assert_equal(#{col: 5, row: 3, endcol: 5, curscol: 5}, screenpos(1, 4, 1))
+ call assert_equal(#{col: 5, row: 3, endcol: 5, curscol: 5}, screenpos(1, 5, 1))
call assert_equal(4, screenpos(1, 6, 1).row)
bwipe!
endfunc
diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim
index 88f0c74d37..704edbf166 100644
--- a/src/nvim/testdir/test_filetype.vim
+++ b/src/nvim/testdir/test_filetype.vim
@@ -289,9 +289,9 @@ let s:filename_checks = {
\ 'jgraph': ['file.jgr'],
\ 'jovial': ['file.jov', 'file.j73', 'file.jovial'],
\ 'jproperties': ['file.properties', 'file.properties_xx', 'file.properties_xx_xx', 'some.properties_xx_xx_file', 'org.eclipse.xyz.prefs'],
- \ 'json': ['file.json', 'file.jsonp', 'file.json-patch', 'file.webmanifest', 'Pipfile.lock', 'file.ipynb', '.babelrc', '.eslintrc', '.prettierrc', '.firebaserc', 'file.slnf'],
+ \ 'json': ['file.json', 'file.jsonp', 'file.json-patch', 'file.webmanifest', 'Pipfile.lock', 'file.ipynb', '.prettierrc', '.firebaserc', 'file.slnf'],
\ 'json5': ['file.json5'],
- \ 'jsonc': ['file.jsonc'],
+ \ 'jsonc': ['file.jsonc', '.babelrc', '.eslintrc', '.jsfmtrc', '.jshintrc', '.hintrc', '.swrc', 'jsconfig.json', 'tsconfig.json', 'tsconfig.test.json', 'tsconfig-test.json'],
\ 'jsonnet': ['file.jsonnet', 'file.libsonnet'],
\ 'jsp': ['file.jsp'],
\ 'julia': ['file.jl'],
@@ -1555,13 +1555,6 @@ endfunc
func Test_sc_file()
filetype on
- " SC file methods are defined 'Class : Method'
- call writefile(['SCNvimDocRenderer : SCDocHTMLRenderer {'], 'srcfile.sc')
- split srcfile.sc
- call assert_equal('supercollider', &filetype)
- bwipe!
- call delete('srcfile.sc')
-
" SC classes are defined with '+ Class {}'
call writefile(['+ SCNvim {', '*methodArgs {|method|'], 'srcfile.sc')
split srcfile.sc
diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim
index d74187537c..f19e4c8253 100644
--- a/src/nvim/testdir/test_fold.vim
+++ b/src/nvim/testdir/test_fold.vim
@@ -157,6 +157,27 @@ func Test_indent_fold_max()
bw!
endfunc
+func Test_indent_fold_tabstop()
+ call setline(1, ['0', ' 1', ' 1', "\t2", "\t2"])
+ setlocal shiftwidth=4
+ setlocal foldcolumn=1
+ setlocal foldlevel=2
+ setlocal foldmethod=indent
+ redraw
+ call assert_equal('2 2', ScreenLines(5, 10)[0])
+ vsplit
+ windo diffthis
+ botright new
+ " This 'tabstop' value should not be used for folding in other buffers.
+ setlocal tabstop=4
+ diffoff!
+ redraw
+ call assert_equal('2 2', ScreenLines(5, 10)[0])
+
+ bwipe!
+ bwipe!
+endfunc
+
func Test_manual_fold_with_filter()
CheckExecutable cat
for type in ['manual', 'marker']
diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim
index c1c78e9a8f..7a9392545e 100644
--- a/src/nvim/testdir/test_ins_complete.vim
+++ b/src/nvim/testdir/test_ins_complete.vim
@@ -191,17 +191,17 @@ func s:CompleteDone_CompleteFuncDict( findstart, base )
endif
return {
- \ 'words': [
- \ {
- \ 'word': 'aword',
- \ 'abbr': 'wrd',
- \ 'menu': 'extra text',
- \ 'info': 'words are cool',
- \ 'kind': 'W',
- \ 'user_data': ['one', 'two']
- \ }
- \ ]
- \ }
+ \ 'words': [
+ \ {
+ \ 'word': 'aword',
+ \ 'abbr': 'wrd',
+ \ 'menu': 'extra text',
+ \ 'info': 'words are cool',
+ \ 'kind': 'W',
+ \ 'user_data': ['one', 'two']
+ \ }
+ \ ]
+ \ }
endfunc
func s:CompleteDone_CheckCompletedItemNone()
@@ -261,16 +261,16 @@ func s:CompleteDone_CompleteFuncDictNoUserData(findstart, base)
endif
return {
- \ 'words': [
- \ {
- \ 'word': 'aword',
- \ 'abbr': 'wrd',
- \ 'menu': 'extra text',
- \ 'info': 'words are cool',
- \ 'kind': 'W'
- \ }
- \ ]
- \ }
+ \ 'words': [
+ \ {
+ \ 'word': 'aword',
+ \ 'abbr': 'wrd',
+ \ 'menu': 'extra text',
+ \ 'info': 'words are cool',
+ \ 'kind': 'W',
+ \ }
+ \ ]
+ \ }
endfunc
func s:CompleteDone_CheckCompletedItemDictNoUserData()
diff --git a/src/nvim/testdir/test_signs.vim b/src/nvim/testdir/test_signs.vim
index 1f1b3097b1..8311955a15 100644
--- a/src/nvim/testdir/test_signs.vim
+++ b/src/nvim/testdir/test_signs.vim
@@ -15,13 +15,13 @@ func Test_sign()
" the icon name when listing signs.
sign define Sign1 text=x
- call Sign_command_ignore_error('sign define Sign2 text=xy texthl=Title linehl=Error culhl=Search icon=../../pixmaps/stock_vim_find_help.png')
+ call Sign_command_ignore_error('sign define Sign2 text=xy texthl=Title linehl=Error culhl=Search numhl=Number icon=../../pixmaps/stock_vim_find_help.png')
" Test listing signs.
let a=execute('sign list')
call assert_match('^\nsign Sign1 text=x \nsign Sign2 ' .
\ 'icon=../../pixmaps/stock_vim_find_help.png .*text=xy ' .
- \ 'linehl=Error texthl=Title culhl=Search$', a)
+ \ 'linehl=Error texthl=Title culhl=Search numhl=Number$', a)
let a=execute('sign list Sign1')
call assert_equal("\nsign Sign1 text=x ", a)
@@ -127,26 +127,34 @@ func Test_sign()
call assert_fails("sign define Sign4 text=\\ ab linehl=Comment", 'E239:')
" an empty highlight argument for an existing sign clears it
- sign define SignY texthl=TextHl culhl=CulHl linehl=LineHl
+ sign define SignY texthl=TextHl culhl=CulHl linehl=LineHl numhl=NumHl
let sl = sign_getdefined('SignY')[0]
call assert_equal('TextHl', sl.texthl)
call assert_equal('CulHl', sl.culhl)
call assert_equal('LineHl', sl.linehl)
+ call assert_equal('NumHl', sl.numhl)
- sign define SignY texthl= culhl=CulHl linehl=LineHl
+ sign define SignY texthl= culhl=CulHl linehl=LineHl numhl=NumHl
let sl = sign_getdefined('SignY')[0]
call assert_false(has_key(sl, 'texthl'))
call assert_equal('CulHl', sl.culhl)
call assert_equal('LineHl', sl.linehl)
+ call assert_equal('NumHl', sl.numhl)
sign define SignY linehl=
let sl = sign_getdefined('SignY')[0]
call assert_false(has_key(sl, 'linehl'))
call assert_equal('CulHl', sl.culhl)
+ call assert_equal('NumHl', sl.numhl)
sign define SignY culhl=
let sl = sign_getdefined('SignY')[0]
call assert_false(has_key(sl, 'culhl'))
+ call assert_equal('NumHl', sl.numhl)
+
+ sign define SignY numhl=
+ let sl = sign_getdefined('SignY')[0]
+ call assert_false(has_key(sl, 'numhl'))
sign undefine SignY
@@ -158,7 +166,7 @@ func Test_sign()
sign define Sign5 text=X\ linehl=Comment
sign undefine Sign5
- sign define Sign5 linehl=Comment text=X\
+ sign define Sign5 linehl=Comment text=X\
sign undefine Sign5
" define sign with backslash
@@ -417,8 +425,8 @@ func Test_sign_funcs()
let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error',
\ 'culhl': 'Visual', 'numhl': 'Number'}
call assert_equal(0, "sign1"->sign_define(attr))
- call assert_equal([{'name' : 'sign1', 'texthl' : 'Error', 'linehl': 'Search',
- \ 'culhl': 'Visual', 'numhl': 'Number', 'text' : '=>'}],
+ call assert_equal([{'name' : 'sign1', 'texthl' : 'Error', 'linehl' : 'Search',
+ \ 'culhl' : 'Visual', 'numhl': 'Number', 'text' : '=>'}],
\ sign_getdefined())
" Define a new sign without attributes and then update it
@@ -535,9 +543,9 @@ func Test_sign_funcs()
call assert_equal(15, sign_place(15, '', 'sign1', 'Xsign', {'lnum' : 20}))
call assert_equal(15, sign_place(15, '', 'sign2', 'Xsign'))
call assert_equal([{'bufnr' : bufnr(''), 'signs' :
- \ [{'id' : 15, 'group' : '', 'lnum' : 20, 'name' : 'sign2',
- \ 'priority' : 10}]}],
- \ sign_getplaced())
+ \ [{'id' : 15, 'group' : '', 'lnum' : 20, 'name' : 'sign2',
+ \ 'priority' : 10}]}],
+ \ sign_getplaced())
" Tests for sign_undefine()
call assert_equal(0, sign_undefine("sign1"))
@@ -1165,7 +1173,7 @@ func Test_sign_unplace()
call delete("Xsign2")
endfunc
-" Tests for auto-generating the sign identifier
+" Tests for auto-generating the sign identifier.
func Test_aaa_sign_id_autogen()
enew | only
call sign_unplace('*')
@@ -1650,10 +1658,34 @@ func Test_sign_lnum_adjust()
" changes made by this function.
let &undolevels=&undolevels
+ " Nvim: make sign adjustment when deleting lines match Vim
+ set signcolumn=yes:1
+
" Delete the line with the sign
call deletebufline('', 4)
let l = sign_getplaced(bufnr(''))
- call assert_equal(0, len(l[0].signs))
+ call assert_equal(4, l[0].signs[0].lnum)
+
+ " Undo the delete operation
+ undo
+ let l = sign_getplaced(bufnr(''))
+ call assert_equal(5, l[0].signs[0].lnum)
+
+ " Break the undo
+ let &undolevels=&undolevels
+
+ " Delete few lines at the end of the buffer including the line with the sign
+ " Sign line number should not change (as it is placed outside of the buffer)
+ call deletebufline('', 3, 6)
+ let l = sign_getplaced(bufnr(''))
+ call assert_equal(5, l[0].signs[0].lnum)
+
+ " Undo the delete operation. Sign should be restored to the previous line
+ undo
+ let l = sign_getplaced(bufnr(''))
+ call assert_equal(5, l[0].signs[0].lnum)
+
+ set signcolumn&
sign unplace * group=*
sign undefine sign1
@@ -1788,8 +1820,8 @@ func Test_sign_numcol()
set number
set signcolumn=number
sign define sign1 text==>
- sign place 10 line=1 name=sign1
sign define sign2 text=V
+ sign place 10 line=1 name=sign1
redraw!
call assert_equal("=> 01234", s:ScreenLine(1, 1, 8))
diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim
index 7db033cb65..ee0445c6b4 100644
--- a/src/nvim/testdir/test_startup.vim
+++ b/src/nvim/testdir/test_startup.vim
@@ -520,7 +520,9 @@ func Test_geometry()
call writefile([&columns, &lines, getwinposx(), getwinposy(), string(getwinpos())], "Xtest_geometry")
qall
[CODE]
- if RunVim([], after, '-f -g -geometry 31x13+41+43')
+ " Some window managers have a bar at the top that pushes windows down,
+ " need to use at least 130, let's do 150
+ if RunVim([], after, '-f -g -geometry 31x13+41+150')
let lines = readfile('Xtest_geometry')
" Depending on the GUI library and the windowing system the final size
" might be a bit different, allow for some tolerance. Tuned based on
@@ -528,8 +530,8 @@ func Test_geometry()
call assert_inrange(31, 35, str2nr(lines[0]))
call assert_equal('13', lines[1])
call assert_equal('41', lines[2])
- call assert_equal('43', lines[3])
- call assert_equal('[41, 43]', lines[4])
+ call assert_equal('150', lines[3])
+ call assert_equal('[41, 150]', lines[4])
endif
endif
diff --git a/src/nvim/testdir/test_usercommands.vim b/src/nvim/testdir/test_usercommands.vim
index 6a985d78aa..3ae990e022 100644
--- a/src/nvim/testdir/test_usercommands.vim
+++ b/src/nvim/testdir/test_usercommands.vim
@@ -323,6 +323,11 @@ func Test_CmdErrors()
call assert_fails('com DoCmd :', 'E174:')
comclear
call assert_fails('delcom DoCmd', 'E184:')
+
+ " These used to leak memory
+ call assert_fails('com! -complete=custom,CustomComplete _ :', 'E182:')
+ call assert_fails('com! -complete=custom,CustomComplete docmd :', 'E183:')
+ call assert_fails('com! -complete=custom,CustomComplete -xxx DoCmd :', 'E181:')
endfunc
func CustomComplete(A, L, P)
diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim
index 6e8368f71d..ab63506d3c 100644
--- a/src/nvim/testdir/test_window_cmd.vim
+++ b/src/nvim/testdir/test_window_cmd.vim
@@ -1811,4 +1811,17 @@ function Test_splitkeep_status()
call VerifyScreenDump(buf, 'Test_splitkeep_status_1', {})
endfunction
+function Test_new_help_window_on_error()
+ help change.txt
+ execute "normal! /CTRL-@\<CR>"
+ silent! execute "normal! \<C-W>]"
+
+ let wincount = winnr('$')
+ help 'mod'
+
+ call assert_equal(wincount, winnr('$'))
+ call assert_equal(expand("<cword>"), "'mod'")
+endfunction
+
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim
index 81615b5963..6d27407f82 100644
--- a/src/nvim/testdir/test_writefile.vim
+++ b/src/nvim/testdir/test_writefile.vim
@@ -511,15 +511,15 @@ endfunc
" Tests for reading and writing files with conversion for Win32.
func Test_write_file_encoding()
- throw 'skipped: Nvim does not support :w ++enc=cp1251'
+ throw 'Skipped: Nvim does not support encoding=latin1'
CheckMSWindows
let save_encoding = &encoding
let save_fileencodings = &fileencodings
- set encoding& fileencodings&
+ set encoding=latin1 fileencodings&
let text =<< trim END
- 1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
- 2 cp1251 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
- 3 cp866 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
+ 1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 2 cp1251 text: Vim version 6.2. : 1970 Jan 01
+ 3 cp866 text: Vim version 6.2. ᫥ : 1970 Jan 01
END
call writefile(text, 'Xfile')
edit Xfile
@@ -534,9 +534,9 @@ func Test_write_file_encoding()
.w ++enc=cp866 >> Xtest
.w! ++enc=utf-8 Xutf8
let expected =<< trim END
- 1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
- 1 utf-8 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
- 1 utf-8 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
+ 1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 1 utf-8 text: Vim version 6.2. : 1970 Jan 01
+ 1 utf-8 text: Vim version 6.2. ᫥ : 1970 Jan 01
END
call assert_equal(expected, readfile('Xtest'))
@@ -547,9 +547,9 @@ func Test_write_file_encoding()
.w ++enc=cp866 >> Xtest
.w! ++enc=cp1251 Xcp1251
let expected =<< trim END
- 2 cp1251 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
- 2 cp1251 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
- 2 cp1251 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
+ 2 cp1251 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 2 cp1251 text: Vim version 6.2. : 1970 Jan 01
+ 2 cp1251 text: Vim version 6.2. ᫥ : 1970 Jan 01
END
call assert_equal(expected, readfile('Xtest'))
@@ -560,9 +560,9 @@ func Test_write_file_encoding()
.w ++enc=cp866 >> Xtest
.w! ++enc=cp866 Xcp866
let expected =<< trim END
- 3 cp866 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
- 3 cp866 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
- 3 cp866 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
+ 3 cp866 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 3 cp866 text: Vim version 6.2. : 1970 Jan 01
+ 3 cp866 text: Vim version 6.2. ᫥ : 1970 Jan 01
END
call assert_equal(expected, readfile('Xtest'))
@@ -576,9 +576,9 @@ func Test_write_file_encoding()
e Xcp866
.w ++enc=utf-8 >> Xtest
let expected =<< trim END
- 1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
- 2 cp1251 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
- 3 cp866 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 2 cp1251 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 3 cp866 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
END
call assert_equal(expected, readfile('Xtest'))
@@ -592,9 +592,9 @@ func Test_write_file_encoding()
e Xcp866
.w ++enc=cp1251 >> Xtest
let expected =<< trim END
- 1 utf-8 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
- 2 cp1251 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
- 3 cp866 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
+ 1 utf-8 text: Vim version 6.2. : 1970 Jan 01
+ 2 cp1251 text: Vim version 6.2. : 1970 Jan 01
+ 3 cp866 text: Vim version 6.2. : 1970 Jan 01
END
call assert_equal(expected, readfile('Xtest'))
@@ -608,9 +608,9 @@ func Test_write_file_encoding()
e Xcp866
.w ++enc=cp866 >> Xtest
let expected =<< trim END
- 1 utf-8 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
- 2 cp1251 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
- 3 cp866 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
+ 1 utf-8 text: Vim version 6.2. ᫥ : 1970 Jan 01
+ 2 cp1251 text: Vim version 6.2. ᫥ : 1970 Jan 01
+ 3 cp866 text: Vim version 6.2. ᫥ : 1970 Jan 01
END
call assert_equal(expected, readfile('Xtest'))
diff --git a/src/nvim/tui/terminfo.c b/src/nvim/tui/terminfo.c
index 0f6ae03d35..507e9df21e 100644
--- a/src/nvim/tui/terminfo.c
+++ b/src/nvim/tui/terminfo.c
@@ -7,10 +7,13 @@
#include <string.h>
#include <unibilium.h>
+#include "nvim/api/private/helpers.h"
+#include "nvim/charset.h"
#include "nvim/globals.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/option.h"
+#include "nvim/strings.h"
#include "nvim/tui/terminfo.h"
#include "nvim/tui/terminfo_defs.h"
@@ -147,82 +150,80 @@ unibi_term *terminfo_from_builtin(const char *term, char **termname)
/// Serves a similar purpose as Vim `:set termcap` (removed in Nvim).
///
/// @note adapted from unibilium unibi-dump.c
-void terminfo_info_msg(const unibi_term *const ut)
+/// @return allocated string
+String terminfo_info_msg(const unibi_term *ut, const char *termname)
{
- if (exiting) {
- return;
- }
- msg_puts_title("\n\n--- Terminal info --- {{{\n");
+ StringBuilder data = KV_INITIAL_VALUE;
- char *term;
- get_tty_option("term", &term);
- msg_printf_attr(0, "&term: %s\n", term);
- msg_printf_attr(0, "Description: %s\n", unibi_get_name(ut));
+ kv_printf(data, "&term: %s\n", termname);
+ kv_printf(data, "Description: %s\n", unibi_get_name(ut));
const char **a = unibi_get_aliases(ut);
if (*a) {
- msg_puts("Aliases: ");
+ kv_printf(data, "Aliases: ");
do {
- msg_printf_attr(0, "%s%s\n", *a, a[1] ? " | " : "");
+ kv_printf(data, "%s%s\n", *a, a[1] ? " | " : "");
a++;
} while (*a);
}
- msg_puts("Boolean capabilities:\n");
+ kv_printf(data, "Boolean capabilities:\n");
for (enum unibi_boolean i = unibi_boolean_begin_ + 1;
i < unibi_boolean_end_; i++) {
- msg_printf_attr(0, " %-25s %-10s = %s\n", unibi_name_bool(i),
- unibi_short_name_bool(i),
- unibi_get_bool(ut, i) ? "true" : "false");
+ kv_printf(data, " %-25s %-10s = %s\n", unibi_name_bool(i),
+ unibi_short_name_bool(i),
+ unibi_get_bool(ut, i) ? "true" : "false");
}
- msg_puts("Numeric capabilities:\n");
+ kv_printf(data, "Numeric capabilities:\n");
for (enum unibi_numeric i = unibi_numeric_begin_ + 1;
i < unibi_numeric_end_; i++) {
int n = unibi_get_num(ut, i); // -1 means "empty"
- msg_printf_attr(0, " %-25s %-10s = %d\n", unibi_name_num(i),
- unibi_short_name_num(i), n);
+ kv_printf(data, " %-25s %-10s = %d\n", unibi_name_num(i),
+ unibi_short_name_num(i), n);
}
- msg_puts("String capabilities:\n");
+ kv_printf(data, "String capabilities:\n");
for (enum unibi_string i = unibi_string_begin_ + 1;
i < unibi_string_end_; i++) {
const char *s = unibi_get_str(ut, i);
if (s) {
- msg_printf_attr(0, " %-25s %-10s = ", unibi_name_str(i),
- unibi_short_name_str(i));
+ kv_printf(data, " %-25s %-10s = ", unibi_name_str(i),
+ unibi_short_name_str(i));
// Most of these strings will contain escape sequences.
- msg_outtrans_special(s, false, 0);
- msg_putchar('\n');
+ kv_transstr(&data, s, false);
+ kv_push(data, '\n');
}
}
if (unibi_count_ext_bool(ut)) {
- msg_puts("Extended boolean capabilities:\n");
+ kv_printf(data, "Extended boolean capabilities:\n");
for (size_t i = 0; i < unibi_count_ext_bool(ut); i++) {
- msg_printf_attr(0, " %-25s = %s\n",
- unibi_get_ext_bool_name(ut, i),
- unibi_get_ext_bool(ut, i) ? "true" : "false");
+ kv_printf(data, " %-25s = %s\n",
+ unibi_get_ext_bool_name(ut, i),
+ unibi_get_ext_bool(ut, i) ? "true" : "false");
}
}
if (unibi_count_ext_num(ut)) {
- msg_puts("Extended numeric capabilities:\n");
+ kv_printf(data, "Extended numeric capabilities:\n");
for (size_t i = 0; i < unibi_count_ext_num(ut); i++) {
- msg_printf_attr(0, " %-25s = %d\n",
- unibi_get_ext_num_name(ut, i),
- unibi_get_ext_num(ut, i));
+ kv_printf(data, " %-25s = %d\n",
+ unibi_get_ext_num_name(ut, i),
+ unibi_get_ext_num(ut, i));
}
}
if (unibi_count_ext_str(ut)) {
- msg_puts("Extended string capabilities:\n");
+ kv_printf(data, "Extended string capabilities:\n");
for (size_t i = 0; i < unibi_count_ext_str(ut); i++) {
- msg_printf_attr(0, " %-25s = ", unibi_get_ext_str_name(ut, i));
- msg_outtrans_special(unibi_get_ext_str(ut, i), false, 0);
- msg_putchar('\n');
+ kv_printf(data, " %-25s = ", unibi_get_ext_str_name(ut, i));
+ // NOTE: unibi_get_ext_str(ut, i) might be NULL, as termcap
+ // might include junk data on mac os. kv_transstr will handle this.
+ kv_transstr(&data, unibi_get_ext_str(ut, i), false);
+ kv_push(data, '\n');
}
}
+ kv_push(data, NUL);
- msg_puts("}}}\n");
- xfree(term);
+ return cbuf_as_string(data.items, data.size - 1);
}
diff --git a/src/nvim/tui/terminfo.h b/src/nvim/tui/terminfo.h
index 099df8967f..178d384457 100644
--- a/src/nvim/tui/terminfo.h
+++ b/src/nvim/tui/terminfo.h
@@ -3,6 +3,8 @@
#include <unibilium.h>
+#include "nvim/api/private/defs.h"
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "tui/terminfo.h.generated.h"
#endif
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c
index be7658616f..3010a7b612 100644
--- a/src/nvim/tui/tui.c
+++ b/src/nvim/tui/tui.c
@@ -15,6 +15,8 @@
#include "auto/config.h"
#include "klib/kvec.h"
#include "nvim/api/private/defs.h"
+#include "nvim/api/private/helpers.h"
+#include "nvim/api/vim.h"
#include "nvim/ascii.h"
#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
@@ -25,10 +27,12 @@
#include "nvim/grid_defs.h"
#include "nvim/highlight_defs.h"
#include "nvim/log.h"
+#include "nvim/macros.h"
#include "nvim/main.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/message.h"
+#include "nvim/msgpack_rpc/channel.h"
#include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
@@ -65,8 +69,21 @@
do { \
(var) = unibi_var_from_num((num)); \
} while (0)
+# define UNIBI_SET_STR_VAR(var, str) \
+ do { \
+ (var) = unibi_var_from_str((str)); \
+ } while (0)
#else
-# define UNIBI_SET_NUM_VAR(var, num) (var).i = (num);
+# define UNIBI_SET_NUM_VAR(var, num) \
+ do { \
+ (var).p = NULL; \
+ (var).i = (num); \
+ } while (0)
+# define UNIBI_SET_STR_VAR(var, str) \
+ do { \
+ (var).i = INT_MIN; \
+ (var).p = str; \
+ } while (0)
#endif
typedef struct {
@@ -85,6 +102,7 @@ struct TUIData {
TermInput input;
uv_loop_t write_loop;
unibi_term *ut;
+ char *term; // value of $TERM
union {
uv_tty_t tty;
uv_pipe_t pipe;
@@ -108,6 +126,7 @@ struct TUIData {
bool mouse_move_enabled;
bool busy, is_invisible, want_invisible;
bool cork, overflow;
+ bool set_cursor_color_as_str;
bool cursor_color_changed;
bool is_starting;
FILE *screenshot;
@@ -118,6 +137,7 @@ struct TUIData {
bool default_attr;
bool can_clear_attr;
ModeShape showing_mode;
+ Integer verbose;
struct {
int enable_mouse, disable_mouse;
int enable_mouse_move, disable_mouse_move;
@@ -236,6 +256,7 @@ static void terminfo_start(UI *ui)
data->busy = false;
data->cork = false;
data->overflow = false;
+ data->set_cursor_color_as_str = false;
data->cursor_color_changed = false;
data->showing_mode = SHAPE_IDX_N;
data->unibi_ext.enable_mouse = -1;
@@ -280,6 +301,7 @@ static void terminfo_start(UI *ui)
os_env_var_unlock();
if (data->ut) {
termname = xstrdup(term);
+ data->term = xstrdup(term);
}
}
if (!data->ut) {
@@ -494,9 +516,6 @@ static void tui_main(UIBridgeData *bridge, UI *ui)
// Allow main thread to continue, we are ready to handle UI callbacks.
CONTINUE(bridge);
- loop_schedule_deferred(&main_loop,
- event_create(show_termcap_event, 1, data->ut));
-
// "Active" loop: first ~100 ms of startup.
for (size_t ms = 0; ms < 100 && !tui_is_stopped(ui);) {
ms += (loop_poll_events(&tui_loop, 20) ? 20 : 1);
@@ -518,6 +537,7 @@ static void tui_main(UIBridgeData *bridge, UI *ui)
kv_destroy(data->invalid_regions);
kv_destroy(data->attrs);
xfree(data->space_buf);
+ xfree(data->term);
xfree(data);
}
@@ -1180,7 +1200,13 @@ static void tui_set_mode(UI *ui, ModeShape mode)
// Hopefully the user's default cursor color is inverse.
unibi_out_ext(ui, data->unibi_ext.reset_cursor_color);
} else {
- UNIBI_SET_NUM_VAR(data->params[0], aep.rgb_bg_color);
+ if (data->set_cursor_color_as_str) {
+ char hexbuf[8];
+ snprintf(hexbuf, 7 + 1, "#%06x", aep.rgb_bg_color);
+ UNIBI_SET_STR_VAR(data->params[0], hexbuf);
+ } else {
+ UNIBI_SET_NUM_VAR(data->params[0], aep.rgb_bg_color);
+ }
unibi_out_ext(ui, data->unibi_ext.set_cursor_color);
data->cursor_color_changed = true;
}
@@ -1225,6 +1251,11 @@ static void tui_mode_change(UI *ui, String mode, Integer mode_idx)
}
#endif
tui_set_mode(ui, (ModeShape)mode_idx);
+ if (data->is_starting) {
+ if (data->verbose >= 3) {
+ show_verbose_terminfo(data);
+ }
+ }
data->is_starting = false; // mode entered, no longer starting
data->showing_mode = (ModeShape)mode_idx;
}
@@ -1369,21 +1400,53 @@ static void tui_flush(UI *ui)
}
/// Dumps termcap info to the messages area, if 'verbose' >= 3.
-static void show_termcap_event(void **argv)
+static void show_verbose_terminfo(TUIData *data)
{
- if (p_verbose < 3) {
- return;
- }
- const unibi_term *const ut = argv[0];
+ const unibi_term *const ut = data->ut;
if (!ut) {
abort();
}
- verbose_enter();
- // XXX: (future) if unibi_term is modified (e.g. after a terminal
- // query-response) this is a race condition.
- terminfo_info_msg(ut);
- verbose_leave();
- verbose_stop(); // flush now
+
+ Array chunks = ARRAY_DICT_INIT;
+ Array title = ARRAY_DICT_INIT;
+ ADD(title, STRING_OBJ(cstr_to_string("\n\n--- Terminal info --- {{{\n")));
+ ADD(title, STRING_OBJ(cstr_to_string("Title")));
+ ADD(chunks, ARRAY_OBJ(title));
+ Array info = ARRAY_DICT_INIT;
+ String str = terminfo_info_msg(ut, data->term);
+ ADD(info, STRING_OBJ(str));
+ ADD(chunks, ARRAY_OBJ(info));
+ Array end_fold = ARRAY_DICT_INIT;
+ ADD(end_fold, STRING_OBJ(cstr_to_string("}}}\n")));
+ ADD(end_fold, STRING_OBJ(cstr_to_string("Title")));
+ ADD(chunks, ARRAY_OBJ(end_fold));
+
+ if (ui_client_channel_id) {
+ Array args = ARRAY_DICT_INIT;
+ ADD(args, ARRAY_OBJ(chunks));
+ ADD(args, BOOLEAN_OBJ(true)); // history
+ Dictionary opts = ARRAY_DICT_INIT;
+ PUT(opts, "verbose", BOOLEAN_OBJ(true));
+ ADD(args, DICTIONARY_OBJ(opts));
+ rpc_send_event(ui_client_channel_id, "nvim_echo", args);
+ } else {
+ loop_schedule_deferred(&main_loop, event_create(verbose_terminfo_event, 2,
+ chunks.items, chunks.size));
+ }
+}
+
+static void verbose_terminfo_event(void **argv)
+{
+ Array chunks = { .items = argv[0], .size = (size_t)argv[1] };
+ Dict(echo_opts) opts = { .verbose = BOOLEAN_OBJ(true) };
+ Error err = ERROR_INIT;
+ nvim_echo(chunks, true, &opts, &err);
+ api_free_array(chunks);
+ if (ERROR_SET(&err)) {
+ fprintf(stderr, "TUI bought the farm: %s\n", err.msg);
+ exit(1);
+ }
+ api_clear_error(&err);
}
#ifdef UNIX
@@ -1488,6 +1551,8 @@ static void tui_option_set(UI *ui, String name, Object value)
data->input.ttimeout = value.data.boolean;
} else if (strequal(name.data, "ttimeoutlen")) {
data->input.ttimeoutlen = (long)value.data.integer;
+ } else if (strequal(name.data, "verbose")) {
+ data->verbose = value.data.integer;
}
}
@@ -2148,10 +2213,20 @@ static void augment_terminfo(TUIData *data, const char *term, long vte_version,
&& (vte_version == 0 || vte_version >= 3900)) {
// Supported in urxvt, newer VTE.
data->unibi_ext.set_cursor_color = (int)unibi_add_ext_str(ut, "ext.set_cursor_color",
- "\033]12;#%p1%06x\007");
+ "\033]12;%p1%s\007");
}
}
if (-1 != data->unibi_ext.set_cursor_color) {
+ // Some terminals supporting cursor color changing specify their Cs
+ // capability to take a string parameter. Others take a numeric parameter.
+ // If and only if the format string contains `%s` we assume a string
+ // parameter. #20628
+ const char *set_cursor_color =
+ unibi_get_ext_str(ut, (unsigned)data->unibi_ext.set_cursor_color);
+ if (set_cursor_color) {
+ data->set_cursor_color_as_str = strstr(set_cursor_color, "%s") != NULL;
+ }
+
data->unibi_ext.reset_cursor_color = unibi_find_ext_str(ut, "Cr");
if (-1 == data->unibi_ext.reset_cursor_color) {
data->unibi_ext.reset_cursor_color = (int)unibi_add_ext_str(ut, "ext.reset_cursor_color",
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index 05adc3c6d3..0777d1309d 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -1343,9 +1343,9 @@ write_error:
#ifdef HAVE_ACL
if (buf->b_ffname != NULL) {
// For systems that support ACL: get the ACL from the original file.
- vim_acl_T acl = mch_get_acl((char_u *)buf->b_ffname);
- mch_set_acl((char_u *)file_name, acl);
- mch_free_acl(acl);
+ vim_acl_T acl = os_get_acl((char_u *)buf->b_ffname);
+ os_set_acl((char_u *)file_name, acl);
+ os_free_acl(acl);
}
#endif
diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c
index ca5307fe24..bc47b1b807 100644
--- a/src/nvim/usercmd.c
+++ b/src/nvim/usercmd.c
@@ -943,7 +943,7 @@ void ex_command(exarg_T *eap)
end = skiptowhite(p);
if (uc_scan_attr(p, (size_t)(end - p), &argt, &def, &flags, &compl, (char_u **)&compl_arg,
&addr_type_arg) == FAIL) {
- return;
+ goto theend;
}
p = skipwhite(end);
}
@@ -953,7 +953,7 @@ void ex_command(exarg_T *eap)
end = uc_validate_name(name);
if (!end) {
emsg(_("E182: Invalid command name"));
- return;
+ goto theend;
}
name_len = (size_t)(end - name);
@@ -971,7 +971,12 @@ void ex_command(exarg_T *eap)
} else {
uc_add_command(name, name_len, p, argt, def, flags, compl, compl_arg, LUA_NOREF, LUA_NOREF,
addr_type_arg, LUA_NOREF, eap->forceit);
+
+ return; // success
}
+
+theend:
+ xfree(compl_arg);
}
/// ":comclear"
diff --git a/src/nvim/vim.h b/src/nvim/vim.h
index 3a927d6a55..59b818fad7 100644
--- a/src/nvim/vim.h
+++ b/src/nvim/vim.h
@@ -201,7 +201,6 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext()
#define STRCPY(d, s) strcpy((char *)(d), (char *)(s)) // NOLINT(runtime/printf)
#define STRLCPY(d, s, n) xstrlcpy((char *)(d), (char *)(s), (size_t)(n))
-#define STRNCMP(d, s, n) strncmp((char *)(d), (char *)(s), (size_t)(n))
#ifdef HAVE_STRCASECMP
# define STRICMP(d, s) strcasecmp((char *)(d), (char *)(s))
#else
@@ -253,8 +252,8 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext()
// been seen at that stage. But it must be before globals.h, where error_ga
// is declared.
#ifndef MSWIN
-# define mch_errmsg(str) fprintf(stderr, "%s", (str))
-# define mch_msg(str) printf("%s", (str))
+# define os_errmsg(str) fprintf(stderr, "%s", (str))
+# define os_msg(str) printf("%s", (str))
#endif
#include "nvim/buffer_defs.h" // buffer and windows
diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c
index 24dfb38ae0..0b19526fa0 100644
--- a/src/nvim/viml/parser/expressions.c
+++ b/src/nvim/viml/parser/expressions.c
@@ -1825,7 +1825,7 @@ static void parse_quoted_string(ParserState *const pstate, ExprASTNode *const no
if (p[1] != '*') {
flags |= FSK_SIMPLIFY;
}
- const size_t special_len = trans_special((const char_u **)&p, (size_t)(e - p),
+ const size_t special_len = trans_special(&p, (size_t)(e - p),
(char_u *)v_p, flags, false, NULL);
if (special_len != 0) {
v_p += special_len;
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 05694a8b6d..d026f4551a 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -494,6 +494,7 @@ newwindow:
// Execute the command right here, required when
// "wincmd ]" was used in a function.
do_nv_ident(Ctrl_RSB, NUL);
+ postponed_split = 0;
break;
// edit file name under cursor in a new window
@@ -594,6 +595,7 @@ wingotofile:
// Execute the command right here, required when
// "wincmd g}" was used in a function.
do_nv_ident('g', xchar);
+ postponed_split = 0;
break;
case 'f': // CTRL-W gf: "gf" in a new tab page