Skip to content

Commit 4dcba70

Browse files
fix(agenda): use only available filters for matching
1 parent b1922c6 commit 4dcba70

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

lua/orgmode/agenda/types/agenda.lua

+10-8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ local SortingStrategy = require('orgmode.agenda.sorting_strategy')
5555
---@field clock_report_view? OrgAgendaView
5656
---@field sorting_strategy? OrgAgendaSortingStrategy[]
5757
---@field remove_tags? boolean
58+
---@field valid_filters? OrgAgendaFilter[]
5859
---@field id? string
5960
local OrgAgendaType = {}
6061
OrgAgendaType.__index = OrgAgendaType
@@ -82,6 +83,14 @@ function OrgAgendaType:new(opts)
8283
id = opts.id,
8384
remove_tags = type(opts.remove_tags) == 'boolean' and opts.remove_tags or config.org_agenda_remove_tags,
8485
}
86+
data.valid_filters = vim.tbl_filter(function(filter)
87+
return filter and true or false
88+
end, {
89+
data.filter,
90+
data.tag_filter,
91+
data.category_filter,
92+
data.agenda_filter,
93+
})
8594
local this = setmetatable(data, OrgAgendaType)
8695
this:_set_date_range()
8796
this:_setup_agenda_files()
@@ -412,14 +421,7 @@ function OrgAgendaType:toggle_clock_report()
412421
end
413422

414423
function OrgAgendaType:_matches_filters(headline)
415-
local valid_filters = {
416-
self.filter,
417-
self.tag_filter,
418-
self.category_filter,
419-
self.agenda_filter,
420-
}
421-
422-
for _, filter in ipairs(valid_filters) do
424+
for _, filter in ipairs(self.valid_filters) do
423425
if filter and not filter:matches(headline) then
424426
return false
425427
end

lua/orgmode/agenda/types/todo.lua

+10-8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ local SortingStrategy = require('orgmode.agenda.sorting_strategy')
3838
---@field todo_only? boolean
3939
---@field sorting_strategy? OrgAgendaSortingStrategy[]
4040
---@field remove_tags? boolean
41+
---@field valid_filters OrgAgendaFilter[]
4142
---@field id? string
4243
local OrgAgendaTodosType = {}
4344
OrgAgendaTodosType.__index = OrgAgendaTodosType
@@ -60,6 +61,14 @@ function OrgAgendaTodosType:new(opts)
6061
id = opts.id,
6162
remove_tags = type(opts.remove_tags) == 'boolean' and opts.remove_tags or config.org_agenda_remove_tags,
6263
}, OrgAgendaTodosType)
64+
this.valid_filters = vim.tbl_filter(function(filter)
65+
return filter and true or false
66+
end, {
67+
this.filter,
68+
this.tag_filter,
69+
this.category_filter,
70+
this.agenda_filter,
71+
})
6372

6473
this:_setup_agenda_files()
6574
return this
@@ -202,14 +211,7 @@ function OrgAgendaTodosType:_get_headlines()
202211
end
203212

204213
function OrgAgendaTodosType:_matches_filters(headline)
205-
local valid_filters = {
206-
self.agenda_filter,
207-
self.filter,
208-
self.tag_filter,
209-
self.category_filter,
210-
}
211-
212-
for _, filter in ipairs(valid_filters) do
214+
for _, filter in ipairs(self.valid_filters) do
213215
if filter and not filter:matches(headline) then
214216
return false
215217
end

0 commit comments

Comments
 (0)