mirror of
https://github.com/neovim/neovim.git
synced 2025-10-09 03:16:31 +00:00
feat(lua): add api and lua autocmds
This commit is contained in:
@@ -6,22 +6,30 @@
|
||||
#include <msgpack.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nvim/api/buffer.h"
|
||||
#include "nvim/api/deprecated.h"
|
||||
#include "nvim/api/extmark.h"
|
||||
#include "nvim/api/private/defs.h"
|
||||
#include "nvim/api/private/dispatch.h"
|
||||
#include "nvim/api/private/helpers.h"
|
||||
#include "nvim/log.h"
|
||||
#include "nvim/map.h"
|
||||
#include "nvim/msgpack_rpc/helpers.h"
|
||||
#include "nvim/vim.h"
|
||||
|
||||
// ===========================================================================
|
||||
// NEW API FILES MUST GO HERE.
|
||||
//
|
||||
// When creating a new API file, you must include it here,
|
||||
// so that the dispatcher can find the C functions that you are creating!
|
||||
// ===========================================================================
|
||||
#include "nvim/api/autocmd.h"
|
||||
#include "nvim/api/buffer.h"
|
||||
#include "nvim/api/extmark.h"
|
||||
#include "nvim/api/tabpage.h"
|
||||
#include "nvim/api/ui.h"
|
||||
#include "nvim/api/vim.h"
|
||||
#include "nvim/api/vimscript.h"
|
||||
#include "nvim/api/win_config.h"
|
||||
#include "nvim/api/window.h"
|
||||
#include "nvim/log.h"
|
||||
#include "nvim/map.h"
|
||||
#include "nvim/msgpack_rpc/helpers.h"
|
||||
#include "nvim/vim.h"
|
||||
|
||||
static Map(String, MsgpackRpcRequestHandler) methods = MAP_INIT;
|
||||
|
||||
|
@@ -396,19 +396,14 @@ void set_option_to(uint64_t channel_id, void *to, int type, String name, Object
|
||||
stringval = value.data.string.data;
|
||||
}
|
||||
|
||||
const sctx_T save_current_sctx = current_sctx;
|
||||
current_sctx.sc_sid =
|
||||
channel_id == LUA_INTERNAL_CALL ? SID_LUA : SID_API_CLIENT;
|
||||
current_sctx.sc_lnum = 0;
|
||||
current_channel_id = channel_id;
|
||||
WITH_SCRIPT_CONTEXT(channel_id, {
|
||||
const int opt_flags = (type == SREQ_WIN && !(flags & SOPT_GLOBAL))
|
||||
? 0 : (type == SREQ_GLOBAL)
|
||||
? OPT_GLOBAL : OPT_LOCAL;
|
||||
|
||||
const int opt_flags = (type == SREQ_WIN && !(flags & SOPT_GLOBAL))
|
||||
? 0 : (type == SREQ_GLOBAL)
|
||||
? OPT_GLOBAL : OPT_LOCAL;
|
||||
set_option_value_for(name.data, numval, stringval,
|
||||
opt_flags, type, to, err);
|
||||
|
||||
current_sctx = save_current_sctx;
|
||||
set_option_value_for(name.data, numval, stringval,
|
||||
opt_flags, type, to, err);
|
||||
});
|
||||
}
|
||||
|
||||
buf_T *find_buffer_by_handle(Buffer buffer, Error *err)
|
||||
@@ -1614,3 +1609,16 @@ err:
|
||||
NLUA_CLEAR_REF(luaref);
|
||||
NLUA_CLEAR_REF(compl_luaref);
|
||||
}
|
||||
|
||||
int find_sid(uint64_t channel_id)
|
||||
{
|
||||
switch (channel_id) {
|
||||
case VIML_INTERNAL_CALL:
|
||||
// TODO(autocmd): Figure out what this should be
|
||||
// return SID_API_CLIENT;
|
||||
case LUA_INTERNAL_CALL:
|
||||
return SID_LUA;
|
||||
default:
|
||||
return SID_API_CLIENT;
|
||||
}
|
||||
}
|
||||
|
@@ -138,10 +138,27 @@ typedef struct {
|
||||
msg_list = saved_msg_list; /* Restore the exception context. */ \
|
||||
} while (0)
|
||||
|
||||
// Useful macro for executing some `code` for each item in an array.
|
||||
#define FOREACH_ITEM(a, __foreach_item, code) \
|
||||
for (size_t __foreach_i = 0; __foreach_i < (a).size; __foreach_i++) { \
|
||||
Object __foreach_item = (a).items[__foreach_i]; \
|
||||
code; \
|
||||
}
|
||||
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "api/private/helpers.h.generated.h"
|
||||
# include "keysets.h.generated.h"
|
||||
#endif
|
||||
|
||||
#define WITH_SCRIPT_CONTEXT(channel_id, code) \
|
||||
const sctx_T save_current_sctx = current_sctx; \
|
||||
current_sctx.sc_sid = \
|
||||
(channel_id) == LUA_INTERNAL_CALL ? SID_LUA : SID_API_CLIENT; \
|
||||
current_sctx.sc_lnum = 0; \
|
||||
current_channel_id = channel_id; \
|
||||
code; \
|
||||
current_sctx = save_current_sctx;
|
||||
|
||||
|
||||
#endif // NVIM_API_PRIVATE_HELPERS_H
|
||||
|
Reference in New Issue
Block a user