Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow for configuration of foldlevel similar to Emacs Orgmode #615

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
vim.notify("Invalid option passed for 'org_startup_folded'!", vim.log.levels.WARN)
self.org_startup_folded = 'overview'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since config does not have __newindex metamethod, this will not be set in the correct place.
It should be self.opts.org_startup_folded = 'overview'.

For the warning message, please use utils.echo_warning since that's what we use for other warnings so it is consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, done now. Did not know that Orgmode had its own utilities for info/warn/error.

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
Loading