mirror of
https://github.com/neovim/neovim.git
synced 2025-10-02 16:08:36 +00:00
Merge pull request #15079 from shadmansaleh/feat/verbose_lua
feat(lua): add :verbose support for lua config
This commit is contained in:
@@ -953,11 +953,11 @@ ArrayOf(Dictionary) nvim_buf_get_keymap(uint64_t channel_id, Buffer buffer, Stri
|
||||
/// @see |nvim_set_keymap()|
|
||||
///
|
||||
/// @param buffer Buffer handle, or 0 for current buffer
|
||||
void nvim_buf_set_keymap(Buffer buffer, String mode, String lhs, String rhs, Dict(keymap) *opts,
|
||||
Error *err)
|
||||
void nvim_buf_set_keymap(uint64_t channel_id, Buffer buffer, String mode, String lhs, String rhs,
|
||||
Dict(keymap) *opts, Error *err)
|
||||
FUNC_API_SINCE(6)
|
||||
{
|
||||
modify_keymap(buffer, false, mode, lhs, rhs, opts, err);
|
||||
modify_keymap(channel_id, buffer, false, mode, lhs, rhs, opts, err);
|
||||
}
|
||||
|
||||
/// Unmaps a buffer-local |mapping| for the given mode.
|
||||
@@ -965,11 +965,12 @@ void nvim_buf_set_keymap(Buffer buffer, String mode, String lhs, String rhs, Dic
|
||||
/// @see |nvim_del_keymap()|
|
||||
///
|
||||
/// @param buffer Buffer handle, or 0 for current buffer
|
||||
void nvim_buf_del_keymap(Buffer buffer, String mode, String lhs, Error *err)
|
||||
void nvim_buf_del_keymap(uint64_t channel_id, Buffer buffer, String mode,
|
||||
String lhs, Error *err)
|
||||
FUNC_API_SINCE(6)
|
||||
{
|
||||
String rhs = { .data = "", .size = 0 };
|
||||
modify_keymap(buffer, true, mode, lhs, rhs, NULL, err);
|
||||
modify_keymap(channel_id, buffer, true, mode, lhs, rhs, NULL, err);
|
||||
}
|
||||
|
||||
/// Gets a map of buffer-local |user-commands|.
|
||||
|
@@ -22,11 +22,11 @@
|
||||
|
||||
/// @deprecated
|
||||
/// @see nvim_exec
|
||||
String nvim_command_output(String command, Error *err)
|
||||
String nvim_command_output(uint64_t channel_id, String command, Error *err)
|
||||
FUNC_API_SINCE(1)
|
||||
FUNC_API_DEPRECATED_SINCE(7)
|
||||
{
|
||||
return nvim_exec(command, true, err);
|
||||
return nvim_exec(channel_id, command, true, err);
|
||||
}
|
||||
|
||||
/// @deprecated Use nvim_exec_lua() instead.
|
||||
|
@@ -586,8 +586,8 @@ Array string_to_array(const String input, bool crlf)
|
||||
/// @param buffer Buffer handle for a specific buffer, or 0 for the current
|
||||
/// buffer, or -1 to signify global behavior ("all buffers")
|
||||
/// @param is_unmap When true, removes the mapping that matches {lhs}.
|
||||
void modify_keymap(Buffer buffer, bool is_unmap, String mode, String lhs, String rhs,
|
||||
Dict(keymap) *opts, Error *err)
|
||||
void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mode, String lhs,
|
||||
String rhs, Dict(keymap) *opts, Error *err)
|
||||
{
|
||||
LuaRef lua_funcref = LUA_NOREF;
|
||||
bool global = (buffer == -1);
|
||||
@@ -600,6 +600,8 @@ void modify_keymap(Buffer buffer, bool is_unmap, String mode, String lhs, String
|
||||
return;
|
||||
}
|
||||
|
||||
const sctx_T save_current_sctx = api_set_sctx(channel_id);
|
||||
|
||||
if (opts != NULL && opts->callback.type == kObjectTypeLuaRef) {
|
||||
lua_funcref = opts->callback.data.luaref;
|
||||
opts->callback.data.luaref = LUA_NOREF;
|
||||
@@ -711,6 +713,7 @@ void modify_keymap(Buffer buffer, bool is_unmap, String mode, String lhs, String
|
||||
|
||||
parsed_args.rhs_lua = LUA_NOREF; // don't clear ref on success
|
||||
fail_and_free:
|
||||
current_sctx = save_current_sctx;
|
||||
NLUA_CLEAR_REF(parsed_args.rhs_lua);
|
||||
xfree(parsed_args.rhs);
|
||||
xfree(parsed_args.orig_rhs);
|
||||
@@ -1623,3 +1626,20 @@ int find_sid(uint64_t channel_id)
|
||||
return SID_API_CLIENT;
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets sctx for API calls.
|
||||
///
|
||||
/// @param channel_id api clients id. Used to determine if it's a internal
|
||||
/// call or a rpc call.
|
||||
/// @return returns previous value of current_sctx. To be used
|
||||
/// to be used for restoring sctx to previous state.
|
||||
sctx_T api_set_sctx(uint64_t channel_id)
|
||||
{
|
||||
sctx_T old_current_sctx = current_sctx;
|
||||
if (channel_id != VIML_INTERNAL_CALL) {
|
||||
current_sctx.sc_sid =
|
||||
channel_id == LUA_INTERNAL_CALL ? SID_LUA : SID_API_CLIENT;
|
||||
current_sctx.sc_lnum = 0;
|
||||
}
|
||||
return old_current_sctx;
|
||||
}
|
||||
|
@@ -1586,6 +1586,7 @@ ArrayOf(Dictionary) nvim_get_keymap(uint64_t channel_id, String mode)
|
||||
/// nmap <nowait> <Space><NL> <Nop>
|
||||
/// </pre>
|
||||
///
|
||||
/// @param channel_id
|
||||
/// @param mode Mode short-name (map command prefix: "n", "i", "v", "x", …)
|
||||
/// or "!" for |:map!|, or empty string for |:map|.
|
||||
/// @param lhs Left-hand-side |{lhs}| of the mapping.
|
||||
@@ -1597,10 +1598,11 @@ ArrayOf(Dictionary) nvim_get_keymap(uint64_t channel_id, String mode)
|
||||
/// a Lua function to call when the mapping is executed.
|
||||
/// Values are Booleans. Unknown key is an error.
|
||||
/// @param[out] err Error details, if any.
|
||||
void nvim_set_keymap(String mode, String lhs, String rhs, Dict(keymap) *opts, Error *err)
|
||||
void nvim_set_keymap(uint64_t channel_id, String mode, String lhs, String rhs, Dict(keymap) *opts,
|
||||
Error *err)
|
||||
FUNC_API_SINCE(6)
|
||||
{
|
||||
modify_keymap(-1, false, mode, lhs, rhs, opts, err);
|
||||
modify_keymap(channel_id, -1, false, mode, lhs, rhs, opts, err);
|
||||
}
|
||||
|
||||
/// Unmaps a global |mapping| for the given mode.
|
||||
@@ -1608,10 +1610,10 @@ void nvim_set_keymap(String mode, String lhs, String rhs, Dict(keymap) *opts, Er
|
||||
/// To unmap a buffer-local mapping, use |nvim_buf_del_keymap()|.
|
||||
///
|
||||
/// @see |nvim_set_keymap()|
|
||||
void nvim_del_keymap(String mode, String lhs, Error *err)
|
||||
void nvim_del_keymap(uint64_t channel_id, String mode, String lhs, Error *err)
|
||||
FUNC_API_SINCE(6)
|
||||
{
|
||||
nvim_buf_del_keymap(-1, mode, lhs, err);
|
||||
nvim_buf_del_keymap(channel_id, -1, mode, lhs, err);
|
||||
}
|
||||
|
||||
/// Gets a map of global (non-buffer-local) Ex commands.
|
||||
|
@@ -37,7 +37,7 @@
|
||||
/// @param[out] err Error details (Vim error), if any
|
||||
/// @return Output (non-error, non-shell |:!|) if `output` is true,
|
||||
/// else empty string.
|
||||
String nvim_exec(String src, Boolean output, Error *err)
|
||||
String nvim_exec(uint64_t channel_id, String src, Boolean output, Error *err)
|
||||
FUNC_API_SINCE(7)
|
||||
{
|
||||
const int save_msg_silent = msg_silent;
|
||||
@@ -52,11 +52,16 @@ String nvim_exec(String src, Boolean output, Error *err)
|
||||
if (output) {
|
||||
msg_silent++;
|
||||
}
|
||||
|
||||
const sctx_T save_current_sctx = api_set_sctx(channel_id);
|
||||
|
||||
do_source_str(src.data, "nvim_exec()");
|
||||
if (output) {
|
||||
capture_ga = save_capture_ga;
|
||||
msg_silent = save_msg_silent;
|
||||
}
|
||||
|
||||
current_sctx = save_current_sctx;
|
||||
try_end(err);
|
||||
|
||||
if (ERROR_SET(err)) {
|
||||
|
Reference in New Issue
Block a user