Created
May 5, 2022 17:04
-
-
Save adsr/100c6ce4a9133033e227e6a7b84c5f28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/uscript.c b/uscript.c | |
index 17cf1d3..5af186a 100644 | |
--- a/uscript.c | |
+++ b/uscript.c | |
@@ -170,29 +170,51 @@ static void _uscript_push_event_map(uscript_t *uscript, char *event_name, void * | |
luaL_pushkey(L, pointer, "bview", event_data); | |
return; | |
} else if (strncmp(event_name, "cmd:", 4) == 0) { | |
_uscript_push_cmd_map(L, (cmd_context_t*)event_data); | |
return; | |
} | |
lua_pushnil(uscript->L); // TODO | |
} | |
static void _uscript_push_cmd_map(lua_State *L, cmd_context_t *ctx) { | |
+ int i; | |
+ | |
lua_createtable(L, 0, 1); | |
luaL_pushkey(L, pointer, "editor", (void*)ctx->editor); | |
luaL_pushkey(L, pointer, "loop_ctx", (void*)ctx->loop_ctx); | |
luaL_pushkey(L, pointer, "cmd", (void*)ctx->cmd); | |
luaL_pushkey(L, pointer, "buffer", (void*)ctx->buffer); | |
luaL_pushkey(L, pointer, "bview", (void*)ctx->bview); | |
luaL_pushkey(L, pointer, "cursor", (void*)ctx->cursor); | |
luaL_pushkey(L, pointer, "mark", (void*)ctx->cursor->mark); | |
luaL_pushkey(L, string, "static_param", (const char*)ctx->static_param); | |
+ | |
+ // wildcard params | |
+ lua_pushstring(L, "wildcard_params"); | |
+ lua_createtable(L, ctx->wildcard_params_len, 0); | |
+ for (i = 0; i < ctx->wildcard_params_len; i++) { | |
+ lua_pushnumber(L, i); | |
+ lua_pushnumber(L, ctx->wildcard_params[i]); | |
+ lua_settable(L, -3); | |
+ } | |
+ lua_settable(L, -3); | |
+ | |
+ // numeric params | |
+ lua_pushstring(L, "numeric_params"); | |
+ lua_createtable(L, ctx->numeric_params_len, 0); | |
+ for (i = 0; i < ctx->numeric_params_len; i++) { | |
+ lua_pushnumber(L, i); | |
+ lua_pushnumber(L, ctx->numeric_params[i]); | |
+ lua_settable(L, -3); | |
+ } | |
+ lua_settable(L, -3); | |
} | |
static void _uscript_push_baction_map(lua_State *L, baction_t *baction) { | |
lua_createtable(L, 0, 1); | |
luaL_pushkey(L, integer, "type", baction->type); | |
luaL_pushkey(L, pointer, "buffer", (void*)baction->buffer); | |
luaL_pushkey(L, integer, "start_line_index", baction->start_line_index); | |
luaL_pushkey(L, integer, "start_col", baction->start_col); | |
luaL_pushkey(L, integer, "maybe_end_line_index", baction->maybe_end_line_index); | |
luaL_pushkey(L, integer, "maybe_end_col", baction->maybe_end_col); | |
diff --git a/uscript.lua b/uscript.lua | |
index c1578c3..c260253 100644 | |
--- a/uscript.lua | |
+++ b/uscript.lua | |
@@ -1,25 +1,10 @@ | |
--- mle -N -x uscript.lua -K lua_kmap,,1 -k cmd_lua_test,f11, -n lua_kmap | |
+-- mle -N -x uscript.lua -K lua_kmap,,1 -k 'cmd_lua_wild,f9 ** **,' -k 'cmd_lua_wild,f10 ## x,' -n lua_kmap | |
-mle.editor_register_observer("buffer:save", function (bview) | |
- r = mle.util_shell_exec("ls", -1) | |
- print("ls " .. r["output"]) | |
-end) | |
- | |
-mle.editor_register_cmd("cmd_lua_test", function (ctx) | |
- name = mle.editor_prompt("Enter your name") | |
- if name then | |
- print("hello <" .. name .. "> from lua") | |
- else | |
- print("you hit cancel") | |
+mle.editor_register_cmd("cmd_lua_wild", function (ctx) | |
+ for key, value in pairs(ctx["wildcard_params"]) do | |
+ print("wildcard_param ", key, "=", utf8.char(value), "\n") | |
+ end | |
+ for key, value in pairs(ctx["numeric_params"]) do | |
+ print("numeric_param ", key, "=", value, "\n") | |
end | |
-end) | |
- | |
-mle.editor_register_observer("cmd:cmd_copy:before", function (ctx) | |
- local rv = mle.cursor_get_anchor(ctx["cursor"]) | |
- local anchor = rv["ret_anchor"] | |
- | |
- rv = mle.mark_get_between_mark(ctx["mark"], anchor) | |
- rv = mle.util_escape_shell_arg(rv["ret_str"]) | |
- | |
- mle.util_shell_exec("echo -n " .. rv["output"] .. " | xclip -sel c >/dev/null", 1) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works perfectly. Thank you