From 66d5a2251b0871aa037135644b6fca2a856de5b4 Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Wed, 7 Jun 2023 16:26:34 +0200 Subject: [PATCH] feat(indent): add `dedent_excess` configuration option (#624) --- .../modules/core/esupports/indent/module.lua | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lua/neorg/modules/core/esupports/indent/module.lua b/lua/neorg/modules/core/esupports/indent/module.lua index 5d2a6d69b..7f6063e54 100644 --- a/lua/neorg/modules/core/esupports/indent/module.lua +++ b/lua/neorg/modules/core/esupports/indent/module.lua @@ -95,7 +95,13 @@ module.public = { return -1 end - return indent + indent_data.indent + (module.config.public.tweaks[node:type()] or 0) + local new_indent = indent + indent_data.indent + (module.config.public.tweaks[node:type()] or 0) + + if (not module.config.public.dedent_excess) and new_indent <= initial_indent then + return initial_indent + end + + return new_indent end local calculated_indent = indent_data.indent(buf, node, line, indent, initial_indent) or 0 @@ -104,7 +110,13 @@ module.public = { return -1 end - return indent + calculated_indent + (module.config.public.tweaks[node:type()] or 0) + local new_indent = indent + calculated_indent + (module.config.public.tweaks[node:type()] or 0) + + if (not module.config.public.dedent_excess) and new_indent <= initial_indent then + return initial_indent + end + + return new_indent end, } @@ -276,6 +288,14 @@ module.config.public = { -- When true, will reformat the current line every time you press `` (i.e. every -- time you leave insert mode). format_on_escape = true, + + -- When false will not dedent nodes, only indent them. This means that if a node + -- is indented too much to the right, it will not be touched. It will only be indented + -- if the node is to the left of the expected indentation level. + -- + -- Useful when writing documentation in the style of vimdoc, where content is indented + -- heavily to the right in comparison to the default neorg style. + dedent_excess = true, } module.load = function()