Open max397574 opened 1 year ago
This is similar to #797, a description for achieving this via api is in there, but I haven't considered just using undo for this. Is it possible to register a new undo-point (?) via lua?
yes looks like this could work for me regarding your question
I can confirm it works with this hack
local auto_expand = require("luasnip").expand_auto
require("luasnip").expand_auto = function(...)
vim.o.undolevels = vim.o.undolevels
auto_expand(...)
end
Ahh okay, thank you!
That seems like something we could just always do before expanding a snippet.. Although undo
won't affect internal variables (the current node), which would have to be reset in some other way, so maybe a proper API is the better approach.
I think in the long run an api would be the better solution for now I just use this (for anyone searching for a solution):
local auto_expand = require("luasnip").expand_auto
require("luasnip").expand_auto = function(...)
vim.o.undolevels = vim.o.undolevels
auto_expand(...)
end
this isn't a nice solution though because it sets new undo everytime the function is called
Slightly better: set the new undo-point in (/around?) snip_expand
, that's the function which actually expands the snippets
I tried both snip_expand
and expand_auto
,
adding undo point in expand_auto
will lead to neovim recording every character you type in an expansion trigger.
local auto_expand = require("luasnip").expand_auto
require("luasnip").expand_auto = function(...)
vim.o.undolevels = vim.o.undolevels
auto_expand(...)
end
however, adding undo in snip_expand
seems just doesn't work. neovim still undoes everything in a single period of insert.
local auto_expand = require("luasnip").snip_expand
require("luasnip").snip_expand = function(...)
vim.o.undolevels = vim.o.undolevels
auto_expand(...)
end
Did I set it wrong? or is there a better alternative?
also, I'm as well looking forward for an api to came out, thank you L3MON4D3 :D
local snip_expand = require("luasnip").snip_expand
require("luasnip").snip_expand = function(...)
vim.o.ul = vim.o.ul
snip_expand(...)
end
works for me
strange, just doesn't work for me. Are you using an auto-trigger or expand by enter?
autoexpand snippets
I see no reason why you'd want to undo manually expanding snippets
if you do you could just put the vim.o.ul=vim.o.ul
inside your mapping to expand
I'm also using autoexpand snippets. Then there might be something wrong in my configs somewhere.
you should be able to just do <c-o>u
in insert mode
oh yes, and that worked, but it's a bit not that automatic.
well you could just map that to something
I think in the long run an api would be the better solution for now I just use this (for anyone searching for a solution):
local auto_expand = require("luasnip").expand_auto require("luasnip").expand_auto = function(...) vim.o.undolevels = vim.o.undolevels auto_expand(...) end
this isn't a nice solution though because it sets new undo everytime the function is called
How do you actually implement this solution? like do i just plop this into an init.lua?
How do you actually implement this solution? like do i just plop this into an init.lua?
yes
Hi, I recently stumbled upon this issue. For me the solution of @max397574 didn't work. On investigating further, I realized that the issue can be resolved by applying the following simple patch:
@@ -363,7 +363,7 @@ local function expand_auto()
},
to = cursor,
}
- snip = snip_expand(snip, {
+ snip = ls.snip_expand(snip, {
expand_params = expand_params,
-- clear trigger-text.
clear_region = clear_region,
to lua/luasnip/init.lua
. If you are interested in changing this, I could submit this as a pull request.
Cheers,
project-repo
it should somehow be possible to undo autoexpand if a snippet autoexpanded when it shouldn't have I see two options for this either start a new undo sequence so you can just
<c-o>u
from insert mode or provide an api to do it which can be mapped to