diff --git a/DOCS.md b/DOCS.md index 70d7a1117..bc10ca3a0 100644 --- a/DOCS.md +++ b/DOCS.md @@ -270,18 +270,18 @@ Possible values: *type*: `boolean`
*default value*: `false`
Possible values: -* `true` - Enables indent mode on startup. Lines that follow headlines are indented to that headline level. -* `false` - Disables indent mode on startup. All lines start from the first column. +* `true` - Uses *Virtual* indents to align content visually. The indents are only visual, they are not saved to the file. +* `false` - Do not add any *Virtual* indentation. + +This feature has no effect when enabled on Neovim verions < 0.10.0 #### **org_adapt_indentation** *type*: `boolean`
*default value*: `true`
Possible values: -* `true` - Converts indents to *Virtual* indents. The indents are only visual, they are not saved to the file. -* `false` - Use real indents, indentation as seen is what is saved to the file. - -This feature has no effect when enabled on Neovim verions < 0.10.0 +* `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_src_window_setup** *type*: `string|function`
diff --git a/lua/orgmode/config/init.lua b/lua/orgmode/config/init.lua index e2b8b7b67..fdae58bde 100644 --- a/lua/orgmode/config/init.lua +++ b/lua/orgmode/config/init.lua @@ -1,5 +1,4 @@ local instance = {} -local VirtualIndent = require('orgmode.ui.virtual_indent') local utils = require('orgmode.utils') local fs = require('orgmode.utils.fs') local defaults = require('orgmode.config.defaults') @@ -149,7 +148,7 @@ function Config:_deprecation_notify(opts) messages, '"org_indent_mode" is deprecated in favor of "org_startup_indented". Check the documentation about the new option.' ) - opts.org_startup_indented = (opts.org_indent_mode == 'noindent') + opts.org_startup_indented = (opts.org_indent_mode == 'indent') end if #messages > 0 then @@ -415,7 +414,7 @@ end ---@param amount number ---@return string function Config:get_indent(amount) - if vim.b.org_indent_mode then + if self.org_adapt_indentation then return string.rep(' ', amount) end return '' diff --git a/lua/orgmode/org/indent.lua b/lua/orgmode/org/indent.lua index 0f9e5ead8..3f183de88 100644 --- a/lua/orgmode/org/indent.lua +++ b/lua/orgmode/org/indent.lua @@ -4,7 +4,7 @@ local ts_utils = require('nvim-treesitter.ts_utils') local query = nil local function get_indent_pad(linenr) - if vim.b.org_indent_mode and not config.org_adapt_indentation then + if config.org_adapt_indentation then local headline = require('orgmode.treesitter.headline').from_cursor({ linenr, 0 }) if not headline then return 0 @@ -311,11 +311,7 @@ end local function setup() local v = vim.version() - if vim.version.lt({ v.major, v.minor, v.patch }, { 0, 10, 0 }) then - config.org_adapt_indentation = false - end - - if config.org_startup_indented and config.org_adapt_indentation then + if config.org_startup_indented and not vim.version.lt({ v.major, v.minor, v.patch }, { 0, 10, 0 }) then VirtualIndent:new():attach() end end diff --git a/lua/orgmode/parser/section.lua b/lua/orgmode/parser/section.lua index 8238d770d..e5e812c37 100644 --- a/lua/orgmode/parser/section.lua +++ b/lua/orgmode/parser/section.lua @@ -406,7 +406,7 @@ end function Section:demote(amount, demote_child_sections, dryRun) amount = amount or 1 demote_child_sections = demote_child_sections or false - local should_indent = vim.b.org_indent_mode + local should_indent = config.org_adapt_indentation local lines = {} local headline_line = string.rep('*', amount) .. self.line table.insert(lines, headline_line) @@ -444,7 +444,7 @@ end function Section:promote(amount, promote_child_sections, dryRun) amount = amount or 1 promote_child_sections = promote_child_sections or false - local should_dedent = vim.b.org_indent_mode + local should_dedent = config.org_adapt_indentation local lines = {} if self.level == 1 then utils.echo_warning('Cannot demote top level heading.') diff --git a/lua/orgmode/treesitter/headline.lua b/lua/orgmode/treesitter/headline.lua index b52e0419a..df68908d0 100644 --- a/lua/orgmode/treesitter/headline.lua +++ b/lua/orgmode/treesitter/headline.lua @@ -1,6 +1,5 @@ local utils = require('orgmode.utils') local ts_utils = require('nvim-treesitter.ts_utils') -local VirtualIndent = require('orgmode.ui.virtual_indent') local tree_utils = require('orgmode.utils.treesitter') local Date = require('orgmode.objects.date') local Range = require('orgmode.parser.range') @@ -69,12 +68,12 @@ function Headline:promote(amount, recursive) if line:sub(1, 1) == '*' then lines[i] = line:sub(1 + amount) elseif vim.trim(line:sub(1, amount)) == '' then - if vim.b.org_indent_mode and config.org_adapt_indentation then + if config.org_adapt_indentation then + lines[i] = line:sub(1 + amount) + else line, _ = line:gsub('^%s+', '') local indent_amount = indent.indentexpr(start_line + i) lines[i] = string.rep(' ', indent_amount) .. line - else - lines[i] = line:sub(1 + amount) end end end @@ -93,12 +92,12 @@ function Headline:demote(amount, recursive) if line:sub(1, 1) == '*' then lines[i] = string.rep('*', amount) .. line else - if vim.b.org_indent_mode and config.org_adapt_indentation then + if config.org_adapt_indentation then + lines[i] = config:apply_indent(line, amount) + else line, _ = line:gsub('^%s+', '') local indent_amount = indent.indentexpr(start_line + i) lines[i] = string.rep(' ', indent_amount) .. line - else - lines[i] = config:apply_indent(line, amount) end end end diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua index 07505078b..a041421c6 100644 --- a/tests/minimal_init.lua +++ b/tests/minimal_init.lua @@ -134,6 +134,4 @@ require('nvim-treesitter.configs').setup({ require('orgmode').setup({ org_agenda_files = { base_root_path .. '/plenary/fixtures/*' }, org_default_notes_file = base_root_path .. '/plenary/fixtures/refile.org', - -- Many of the tests were originally written with indent mode being enabled in mind :/ - org_startup_indented = true, }) diff --git a/tests/plenary/org/indent_spec.lua b/tests/plenary/org/indent_spec.lua index 15ce83f21..3d7e5efc7 100644 --- a/tests/plenary/org/indent_spec.lua +++ b/tests/plenary/org/indent_spec.lua @@ -1,5 +1,4 @@ local config = require('orgmode.config') -local VirtualIndent = require('orgmode.ui.virtual_indent') local helpers = require('tests.plenary.ui.helpers') -- Helper assert function. @@ -67,7 +66,7 @@ local function test_full_reindent() helpers.load_file_content(unformatted_file) vim.cmd([[silent norm 0gg=G]]) local expected - if config.org_startup_indented and not VirtualIndent.enabled then + if config.org_adapt_indentation then expected = { '* TODO First task', ' SCHEDULED: <1970-01-01 Thu>', @@ -269,7 +268,7 @@ describe('with "indent" and "VirtualIndent" is enabled', function() end) it('has the correct amount of virtual indentation', function() - if not VirtualIndent.enabled then + if not vim.b.org_indent_mode then return end diff --git a/tests/plenary/ui/mappings/headline_spec.lua b/tests/plenary/ui/mappings/headline_spec.lua index 12c10648a..522960dd5 100644 --- a/tests/plenary/ui/mappings/headline_spec.lua +++ b/tests/plenary/ui/mappings/headline_spec.lua @@ -1,5 +1,5 @@ local helpers = require('tests.plenary.ui.helpers') -local VirtualIndent = require('orgmode.ui.virtual_indent') +local config = require('orgmode.config') describe('Heading mappings', function() after_each(function() @@ -92,23 +92,23 @@ describe('Heading mappings', function() }, vim.api.nvim_buf_get_lines(0, 2, 8, false)) vim.fn.cursor(3, 1) local check - if VirtualIndent.enabled then + if config.org_adapt_indentation then check = { '** TODO Test orgmode', - 'DEADLINE: <2021-07-21 Wed 22:02>', + ' DEADLINE: <2021-07-21 Wed 22:02>', '*** TODO [#A] Test orgmode level 2 :PRIVATE:', - 'Some content for level 2', + ' Some content for level 2', '**** NEXT [#1] Level 3', - 'Content Level 3', + ' Content Level 3', } else check = { '** TODO Test orgmode', - ' DEADLINE: <2021-07-21 Wed 22:02>', + 'DEADLINE: <2021-07-21 Wed 22:02>', '*** TODO [#A] Test orgmode level 2 :PRIVATE:', - ' Some content for level 2', + 'Some content for level 2', '**** NEXT [#1] Level 3', - ' Content Level 3', + 'Content Level 3', } end vim.cmd([[norm >s]]) @@ -116,23 +116,23 @@ describe('Heading mappings', function() -- Support count local check - if VirtualIndent.enabled then + if config.org_adapt_indentation then check = { '****** TODO Test orgmode', - 'DEADLINE: <2021-07-21 Wed 22:02>', + ' DEADLINE: <2021-07-21 Wed 22:02>', '******* TODO [#A] Test orgmode level 2 :PRIVATE:', - 'Some content for level 2', + ' Some content for level 2', '******** NEXT [#1] Level 3', - 'Content Level 3', + ' Content Level 3', } else check = { '****** TODO Test orgmode', - ' DEADLINE: <2021-07-21 Wed 22:02>', + 'DEADLINE: <2021-07-21 Wed 22:02>', '******* TODO [#A] Test orgmode level 2 :PRIVATE:', - ' Some content for level 2', + 'Some content for level 2', '******** NEXT [#1] Level 3', - ' Content Level 3', + 'Content Level 3', } end vim.cmd([[norm 4>s]]) @@ -205,23 +205,23 @@ describe('Heading mappings', function() -- Support count local check - if VirtualIndent.enabled then + if config.org_adapt_indentation then check = { '*** TODO Test orgmode', - 'DEADLINE: <2021-07-21 Wed 22:02>', + ' DEADLINE: <2021-07-21 Wed 22:02>', '**** TODO [#A] Test orgmode level 2 :PRIVATE:', - 'Some content for level 2', + ' Some content for level 2', '***** NEXT [#1] Level 3', - 'Content Level 3', + ' Content Level 3', } else check = { '*** TODO Test orgmode', - ' DEADLINE: <2021-07-21 Wed 22:02>', + 'DEADLINE: <2021-07-21 Wed 22:02>', '**** TODO [#A] Test orgmode level 2 :PRIVATE:', - ' Some content for level 2', + 'Some content for level 2', '***** NEXT [#1] Level 3', - ' Content Level 3', + 'Content Level 3', } end vim.cmd([[norm 2', + ' DEADLINE: <2021-07-21 Wed 22:02>', '** TODO [#A] Test orgmode level 2 :PRIVATE:', - 'Some content for level 2', + ' Some content for level 2', '*** NEXT [#1] Level 3', - 'Content Level 3', + ' Content Level 3', } else check = { '* TODO Test orgmode', - ' DEADLINE: <2021-07-21 Wed 22:02>', + 'DEADLINE: <2021-07-21 Wed 22:02>', '** TODO [#A] Test orgmode level 2 :PRIVATE:', - ' Some content for level 2', + 'Some content for level 2', '*** NEXT [#1] Level 3', - ' Content Level 3', + 'Content Level 3', } end vim.cmd([[norm 5