-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request: non-recursive mapping #437
Comments
Why? What do you want to achieve, it can almost certainly be done in some other way. |
i'm implementing html tag auto completion: edit: bonus: the key binding action pseudo-keys could be dropped |
I agree that recursive bindings might require a bit more thought, but I don't really see a better alternative.
I don't want them to be dropped though. The reason why vim has non-recursive bindings is because certain stuff is hard coded/built-in into the editor core. For example you can't really unmap those ( Now suppose we want to write a nano frontend on top of the text editing code, As for your concrete use case/problem, how would you get the tag to insert? One mapping per tag? Probably a better approach would be to use a Lua function, something like the following: local autoclose_htmltags = function()
local win = vis.win
local file = win.file
for cursor in win:cursors_iterator() do
local pos = cursor.pos
file:insert(pos, ">")
local tag_range = file:text_object_angle_bracket(pos)
if tag_range then
local tag_name = file:content(tag_range)
if not tag_name:find("\n") and tag_name:sub(-1) ~= "/" then
local space = tag_name:find(" ")
if space then
tag_name = tag_name:sub(1, space-1)
end
file:insert(pos+1, string.format("</%s>", tag_name))
end
end
cursor.pos = pos + 1
end
end
vis.events.subscribe(vis.events.WIN_OPEN, function(win)
if win.syntax == 'html' then
win:map(vis.modes.INSERT, ">", autoclose_htmltags, "Autoclose HTML tags")
end
end) This depends on the following patch to expose the diff --git a/vis-lua.c b/vis-lua.c
index 301d719..ac31e16 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -1964,6 +1964,7 @@ void vis_lua_init(Vis *vis) {
const char *name;
} textobjects[] = {
{ VIS_TEXTOBJECT_INNER_WORD, "text_object_word" },
+ { VIS_TEXTOBJECT_INNER_ANGLE_BRACKET, "text_object_angle_bracket" },
};
for (size_t i = 0; i < LENGTH(textobjects); i++) { I'm not yet sure how to best expose the text object functionality to Lua. Duplicating the C API would be one approach, but maybe we can do better. To be discussed in #292. |
the alternative is non-recursive bindings. we can have both, just like vim.
if win.syntax == 'html' then
vis:command('map! insert >> <Escape>ybea></<C-r>0><Escape>h%i')
vis:command('map! insert ><Enter> <Escape>ybea></<C-r>0><Escape>h%i<Enter><Escape>O')
end |
You failed to address the better part. As explained in my last post vis does not have special internal commands. Hence, consider the following imaginary mapping
The current model is simple to reason about. I don't want the additional complexity. Also personally I do not like these hackish mappings (e.g. you just clobbered the default register, you exited insert mode which messes with undo history etc). In my opinion they should only be used to set up preferred key bindings. |
ok, i didn't grasp what no builtin mappings meant. i can live with recursion.
|
stop infinite recursion
The text was updated successfully, but these errors were encountered: