Skip to content

Commit

Permalink
feat: add org_indent_mode_turns_off_org_adapt_indentation
Browse files Browse the repository at this point in the history
See nvim-orgmode#627 (review)

> 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.
  • Loading branch information
PriceHiller committed Jan 25, 2024
1 parent 401922c commit 967b9b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`<br />
*default value*: `true`<br />
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`<br />
*default value*: "top 16new"<br />
Expand Down
1 change: 1 addition & 0 deletions ftplugin/org.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions lua/orgmode/config/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 967b9b2

Please sign in to comment.