Skip to content

Commit

Permalink
feat: Allow for configuration of foldlevel similar to Emacs Orgmode (
Browse files Browse the repository at this point in the history
  • Loading branch information
PriceHiller authored Sep 26, 2023
1 parent 983fc95 commit 5325a8e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ Applies to:
- agenda window
- capture window

#### **org_startup_folded**
*type*: `string`<br />
*default value*: `overview`<br />
How many headings and other foldable items should be shown when an org file is opened.<br />
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<string, string>`<br />
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/org.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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()')
Expand All @@ -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 <silent><buffer> :today: <C-R>=luaeval("require('orgmode.objects.date').today():to_wrapped_string(true)")<CR>
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 @@ -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 = {},
Expand Down
15 changes: 15 additions & 0 deletions lua/orgmode/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5325a8e

Please sign in to comment.