Skip to content

Commit 090965e

Browse files
feat(agenda): Add option to hide custom agenda views that are empty
See `org_agenda_hide_empty_blocks` in docs.
1 parent 9bfba3d commit 090965e

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

docs/configuration.org

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,14 @@ These arguments are shared between all of the agenda types:
741741
- =far= - Do not show deadlines that are too far in future (over [[#org_deadline_warning_days][org_deadline_warning_days]])
742742
- =near= - Do not show deadlines that are too near in future (under [[#org_deadline_warning_days][org_deadline_warning_days]])
743743

744+
*** org_agenda_hide_empty_blocks
745+
:PROPERTIES:
746+
:CUSTOM_ID: org_agenda_hide_empty_blocks
747+
:END:
748+
- Type: =boolean=
749+
- Default: =false=
750+
Should custom agenda commands be hidden if they have no entries to show. Does not work for =agenda= type since it shows days.
751+
744752
*** org_agenda_sorting_strategy
745753
:PROPERTIES:
746754
:CUSTOM_ID: org_agenda_sorting_strategy

lua/orgmode/agenda/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function Agenda:render()
7878
local bufnr = self:_open_window()
7979
for i, view in ipairs(self.views) do
8080
view:render(bufnr, line)
81-
if #self.views > 1 and i < #self.views then
81+
if #self.views > 1 and i < #self.views and #view:get_lines() > 0 then
8282
colors.add_hr(bufnr, vim.api.nvim_buf_line_count(bufnr), config.org_agenda_block_separator)
8383
end
8484
end

lua/orgmode/agenda/types/todo.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ function OrgAgendaTodosType:render(bufnr)
108108
local headlines, category_length = self:_get_headlines()
109109
local agendaView = AgendaView:new({ bufnr = self.bufnr, highlighter = self.highlighter })
110110

111+
-- If custom view and no headlines, return empty view
112+
-- Works only for custom agenda views (has id)
113+
if self.id and config.org_agenda_hide_empty_blocks and #headlines == 0 then
114+
self.view = agendaView:render()
115+
return self.view
116+
end
117+
111118
agendaView:add_line(AgendaLine:single_token({
112119
content = self:_get_header(),
113120
hl_group = '@org.agenda.header',
@@ -123,9 +130,8 @@ function OrgAgendaTodosType:render(bufnr)
123130
agendaView:add_line(self:_build_line(headline, { category_length = category_length }))
124131
end
125132

126-
local result = agendaView:render()
127-
self.view = result
128-
return result
133+
self.view = agendaView:render()
134+
return self.view
129135
end
130136

131137
---@private

lua/orgmode/config/_meta.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
---@field org_agenda_skip_scheduled_if_done? boolean If true, scheduled entries marked as done will not be shown in the agenda. Default: false
214214
---@field org_agenda_skip_deadline_if_done? boolean If true, deadline entries marked as done will not be shown in the agenda. Default: false
215215
---@field org_agenda_text_search_extra_files? ('agenda-archives')[] Additional files to earch from agenda search prompt. Default: {}
216+
---@field org_agenda_hide_empty_blocks? boolean Hide empty custom agenda commands in agenda view. Default: false
216217
---@field org_agenda_custom_commands? table<string, OrgAgendaCustomCommand> Custom commands for the agenda view. Default: {}
217218
---@field org_agenda_block_separator? string Separator for blocks in the agenda view. Default: '-'
218219
---@field org_agenda_sorting_strategy? table<'agenda' | 'todo' | 'tags', OrgAgendaSortingStrategy[]> Sorting strategy for the agenda view. See docs for default value

lua/orgmode/config/defaults.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ local DefaultConfig = {
2626
org_agenda_skip_deadline_if_done = false,
2727
org_agenda_text_search_extra_files = {},
2828
org_agenda_custom_commands = {},
29+
org_agenda_hide_empty_blocks = false,
2930
org_agenda_block_separator = '-',
3031
org_agenda_sorting_strategy = {
3132
agenda = { 'time-up', 'priority-down', 'category-keep' },

0 commit comments

Comments
 (0)