From be783f930cff33a2870d9667ec3cac682a1ff145 Mon Sep 17 00:00:00 2001 From: champignoom Date: Wed, 3 Jan 2024 00:57:49 +0800 Subject: [PATCH 1/3] fix(autocommands): pass augroup correctly --- lua/neorg/modules/core/autocommands/module.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lua/neorg/modules/core/autocommands/module.lua b/lua/neorg/modules/core/autocommands/module.lua index 5cae451de..babdc896d 100644 --- a/lua/neorg/modules/core/autocommands/module.lua +++ b/lua/neorg/modules/core/autocommands/module.lua @@ -68,11 +68,12 @@ module.public = { autocmd = autocmd:lower() local subscribed_autocommand = module.events.subscribed["core.autocommands"][autocmd] - if subscribed_autocommand ~= nil then - vim.cmd("augroup Neorg") + local group = vim.api.nvim_create_augroup("Neorg", { clear = false }) + if subscribed_autocommand ~= nil then if dont_isolate and vim.fn.exists("#Neorg#" .. autocmd .. "#*") == 0 then vim.api.nvim_create_autocmd(autocmd, { + group = group, callback = function(ev) _neorg_module_autocommand_triggered("core.autocommands.events." .. autocmd, false, ev) end, @@ -80,12 +81,12 @@ module.public = { elseif vim.fn.exists("#Neorg#" .. autocmd .. "#*.norg") == 0 then vim.api.nvim_create_autocmd(autocmd, { pattern = "*.norg", + group = group, callback = function(ev) _neorg_module_autocommand_triggered("core.autocommands.events." .. autocmd, true, ev) end, }) end - vim.cmd("augroup END") module.events.subscribed["core.autocommands"][autocmd] = true end end, From 712eac3c4241390689732d92d53ae998b62ac454 Mon Sep 17 00:00:00 2001 From: champignoom Date: Wed, 3 Jan 2024 01:52:03 +0800 Subject: [PATCH 2/3] fix(journal): don't create file twice --- lua/neorg/modules/core/journal/module.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lua/neorg/modules/core/journal/module.lua b/lua/neorg/modules/core/journal/module.lua index 17a78bbfd..0af56890b 100644 --- a/lua/neorg/modules/core/journal/module.lua +++ b/lua/neorg/modules/core/journal/module.lua @@ -135,8 +135,6 @@ module.private = { module.required["core.dirman"].create_file(folder_name .. config.pathsep .. path, workspace) - module.required["core.dirman"].create_file(folder_name .. config.pathsep .. path, workspace) - if not journal_file_exists and module.config.public.use_template From b8d5c93017ad094a3089c5f962a9b9519bf1964c Mon Sep 17 00:00:00 2001 From: champignoom Date: Wed, 3 Jan 2024 00:58:28 +0800 Subject: [PATCH 3/3] feat(indent): add new undo block before indenting upon pressing esc --- .../modules/core/esupports/indent/module.lua | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lua/neorg/modules/core/esupports/indent/module.lua b/lua/neorg/modules/core/esupports/indent/module.lua index 795e9b599..4e88b4b07 100644 --- a/lua/neorg/modules/core/esupports/indent/module.lua +++ b/lua/neorg/modules/core/esupports/indent/module.lua @@ -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", @@ -315,14 +320,30 @@ module.on_event = function(event) local indentkeys = "o,O,*,*" .. lib.when(module.config.public.format_on_enter, ",*", "") - .. lib.when(module.config.public.format_on_escape, ",*", "") 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() + if event.line_content == "" then + return + end + + local lineno_1b = event.cursor_position[1] + local old_indent = vim.fn.indent(lineno_1b) + local new_indent = module.public.indentexpr(0, lineno_1b - 1) + if old_indent ~= new_indent then + vim.bo.undolevels = vim.bo.undolevels + vim.api.nvim_buf_set_text(0, lineno_1b-1, 0, lineno_1b-1, old_indent, { (" "):rep(new_indent) }) + end + end) + end end end module.events.subscribed = { ["core.autocommands"] = { bufenter = true, + insertleave = true, }, }