Skip to content

Commit

Permalink
feat(indent): add new undo block before indenting upon pressing esc
Browse files Browse the repository at this point in the history
  • Loading branch information
champignoom committed Jan 3, 2024
1 parent 712eac3 commit 9d1c70e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lua/neorg/modules/core/esupports/indent/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,15 @@ module.config.public = {

module.load = function()
module.required["core.autocommands"].enable_autocommand("BufEnter")
module.required["core.autocommands"].enable_autocommand("InsertLeave")
end

module.on_event = function(event)
if event.type == "core.autocommands.events.bufenter" and event.content.norg then
if not event.content.norg then
return
end

if event.type == "core.autocommands.events.bufenter" then
vim.api.nvim_buf_set_option(
event.buffer,
"indentexpr",
Expand All @@ -315,14 +320,21 @@ module.on_event = function(event)

local indentkeys = "o,O,*<M-o>,*<M-O>"
.. lib.when(module.config.public.format_on_enter, ",*<CR>", "")
.. lib.when(module.config.public.format_on_escape, ",*<Esc>", "")
vim.api.nvim_buf_set_option(event.buffer, "indentkeys", indentkeys)
elseif event.type == "core.autocommands.events.insertleave" then
if module.config.public.format_on_escape then
vim.api.nvim_buf_call(event.buffer, function()
vim.bo.undolevels = vim.bo.undolevels
vim.cmd("normal! ==")
end)
end
end
end

module.events.subscribed = {
["core.autocommands"] = {
bufenter = true,
insertleave = true,
},
}

Expand Down

0 comments on commit 9d1c70e

Please sign in to comment.