diff --git a/DOCS.md b/DOCS.md index c0a826057..56d61ff06 100644 --- a/DOCS.md +++ b/DOCS.md @@ -153,6 +153,15 @@ Applies to: - agenda window - capture window +#### **org_startup_folded** +*type*: `string`
+*default value*: `overview`
+How many headings and other foldable items should be shown when an org file is opened.
+Available options: +* `overview` - Only show top level elements (default) +* `content` - Only show the first two levels +* `showeverything` - A double line box +* `inherit` - Use the fold level set in Neovim's global `foldlevel` option #### **org_todo_keyword_faces** *type*: `table`
diff --git a/ftplugin/org.vim b/ftplugin/org.vim index 7874472c1..91d688cdf 100644 --- a/ftplugin/org.vim +++ b/ftplugin/org.vim @@ -5,6 +5,7 @@ let b:did_ftplugin = 1 lua require('orgmode.config'):setup_mappings('org') lua require('orgmode.config'):setup_mappings('text_objects') +lua require('orgmode.config'):setup_foldlevel() function! OrgmodeFoldText() return luaeval('require("orgmode.org.indent").foldtext()') @@ -24,7 +25,6 @@ setlocal foldmethod=expr setlocal foldexpr=nvim_treesitter#foldexpr() setlocal foldtext=OrgmodeFoldText() setlocal formatexpr=OrgmodeFormatExpr() -setlocal foldlevel=0 setlocal omnifunc=OrgmodeOmni setlocal commentstring=#\ %s inoreabbrev :today: =luaeval("require('orgmode.objects.date').today():to_wrapped_string(true)") diff --git a/lua/orgmode/config/defaults.lua b/lua/orgmode/config/defaults.lua index 50583be81..49334e387 100644 --- a/lua/orgmode/config/defaults.lua +++ b/lua/orgmode/config/defaults.lua @@ -16,6 +16,7 @@ local DefaultConfig = { template = '* TODO %?\n %u', }, }, + org_startup_folded = 'overview', org_agenda_skip_scheduled_if_done = false, org_agenda_skip_deadline_if_done = false, org_agenda_text_search_extra_files = {}, diff --git a/lua/orgmode/config/init.lua b/lua/orgmode/config/init.lua index 111fde0f1..55b53cd7a 100644 --- a/lua/orgmode/config/init.lua +++ b/lua/orgmode/config/init.lua @@ -292,6 +292,21 @@ function Config:setup_mappings(category, buffer) end end +--- Setup the foldlevel for a given org file +function Config:setup_foldlevel() + if self.org_startup_folded == 'overview' then + vim.opt_local.foldlevel = 0 + elseif self.org_startup_folded == 'content' then + vim.opt_local.foldlevel = 1 + elseif self.org_startup_folded == 'showeverything' then + vim.opt_local.foldlevel = 99 + elseif self.org_startup_folded ~= 'inherit' then + utils.echo_warning("Invalid option passed for 'org_startup_folded'!") + self.opts.org_startup_folded = 'overview' + self:setup_foldlevel() + end +end + ---@return string|nil function Config:parse_archive_location(file, archive_loc) if self:is_archive_file(file) then