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 committed Sep 25, 2023
1 parent ac5f48c commit 7b8a5be
Show file tree
Hide file tree
Showing 3 changed files with 23 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
13 changes: 13 additions & 0 deletions lua/orgmode/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,19 @@ 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
error("Invalid option passed for `org_startup_folded`!")
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 7b8a5be

Please sign in to comment.