aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/stdlib.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-05-24 19:18:11 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-05-24 19:18:11 +0000
commitff7ed8f586589d620a806c3758fac4a47a8e7e15 (patch)
tree729bbcb92231538fa61dab6c3d890b025484b7f5 /src/nvim/lua/stdlib.c
parent376914f419eb08fdf4c1a63a77e1f035898a0f10 (diff)
parent28c04948a1c887a1cc0cb64de79fa32631700466 (diff)
downloadrneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.gz
rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.bz2
rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'src/nvim/lua/stdlib.c')
-rw-r--r--src/nvim/lua/stdlib.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c
index 8f58fd1a1a..22ee0a1c98 100644
--- a/src/nvim/lua/stdlib.c
+++ b/src/nvim/lua/stdlib.c
@@ -107,15 +107,15 @@ static int regex_match_line(lua_State *lstate)
}
char *line = ml_get_buf(buf, rownr + 1);
- size_t len = strlen(line);
+ colnr_T len = ml_get_buf_len(buf, rownr + 1);
- if (start < 0 || (size_t)start > len) {
+ if (start < 0 || start > len) {
return luaL_error(lstate, "invalid start");
}
char save = NUL;
if (end >= 0) {
- if ((size_t)end > len || end < start) {
+ if (end > len || end < start) {
return luaL_error(lstate, "invalid end");
}
save = line[end];
@@ -449,7 +449,7 @@ int nlua_getvar(lua_State *lstate)
if (di == NULL) {
return 0; // nil
}
- nlua_push_typval(lstate, &di->di_tv, false);
+ nlua_push_typval(lstate, &di->di_tv, 0);
return 1;
}
@@ -543,14 +543,27 @@ static int nlua_iconv(lua_State *lstate)
return 1;
}
-// Update foldlevels (e.g., by evaluating 'foldexpr') for all lines in the current window without
-// invoking other side effects. Unlike `zx`, it does not close manually opened folds and does not
-// open folds under the cursor.
+// Update foldlevels (e.g., by evaluating 'foldexpr') for the given line range in the given window,
+// without invoking other side effects. Unlike `zx`, it does not close manually opened folds and
+// does not open folds under the cursor.
static int nlua_foldupdate(lua_State *lstate)
{
- curwin->w_foldinvalid = true; // recompute folds
- foldUpdate(curwin, 1, (linenr_T)MAXLNUM);
- curwin->w_foldinvalid = false;
+ handle_T window = (handle_T)luaL_checkinteger(lstate, 1);
+ win_T *win = handle_get_window(window);
+ if (!win) {
+ return luaL_error(lstate, "invalid window");
+ }
+ // input is zero-based end-exclusive range
+ linenr_T top = (linenr_T)luaL_checkinteger(lstate, 2) + 1;
+ if (top < 1 || top > win->w_buffer->b_ml.ml_line_count) {
+ return luaL_error(lstate, "invalid top");
+ }
+ linenr_T bot = (linenr_T)luaL_checkinteger(lstate, 3);
+ if (top > bot) {
+ return luaL_error(lstate, "invalid bot");
+ }
+
+ foldUpdate(win, top, bot);
return 0;
}