From 967b9b2304f9643b7542508cfbb6a8f9fc4635e8 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Thu, 25 Jan 2024 13:19:58 -0600 Subject: [PATCH] feat: add `org_indent_mode_turns_off_org_adapt_indentation` See https://github.com/nvim-orgmode/orgmode/pull/627#pullrequestreview-1843265624 > I gave it a test, it works great, and code looks good overall. I only noticed one inconsistency. > > If `org_startup_indented = true` and `org_adapt_indentation = true`, when I open up the file and reindent the file, it doesn't change any indentation. > > For example, I have this content that is hard indented: > > ``` > * TODO Test > Test > List > - First > - second > - level2 > - level3 > - level2 item > ``` > > Now when I apply above configuration (setting both to `true`) and open it, I get this: > > virtual indent + hard indent: > > ``` > * TODO Test > Test > List > - First > - second > - level2 > - level3 > - level2 item > ``` > > This is working as expected. But now, if I do gg=G, no indentation is actually changed. I would expect to realign everything so it adapts to the virtual indentation. It does that when `org_adapt_indentation = false`, so it generally works. We just need to tweak the checks. > > AFAIK Emacs doesn't have this idea of (hard) reindentation, so this is something we can figure out ourselves. > > If we follow the default Emacs settings for org indent mode I mentioned previously [link](https://orgmode.org/manual/Org-Indent-Mode.html#:~:text=By%20default%2C%20Org%20Indent%20mode%20turns%20off%20org%2Dadapt%2Dindentation), which states that when org-indent-mode is enabled on buffer, it disables the `org-adapt-indentation`, we can expect to apply the reindentation logic I mentioned above. > > So `org_startup_indented` always has higher priority over `org_adapt_indentation`, until we maybe introduce `org_indent_mode_turns_off_org_adapt_indentation` mentioned [here](https://orgmode.org/manual/Org-Indent-Mode.html#:~:text=If%20you%20want%20to%20customize%20this%20default%20behavior%2C%20see%20org%2Dindent%2Dmode%2Dturns%2Don%2Dhiding%2Dstars%20and%20org%2Dindent%2Dmode%2Dturns%2Doff%2Dorg%2Dadapt%2Dindentation.), but we'll leave that as an improvement for later. --- DOCS.md | 8 ++++++++ ftplugin/org.lua | 1 + lua/orgmode/config/defaults.lua | 1 + 3 files changed, 10 insertions(+) diff --git a/DOCS.md b/DOCS.md index a270bdd01..3d850501a 100644 --- a/DOCS.md +++ b/DOCS.md @@ -283,6 +283,14 @@ Possible values: * `true` - Use *hard* indents for content under headlines. Files will save with indents relative to headlines. * `false` - Do not add any *hard* indents. Files will save without indentation relative to headlines. +#### **org_indent_mode_turns_off_org_adapt_indentation** + +*type*: `boolean`
+*default value*: `true`
+Possible values: +* `true` - Disable [`org_adapt_indentation`](#org_adapt_indentation) by default when [`org_startup_indented`](#org_startup_indented) is enabled. +* `false` - Do not disable [`org_adapt_indentation`](#org_adapt_indentation) by default when [`org_startup_indented`](#org_startup_indented) is enabled. + #### **org_src_window_setup** *type*: `string|function`
*default value*: "top 16new"
diff --git a/ftplugin/org.lua b/ftplugin/org.lua index 557699e84..6715e284b 100644 --- a/ftplugin/org.lua +++ b/ftplugin/org.lua @@ -11,6 +11,7 @@ config:setup_mappings('text_objects') config:setup_foldlevel() if config.org_startup_indented then + config.org_adapt_indentation = not config.org_indent_mode_turns_off_org_adapt_indentation vim.b.org_indent_mode = true end require("orgmode.org.indent").setup() diff --git a/lua/orgmode/config/defaults.lua b/lua/orgmode/config/defaults.lua index b6b016c6b..25bdb91c0 100644 --- a/lua/orgmode/config/defaults.lua +++ b/lua/orgmode/config/defaults.lua @@ -36,6 +36,7 @@ local DefaultConfig = { org_custom_exports = {}, org_adapt_indentation = true, org_startup_indented = false, + org_indent_mode_turns_off_org_adapt_indentation = true, org_time_stamp_rounding_minutes = 5, org_blank_before_new_entry = { heading = true,