Skip to content

Commit

Permalink
Provide setting for delete-check autocommands.
Browse files Browse the repository at this point in the history
  • Loading branch information
L3MON4D3 committed Aug 25, 2021
1 parent d87d094 commit 0db416c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Neovim >= 0.5 (extmarks)
- `history`: If true, Snippets that were exited can still be jumped back into. As Snippets are not removed when their text is deleted, they have to be removed manually via `LuasnipUnlinkCurrent`.
- `updateevents`: Choose which events trigger an update of the active nodes' dependents. Default is just `'InsertLeave'`, `'TextChanged,TextChangedI'` would update on every change.
- `region_check_events`: Events on which to leave the current snippet if the cursor is outside its' 'region'. Disabled by default, `'CursorMoved'`, `'CursorHold'` or `'InsertEnter'` seem reasonable.
- `delete_check_events`: When to check if the current snippet was deleted, and if so, remove it from the history. Off by default, `'TextChanged'` (perhaps `'InsertLeave'`, to react to changes done in Insert mode) should work just fine (alternatively, this can also be mapped using `<Plug>luasnip-delete-check`).
- `store_selection_keys`: Mapping for populating `TM_SELECTED_TEXT` and related variables (not set by default).
- `enable_autosnippets`: Autosnippets are disabled by default to minimize performance penalty if unused. Set to `true` to enable.
- `ext_opts`: Additional options passed to extmarks. Can be used to add passive/active highlight on a per-node-basis (more info in DOC.md)
Expand Down
4 changes: 3 additions & 1 deletion lua/luasnip/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local defaults = {
updateevents = "InsertLeave",
-- see :h User, event should never be triggered(except if it is `doautocmd`'d)
region_check_events = "User None",
delete_check_events = "User None",
store_selection_keys = nil, -- Supossed to be the same as the expand shortcut
ext_opts = {
[types.textNode] = {
Expand Down Expand Up @@ -78,14 +79,15 @@ c = {
au!
autocmd %s * lua require("luasnip").active_update_dependents()
autocmd %s * lua require("luasnip").exit_out_of_region(Luasnip_current_nodes[vim.api.nvim_get_current_buf()])
autocmd %s * lua require("luasnip").unlink_current_if_deleted()
"Remove buffers' nodes on deletion+wipeout.
autocmd BufDelete,BufWipeout * lua if Luasnip_current_nodes then Luasnip_current_nodes[tonumber(vim.fn.expand("<abuf>"))] = nil end
]] .. (c.config.enable_autosnippets and [[
autocmd InsertCharPre * lua Luasnip_just_inserted = true
autocmd TextChangedI * lua if Luasnip_just_inserted then require("luasnip").expand_auto() Luasnip_just_inserted=false end
]] or "") .. [[
augroup END
]], c.config.updateevents, c.config.region_check_events))
]], c.config.updateevents, c.config.region_check_events, c.config.delete_check_events))
if c.config.store_selection_keys then
vim.cmd(
string.format(
Expand Down

0 comments on commit 0db416c

Please sign in to comment.