aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/README.md8
-rw-r--r--src/nvim/api/buffer.c4
-rw-r--r--src/nvim/api/command.c6
-rw-r--r--src/nvim/api/extmark.c2
-rw-r--r--src/nvim/autocmd.c8
-rw-r--r--src/nvim/charset.c4
-rw-r--r--src/nvim/cmdhist.c10
-rw-r--r--src/nvim/drawline.c5
-rw-r--r--src/nvim/eval/funcs.c3
-rw-r--r--src/nvim/ex_cmds.c2
-rw-r--r--src/nvim/main.c2
-rw-r--r--src/nvim/message.c14
-rw-r--r--src/nvim/move.c22
-rw-r--r--src/nvim/option.c8
-rw-r--r--src/nvim/path.c4
-rw-r--r--src/nvim/statusline.c35
16 files changed, 78 insertions, 59 deletions
diff --git a/src/nvim/README.md b/src/nvim/README.md
index 75155fb9c6..0de0fb9a3f 100644
--- a/src/nvim/README.md
+++ b/src/nvim/README.md
@@ -208,15 +208,11 @@ To debug the main process, you can debug the nvim binary with the `--headless`
flag which does not launch the TUI and will allow you to set breakpoints in code
not related to TUI rendering like so:
-```
-lldb -- ./build/bin/nvim --headless --listen ~/.cache/nvim/debug-server.pipe
-```
+ lldb -- ./build/bin/nvim --headless --listen ~/.cache/nvim/debug-server.pipe
You can then attach to the headless process to interact with the editor like so:
-```
-./build/bin/nvim --remote-ui --server ~/.cache/nvim/debug-server.pipe
-```
+ ./build/bin/nvim --remote-ui --server ~/.cache/nvim/debug-server.pipe
Conversely for debugging TUI rendering, you can start a headless process and
debug the remote-ui process multiple times without losing editor state.
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 4c3faf8d8b..5bf7295bb3 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -48,7 +48,7 @@
///
/// \brief For more information on buffers, see |buffers|
///
-/// Unloaded Buffers:~
+/// Unloaded Buffers: ~
///
/// Buffers may be unloaded by the |:bunload| command or the buffer's
/// |'bufhidden'| option. When a buffer is unloaded its file contents are freed
@@ -84,7 +84,7 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err)
/// Activates buffer-update events on a channel, or as Lua callbacks.
///
/// Example (Lua): capture buffer updates in a global `events` variable
-/// (use "print(vim.inspect(events))" to see its contents):
+/// (use "vim.print(events)" to see its contents):
/// <pre>lua
/// events = {}
/// vim.api.nvim_buf_attach(0, false, {
diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c
index eba209b424..3157132256 100644
--- a/src/nvim/api/command.c
+++ b/src/nvim/api/command.c
@@ -393,6 +393,12 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error
VALIDATE(!is_cmd_ni(ea.cmdidx), "Command not implemented: %s", cmdname, {
goto end;
});
+ const char *fullname = IS_USER_CMDIDX(ea.cmdidx)
+ ? get_user_command_name(ea.useridx, ea.cmdidx)
+ : get_command_name(NULL, ea.cmdidx);
+ VALIDATE(strncmp(fullname, cmdname, strlen(cmdname)) == 0, "Invalid command: \"%s\"", cmdname, {
+ goto end;
+ });
// Get the command flags so that we can know what type of arguments the command uses.
// Not required for a user command since `find_ex_command` already deals with it in that case.
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c
index a101e1bbf1..0608a8961d 100644
--- a/src/nvim/api/extmark.c
+++ b/src/nvim/api/extmark.c
@@ -320,7 +320,7 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id,
/// local ms = api.nvim_buf_get_extmarks(0, ns, {2,0}, {2,0}, {})
/// -- Get all marks in this buffer + namespace.
/// local all = api.nvim_buf_get_extmarks(0, ns, 0, -1, {})
-/// print(vim.inspect(ms))
+/// vim.print(ms)
/// </pre>
///
/// @param buffer Buffer handle, or 0 for current buffer
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index 427bce0e80..36f0183fd8 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -1783,8 +1783,14 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force
check_lnums_nested(true);
}
+ const int save_did_emsg = did_emsg;
+ const bool save_ex_pressedreturn = get_pressedreturn();
+
// Execute the autocmd. The `getnextac` callback handles iteration.
- do_cmdline(NULL, getnextac, (void *)&patcmd, DOCMD_NOWAIT | DOCMD_VERBOSE | DOCMD_REPEAT);
+ do_cmdline(NULL, getnextac, &patcmd, DOCMD_NOWAIT | DOCMD_VERBOSE | DOCMD_REPEAT);
+
+ did_emsg += save_did_emsg;
+ set_pressedreturn(save_ex_pressedreturn);
if (nesting == 1) {
// restore cursor and topline, unless they were changed
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 49890a460a..c2745a66a0 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -645,8 +645,8 @@ size_t transchar_hex(char *const buf, const int c)
size_t i = 0;
buf[i++] = '<';
- if (c > 255) {
- if (c > 255 * 256) {
+ if (c > 0xFF) {
+ if (c > 0xFFFF) {
buf[i++] = (char)nr2hex((unsigned)c >> 20);
buf[i++] = (char)nr2hex((unsigned)c >> 16);
}
diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c
index fc84cecc1a..072898706b 100644
--- a/src/nvim/cmdhist.c
+++ b/src/nvim/cmdhist.c
@@ -204,7 +204,7 @@ static inline void clear_hist_entry(histentry_T *hisptr)
/// If 'move_to_front' is true, matching entry is moved to end of history.
///
/// @param move_to_front Move the entry to the front if it exists
-static int in_history(int type, char *str, int move_to_front, int sep)
+static int in_history(int type, const char *str, int move_to_front, int sep)
{
int last_i = -1;
@@ -238,7 +238,7 @@ static int in_history(int type, char *str, int move_to_front, int sep)
}
list_T *const list = history[type][i].additional_elements;
- str = history[type][i].hisstr;
+ char *const save_hisstr = history[type][i].hisstr;
while (i != hisidx[type]) {
if (++i >= hislen) {
i = 0;
@@ -248,7 +248,7 @@ static int in_history(int type, char *str, int move_to_front, int sep)
}
tv_list_unref(list);
history[type][i].hisnum = ++hisnum[type];
- history[type][i].hisstr = str;
+ history[type][i].hisstr = save_hisstr;
history[type][i].timestamp = os_time();
history[type][i].additional_elements = NULL;
return true;
@@ -295,7 +295,7 @@ static int last_maptick = -1; // last seen maptick
/// @param histype may be one of the HIST_ values.
/// @param in_map consider maptick when inside a mapping
/// @param sep separator character used (search hist)
-void add_to_history(int histype, char *new_entry, int in_map, int sep)
+void add_to_history(int histype, const char *new_entry, int in_map, int sep)
{
histentry_T *hisptr;
@@ -538,7 +538,7 @@ void f_histadd(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
init_history();
- add_to_history(histype, (char *)str, false, NUL);
+ add_to_history(histype, str, false, NUL);
rettv->vval.v_number = true;
}
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index b8dc1297cc..7aad47df00 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -747,6 +747,11 @@ static void get_statuscol_display_info(statuscol_T *stcp, winlinevars_T *wlv)
}
// Skip over empty highlight sections
} while (wlv->n_extra == 0 && stcp->textp < stcp->text_end);
+ if (wlv->n_extra > 0) {
+ static char transbuf[MAX_NUMBERWIDTH * MB_MAXBYTES + 1];
+ wlv->n_extra = (int)transstr_buf(wlv->p_extra, wlv->n_extra, transbuf, sizeof transbuf, true);
+ wlv->p_extra = transbuf;
+ }
}
static void handle_breakindent(win_T *wp, winlinevars_T *wlv)
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 33f1ed51e5..99fec3d773 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -873,8 +873,7 @@ static void f_confirm(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
if (!error) {
- rettv->vval.v_number = do_dialog(type, NULL, (char *)message, (char *)buttons, def, NULL,
- false);
+ rettv->vval.v_number = do_dialog(type, NULL, message, buttons, def, NULL, false);
}
}
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 40afb3250c..591f8febdc 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -389,7 +389,7 @@ typedef struct {
static int string_compare(const void *s1, const void *s2) FUNC_ATTR_NONNULL_ALL
{
if (sort_lc) {
- return strcoll((char *)s1, (char *)s2);
+ return strcoll((const char *)s1, (const char *)s2);
}
return sort_ic ? STRICMP(s1, s2) : strcmp(s1, s2);
}
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 83e56c3066..9b364f8c35 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -1361,7 +1361,7 @@ static void command_line_scan(mparm_T *parmp)
}
parmp->luaf = argv[0];
argc--;
- if (argc > 0) { // Lua args after "-l <file>".
+ if (argc >= 0) { // Lua args after "-l <file>".
parmp->lua_arg0 = parmp->argc - argc;
argc = 0;
}
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 0064f0358b..c60e5c31fd 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -3511,8 +3511,8 @@ void msg_advance(int col)
/// @param textfiel IObuff for inputdialog(), NULL otherwise
/// @param ex_cmd when true pressing : accepts default and starts Ex command
/// @returns 0 if cancelled, otherwise the nth button (1-indexed).
-int do_dialog(int type, char *title, char *message, char *buttons, int dfltbutton, char *textfield,
- int ex_cmd)
+int do_dialog(int type, const char *title, const char *message, const char *buttons, int dfltbutton,
+ const char *textfield, int ex_cmd)
{
int retval = 0;
char *hotkeys;
@@ -3619,7 +3619,7 @@ static int copy_char(const char *from, char *to, bool lowercase)
/// corresponding button has a hotkey
///
/// @return Pointer to memory allocated for storing hotkeys
-static char *console_dialog_alloc(const char *message, char *buttons, bool has_hotkey[])
+static char *console_dialog_alloc(const char *message, const char *buttons, bool has_hotkey[])
{
int lenhotkey = HOTK_LEN; // count first button
has_hotkey[0] = false;
@@ -3627,7 +3627,7 @@ static char *console_dialog_alloc(const char *message, char *buttons, bool has_h
// Compute the size of memory to allocate.
int len = 0;
int idx = 0;
- char *r = buttons;
+ const char *r = buttons;
while (*r) {
if (*r == DLG_BUTTON_SEP) {
len += 3; // '\n' -> ', '; 'x' -> '(x)'
@@ -3673,7 +3673,7 @@ static char *console_dialog_alloc(const char *message, char *buttons, bool has_h
/// The hotkeys can be multi-byte characters, but without combining chars.
///
/// @return an allocated string with hotkeys.
-static char *msg_show_console_dialog(char *message, char *buttons, int dfltbutton)
+static char *msg_show_console_dialog(const char *message, const char *buttons, int dfltbutton)
FUNC_ATTR_NONNULL_RET
{
bool has_hotkey[HAS_HOTKEY_LEN] = { false };
@@ -3693,7 +3693,7 @@ static char *msg_show_console_dialog(char *message, char *buttons, int dfltbutto
/// @param has_hotkey An element in this array is true if corresponding button
/// has a hotkey
/// @param[out] hotkeys_ptr Pointer to the memory location where hotkeys will be copied
-static void copy_hotkeys_and_msg(const char *message, char *buttons, int default_button_idx,
+static void copy_hotkeys_and_msg(const char *message, const char *buttons, int default_button_idx,
const bool has_hotkey[], char *hotkeys_ptr)
{
*confirm_msg = '\n';
@@ -3716,7 +3716,7 @@ static void copy_hotkeys_and_msg(const char *message, char *buttons, int default
}
int idx = 0;
- char *r = buttons;
+ const char *r = buttons;
while (*r) {
if (*r == DLG_BUTTON_SEP) {
*msgp++ = ',';
diff --git a/src/nvim/move.c b/src/nvim/move.c
index f859294d65..cc02808e4c 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -1954,17 +1954,19 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
int top_plines = plines_win_nofill(curwin, curwin->w_topline, false);
int skip_lines = 0;
int width1 = curwin->w_width_inner - curwin_col_off();
- int width2 = width1 + curwin_col_off2();
- // similar formula is used in curs_columns()
- if (curwin->w_skipcol > width1) {
- skip_lines += (curwin->w_skipcol - width1) / width2 + 1;
- } else if (curwin->w_skipcol > 0) {
- skip_lines = 1;
- }
+ if (width1 > 0) {
+ int width2 = width1 + curwin_col_off2();
+ // similar formula is used in curs_columns()
+ if (curwin->w_skipcol > width1) {
+ skip_lines += (curwin->w_skipcol - width1) / width2 + 1;
+ } else if (curwin->w_skipcol > 0) {
+ skip_lines = 1;
+ }
- top_plines -= skip_lines;
- if (top_plines > curwin->w_height_inner) {
- scrolled += (top_plines - curwin->w_height_inner);
+ top_plines -= skip_lines;
+ if (top_plines > curwin->w_height_inner) {
+ scrolled += (top_plines - curwin->w_height_inner);
+ }
}
}
}
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 673c6280d3..0002329da3 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -794,10 +794,14 @@ static void do_set_num(int opt_idx, int opt_flags, char **argp, int nextchar, co
if (nextchar == '&') {
value = (long)(intptr_t)options[opt_idx].def_val;
} else if (nextchar == '<') {
- // For 'undolevels' NO_LOCAL_UNDOLEVEL means to
- // use the global value.
if ((long *)varp == &curbuf->b_p_ul && opt_flags == OPT_LOCAL) {
+ // for 'undolevels' NO_LOCAL_UNDOLEVEL means using the global value
value = NO_LOCAL_UNDOLEVEL;
+ } else if (opt_flags == OPT_LOCAL
+ && ((long *)varp == &curwin->w_p_siso
+ || (long *)varp == &curwin->w_p_so)) {
+ // for 'scrolloff'/'sidescrolloff' -1 means using the global value
+ value = -1;
} else {
value = *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
}
diff --git a/src/nvim/path.c b/src/nvim/path.c
index ea0d5a8be1..0927a3a102 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1810,7 +1810,7 @@ bool path_with_extension(const char *path, const char *extension)
}
/// Return true if "name" is a full (absolute) path name or URL.
-bool vim_isAbsName(char *name)
+bool vim_isAbsName(const char *name)
{
return path_with_url(name) != 0 || path_is_absolute(name);
}
@@ -1871,7 +1871,7 @@ char *fix_fname(const char *fname)
#ifdef UNIX
return FullName_save(fname, true);
#else
- if (!vim_isAbsName((char *)fname)
+ if (!vim_isAbsName(fname)
|| strstr(fname, "..") != NULL
|| strstr(fname, "//") != NULL
# ifdef BACKSLASH_IN_FILENAME
diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c
index b89d346fbf..f2502fe1e3 100644
--- a/src/nvim/statusline.c
+++ b/src/nvim/statusline.c
@@ -248,8 +248,8 @@ StlClickDefinition *stl_alloc_click_defs(StlClickDefinition *cdp, long width, si
}
/// Fill the click definitions array if needed.
-void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_recs, char *buf,
- int width, bool tabline)
+void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_recs,
+ const char *buf, int width, bool tabline)
{
if (click_defs == NULL) {
return;
@@ -263,6 +263,7 @@ void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_r
};
for (int i = 0; click_recs[i].start != NULL; i++) {
len += vim_strnsize(buf, (int)(click_recs[i].start - buf));
+ assert(len <= width);
if (col < len) {
while (col < len) {
click_defs[col++] = cur_click_def;
@@ -270,7 +271,7 @@ void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_r
} else {
xfree(cur_click_def.func);
}
- buf = (char *)click_recs[i].start;
+ buf = click_recs[i].start;
cur_click_def = click_recs[i].def;
if (!tabline && !(cur_click_def.type == kStlClickDisabled
|| cur_click_def.type == kStlClickFuncRun)) {
@@ -905,9 +906,9 @@ int build_statuscol_str(win_T *wp, linenr_T lnum, long relnum, statuscol_T *stcp
// Only update click definitions once per window per redraw
if (fillclick) {
stl_clear_click_defs(wp->w_statuscol_click_defs, wp->w_statuscol_click_defs_size);
- wp->w_statuscol_click_defs = stl_alloc_click_defs(wp->w_statuscol_click_defs, width,
+ wp->w_statuscol_click_defs = stl_alloc_click_defs(wp->w_statuscol_click_defs, stcp->width,
&wp->w_statuscol_click_defs_size);
- stl_fill_click_defs(wp->w_statuscol_click_defs, clickrec, stcp->text, width, false);
+ stl_fill_click_defs(wp->w_statuscol_click_defs, clickrec, stcp->text, stcp->width, false);
}
return width;
@@ -2052,17 +2053,6 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
// Put a `<` to mark where we truncated at
*trunc_p = '<';
-
- if (width + 1 < maxwidth) {
- // Advance the pointer to the end of the string
- trunc_p = trunc_p + strlen(trunc_p);
- }
-
- // Fill up for half a double-wide character.
- while (++width < maxwidth) {
- MB_CHAR2BYTES(fillchar, trunc_p);
- *trunc_p = NUL;
- }
// }
// { Change the start point for items based on
@@ -2077,13 +2067,24 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
// to be moved backwards.
if (stl_items[i].start >= trunc_end_p) {
stl_items[i].start -= item_offset;
+ } else {
// Anything inside the truncated area is set to start
// at the `<` truncation character.
- } else {
stl_items[i].start = trunc_p;
}
}
// }
+
+ if (width + 1 < maxwidth) {
+ // Advance the pointer to the end of the string
+ trunc_p = trunc_p + strlen(trunc_p);
+ }
+
+ // Fill up for half a double-wide character.
+ while (++width < maxwidth) {
+ MB_CHAR2BYTES(fillchar, trunc_p);
+ *trunc_p = NUL;
+ }
}
width = maxwidth;