From 79a0c7837fdf9ee41192b45d1603f749e2278375 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Mon, 22 Nov 2021 22:58:54 +0100 Subject: [PATCH 01/36] if no HH:MM then sort after --- lua/orgmode/objects/date.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lua/orgmode/objects/date.lua b/lua/orgmode/objects/date.lua index e6d808059..6725df93f 100644 --- a/lua/orgmode/objects/date.lua +++ b/lua/orgmode/objects/date.lua @@ -524,6 +524,15 @@ function Date:is_same_or_after(date, span) d = date:start_of(span) s = self:start_of(span) end + if s.date_only and not d.date_only then + return true + end + if d.date_only and not s.date_only then + return false + end + if d.date_only and s.date_only then + return false + end return s.timestamp >= d.timestamp end From ad47fe055fcc36d54bba3281d9b1df657b98bcb5 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Mon, 22 Nov 2021 23:05:58 +0100 Subject: [PATCH 02/36] reverse logic --- lua/orgmode/objects/date.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/orgmode/objects/date.lua b/lua/orgmode/objects/date.lua index 6725df93f..d74d76da9 100644 --- a/lua/orgmode/objects/date.lua +++ b/lua/orgmode/objects/date.lua @@ -525,13 +525,13 @@ function Date:is_same_or_after(date, span) s = self:start_of(span) end if s.date_only and not d.date_only then - return true + return false end if d.date_only and not s.date_only then - return false + return true end if d.date_only and s.date_only then - return false + return true end return s.timestamp >= d.timestamp end From fde2780cfb22e76da9fead6932da8c44eab3f7be Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Mon, 22 Nov 2021 23:15:01 +0100 Subject: [PATCH 03/36] moved check to sort function --- lua/orgmode/agenda/init.lua | 10 ++++++++++ lua/orgmode/objects/date.lua | 9 --------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index d117f80f5..d6c504229 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -18,6 +18,15 @@ local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then + if a.date_only and not b.date_only then + return false + end + if not a.date_only and b.date_only then + return true + end + if a.date_only and b.date_only then + return false + end return a.headline_date:is_before(b.headline_date) end return true @@ -25,6 +34,7 @@ local function sort_agenda_items(agenda_items) if b.is_today and b.is_same_day then if a.is_today and a.is_same_day then + -- isn't this covered above? return a.headline_date:is_before(b.headline_date) end return false diff --git a/lua/orgmode/objects/date.lua b/lua/orgmode/objects/date.lua index d74d76da9..e6d808059 100644 --- a/lua/orgmode/objects/date.lua +++ b/lua/orgmode/objects/date.lua @@ -524,15 +524,6 @@ function Date:is_same_or_after(date, span) d = date:start_of(span) s = self:start_of(span) end - if s.date_only and not d.date_only then - return false - end - if d.date_only and not s.date_only then - return true - end - if d.date_only and s.date_only then - return true - end return s.timestamp >= d.timestamp end From ae6415d99bd41e1dc195bc424eae3a21bebb96e0 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Mon, 22 Nov 2021 23:17:22 +0100 Subject: [PATCH 04/36] added the same to reversed case --- lua/orgmode/agenda/init.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index d6c504229..82f60c37b 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -35,6 +35,15 @@ local function sort_agenda_items(agenda_items) if b.is_today and b.is_same_day then if a.is_today and a.is_same_day then -- isn't this covered above? + if a.date_only and not b.date_only then + return false + end + if not a.date_only and b.date_only then + return true + end + if a.date_only and b.date_only then + return false + end return a.headline_date:is_before(b.headline_date) end return false From f58d3b1d5b917173d790a107d4de10783dee35bf Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Mon, 22 Nov 2021 23:36:12 +0100 Subject: [PATCH 05/36] added proper reference --- lua/orgmode/agenda/init.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 82f60c37b..d9df18441 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -18,13 +18,13 @@ local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then - if a.date_only and not b.date_only then + if a.headline_date.date_only and not b.headline_date.date_only then return false end - if not a.date_only and b.date_only then + if not a.headline_date.date_only and b.headline_date.date_only then return true end - if a.date_only and b.date_only then + if a.headline_date.date_only and b.headline_date.date_only then return false end return a.headline_date:is_before(b.headline_date) @@ -35,15 +35,15 @@ local function sort_agenda_items(agenda_items) if b.is_today and b.is_same_day then if a.is_today and a.is_same_day then -- isn't this covered above? - if a.date_only and not b.date_only then - return false - end - if not a.date_only and b.date_only then - return true - end - if a.date_only and b.date_only then - return false - end + -- if a.date_only and not b.date_only then + -- return false + -- end + -- if not a.date_only and b.date_only then + -- return true + -- end + -- if a.date_only and b.date_only then + -- return false + -- end return a.headline_date:is_before(b.headline_date) end return false From 42d7229219732c4d06f4b928df385a7a338ed50d Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Mon, 22 Nov 2021 23:38:22 +0100 Subject: [PATCH 06/36] added lines below --- lua/orgmode/agenda/init.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index d9df18441..6794f6e32 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -35,15 +35,15 @@ local function sort_agenda_items(agenda_items) if b.is_today and b.is_same_day then if a.is_today and a.is_same_day then -- isn't this covered above? - -- if a.date_only and not b.date_only then - -- return false - -- end - -- if not a.date_only and b.date_only then - -- return true - -- end - -- if a.date_only and b.date_only then - -- return false - -- end + if a.headline_date.date_only and not b.headline_date.date_only then + return false + end + if not a.headline_date.date_only and b.headline_date.date_only then + return true + end + if a.headline_date.date_only and b.headline_date.date_only then + return false + end return a.headline_date:is_before(b.headline_date) end return false From 30dcd34c124404d57b68d11e1013e523bdb59fd6 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Mon, 22 Nov 2021 23:43:08 +0100 Subject: [PATCH 07/36] last try --- lua/orgmode/agenda/init.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 6794f6e32..79902321b 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -32,6 +32,19 @@ local function sort_agenda_items(agenda_items) return true end + if a.is_same_day and b.is_same_day then + if a.headline_date.date_only and not b.headline_date.date_only then + return false + end + if not a.headline_date.date_only and b.headline_date.date_only then + return true + end + if a.headline_date.date_only and b.headline_date.date_only then + return false + end + return false + end + if b.is_today and b.is_same_day then if a.is_today and a.is_same_day then -- isn't this covered above? From 0ac91a7e94928a27435c335af59b331d01b964be Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 22:02:26 +0100 Subject: [PATCH 08/36] sorting date onlys first --- lua/orgmode/agenda/init.lua | 43 ++++++++++--------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 79902321b..13d07d53b 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -16,47 +16,26 @@ local hl_map = agenda_highlights.get_agenda_hl_map() ---@return AgendaItem[] local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) + -- date only items get sorted last + if not a.headline_date.date_only and b.headline_date.date_only then + return false + end + if a.headline_date.date_only and not b.headline_date.date_only then + return true + end + if a.headline_date.date_only and b.headline_date.date_only then + -- if both are date only don't change their order + return false + end if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then - if a.headline_date.date_only and not b.headline_date.date_only then - return false - end - if not a.headline_date.date_only and b.headline_date.date_only then - return true - end - if a.headline_date.date_only and b.headline_date.date_only then - return false - end return a.headline_date:is_before(b.headline_date) end return true end - if a.is_same_day and b.is_same_day then - if a.headline_date.date_only and not b.headline_date.date_only then - return false - end - if not a.headline_date.date_only and b.headline_date.date_only then - return true - end - if a.headline_date.date_only and b.headline_date.date_only then - return false - end - return false - end - if b.is_today and b.is_same_day then if a.is_today and a.is_same_day then - -- isn't this covered above? - if a.headline_date.date_only and not b.headline_date.date_only then - return false - end - if not a.headline_date.date_only and b.headline_date.date_only then - return true - end - if a.headline_date.date_only and b.headline_date.date_only then - return false - end return a.headline_date:is_before(b.headline_date) end return false From f6539b63a6dc2b6735893dd4b42afc270b2274b8 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 22:05:58 +0100 Subject: [PATCH 09/36] changed true to false --- lua/orgmode/agenda/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 13d07d53b..24b09c632 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -18,14 +18,14 @@ local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) -- date only items get sorted last if not a.headline_date.date_only and b.headline_date.date_only then - return false + return true end if a.headline_date.date_only and not b.headline_date.date_only then - return true + return false end if a.headline_date.date_only and b.headline_date.date_only then -- if both are date only don't change their order - return false + return true end if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then From d314998a0951d0c68755127fb006e7462e526b2b Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 22:14:50 +0100 Subject: [PATCH 10/36] sort function doesn't work --- lua/orgmode/agenda/init.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 24b09c632..ef25e8beb 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -16,17 +16,18 @@ local hl_map = agenda_highlights.get_agenda_hl_map() ---@return AgendaItem[] local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) + -- if both are date only don't change their order + if a.headline_date.date_only and b.headline_date.date_only then + return false + end -- date only items get sorted last if not a.headline_date.date_only and b.headline_date.date_only then - return true - end - if a.headline_date.date_only and not b.headline_date.date_only then return false end - if a.headline_date.date_only and b.headline_date.date_only then - -- if both are date only don't change their order + if a.headline_date.date_only and not b.headline_date.date_only then return true end + if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then return a.headline_date:is_before(b.headline_date) From ca76fd180889e2538bd41bc3701f045be8fb1044 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 22:20:11 +0100 Subject: [PATCH 11/36] separate date_only from timed events before sorting --- lua/orgmode/agenda/init.lua | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index ef25e8beb..b8c6c5d1c 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -16,17 +16,17 @@ local hl_map = agenda_highlights.get_agenda_hl_map() ---@return AgendaItem[] local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) - -- if both are date only don't change their order - if a.headline_date.date_only and b.headline_date.date_only then - return false - end - -- date only items get sorted last - if not a.headline_date.date_only and b.headline_date.date_only then - return false - end - if a.headline_date.date_only and not b.headline_date.date_only then - return true - end + -- -- if both are date only don't change their order + -- if a.headline_date.date_only and b.headline_date.date_only then + -- return false + -- end + -- -- date only items get sorted last + -- if not a.headline_date.date_only and b.headline_date.date_only then + -- return false + -- end + -- if a.headline_date.date_only and not b.headline_date.date_only then + -- return true + -- end if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then @@ -469,17 +469,23 @@ function Agenda:agenda() for _, day in ipairs(dates) do local date = { day = day, agenda_items = {} } + local date_only = { day = day, agenda_items = {} } for _, item in ipairs(headline_dates) do local agenda_item = AgendaItem:new(item.headline_date, item.headline, day) if agenda_item.is_valid and self.filters:matches(item.headline) then - table.insert(date.agenda_items, agenda_item) + if item.headline_date.date_only then + table.insert(date_only.agenda_items, agenda_item) + else + table.insert(date.agenda_items, agenda_item) + end end end date.agenda_items = sort_agenda_items(date.agenda_items) table.insert(agenda_days, date) + table.insert(agenda_days, date_only) end self.items = agenda_days From ea0b924d36ad3c6dbff1c6306664a859db1ab935 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 22:28:01 +0100 Subject: [PATCH 12/36] concatenate tables before insert --- lua/orgmode/agenda/init.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index b8c6c5d1c..c04bcf99a 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -481,11 +481,10 @@ function Agenda:agenda() end end end - date.agenda_items = sort_agenda_items(date.agenda_items) + date = utils.concat(date, date_only, false) table.insert(agenda_days, date) - table.insert(agenda_days, date_only) end self.items = agenda_days From 24935c9528dcc9707ef7571d3be5895be0b2f099 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 22:29:57 +0100 Subject: [PATCH 13/36] concatenate agenda items --- lua/orgmode/agenda/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index c04bcf99a..fad200ce6 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -483,7 +483,7 @@ function Agenda:agenda() end date.agenda_items = sort_agenda_items(date.agenda_items) - date = utils.concat(date, date_only, false) + date = utils.concat(date.agenda_items, date_only.agenda_items, false) table.insert(agenda_days, date) end From 4afd6bc821786739480ea451e53e866ec986a01c Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 22:31:10 +0100 Subject: [PATCH 14/36] agenda items concatenation fix --- lua/orgmode/agenda/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index fad200ce6..62fffc75a 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -483,7 +483,7 @@ function Agenda:agenda() end date.agenda_items = sort_agenda_items(date.agenda_items) - date = utils.concat(date.agenda_items, date_only.agenda_items, false) + date.agenda_items = utils.concat(date.agenda_items, date_only.agenda_items, false) table.insert(agenda_days, date) end From 390636c548ca2866b257c6b6bc0b2d2cd230276b Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 22:56:20 +0100 Subject: [PATCH 15/36] commented out file sorting --- lua/orgmode/parser/files.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lua/orgmode/parser/files.lua b/lua/orgmode/parser/files.lua index 6f8f9ebac..934029150 100644 --- a/lua/orgmode/parser/files.lua +++ b/lua/orgmode/parser/files.lua @@ -85,9 +85,10 @@ end function Files.all() Files.ensure_loaded() local files = vim.tbl_values(Files.orgfiles) - table.sort(files, function(a, b) - return a.category < b.category - end) + -- this sorts files alphabetically, I'm not sure if it's useful + -- table.sort(files, function(a, b) + -- return a.category < b.category + -- end) return files end From 471673aa3302c02f0f30d15597516a7bd9978472 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 23:16:54 +0100 Subject: [PATCH 16/36] sort not same days at end --- lua/orgmode/agenda/init.lua | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 62fffc75a..b31e451d5 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -16,17 +16,6 @@ local hl_map = agenda_highlights.get_agenda_hl_map() ---@return AgendaItem[] local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) - -- -- if both are date only don't change their order - -- if a.headline_date.date_only and b.headline_date.date_only then - -- return false - -- end - -- -- date only items get sorted last - -- if not a.headline_date.date_only and b.headline_date.date_only then - -- return false - -- end - -- if a.headline_date.date_only and not b.headline_date.date_only then - -- return true - -- end if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then @@ -474,7 +463,7 @@ function Agenda:agenda() for _, item in ipairs(headline_dates) do local agenda_item = AgendaItem:new(item.headline_date, item.headline, day) if agenda_item.is_valid and self.filters:matches(item.headline) then - if item.headline_date.date_only then + if item.headline_date.date_only and not item.headline_date.is_same_day then table.insert(date_only.agenda_items, agenda_item) else table.insert(date.agenda_items, agenda_item) From b7720ed6e4d16797eb1184eea9f22c1da67149fd Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 23:18:27 +0100 Subject: [PATCH 17/36] same day and date_only --- lua/orgmode/agenda/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index b31e451d5..da86fa9e8 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -463,7 +463,7 @@ function Agenda:agenda() for _, item in ipairs(headline_dates) do local agenda_item = AgendaItem:new(item.headline_date, item.headline, day) if agenda_item.is_valid and self.filters:matches(item.headline) then - if item.headline_date.date_only and not item.headline_date.is_same_day then + if item.headline_date.date_only and item.headline_date.is_same_day then table.insert(date_only.agenda_items, agenda_item) else table.insert(date.agenda_items, agenda_item) From def02ca0b680d8f7d1fc00608b20daa3383d4822 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 23:24:27 +0100 Subject: [PATCH 18/36] same day correctly referenced --- lua/orgmode/agenda/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index da86fa9e8..d25976485 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -463,7 +463,7 @@ function Agenda:agenda() for _, item in ipairs(headline_dates) do local agenda_item = AgendaItem:new(item.headline_date, item.headline, day) if agenda_item.is_valid and self.filters:matches(item.headline) then - if item.headline_date.date_only and item.headline_date.is_same_day then + if item.headline_date.date_only and item.is_same_day then table.insert(date_only.agenda_items, agenda_item) else table.insert(date.agenda_items, agenda_item) From 7a7fb0f8006c59ee67e6a7aae46163df18e47fca Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 23:25:41 +0100 Subject: [PATCH 19/36] agenda_item.is_same_day --- lua/orgmode/agenda/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index d25976485..6aefb3045 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -463,7 +463,7 @@ function Agenda:agenda() for _, item in ipairs(headline_dates) do local agenda_item = AgendaItem:new(item.headline_date, item.headline, day) if agenda_item.is_valid and self.filters:matches(item.headline) then - if item.headline_date.date_only and item.is_same_day then + if item.headline_date.date_only and agenda_item.is_same_day then table.insert(date_only.agenda_items, agenda_item) else table.insert(date.agenda_items, agenda_item) From 3001ab66a166f8070475149f33e545e375461a61 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 23:29:08 +0100 Subject: [PATCH 20/36] sorting not_same_day last --- lua/orgmode/agenda/init.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 6aefb3045..333a6cc4e 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -459,11 +459,14 @@ function Agenda:agenda() for _, day in ipairs(dates) do local date = { day = day, agenda_items = {} } local date_only = { day = day, agenda_items = {} } + local date_not_same = { day = day, agenda_items = {} } for _, item in ipairs(headline_dates) do local agenda_item = AgendaItem:new(item.headline_date, item.headline, day) if agenda_item.is_valid and self.filters:matches(item.headline) then - if item.headline_date.date_only and agenda_item.is_same_day then + if agenda_item.is_same_day then + table.insert(date_not_same.agenda_items, agenda_item) + elseif item.headline_date.date_only then table.insert(date_only.agenda_items, agenda_item) else table.insert(date.agenda_items, agenda_item) @@ -471,8 +474,10 @@ function Agenda:agenda() end end date.agenda_items = sort_agenda_items(date.agenda_items) + date_not_same.agenda_items = sort_agenda_items(date_not_same.agenda_items) date.agenda_items = utils.concat(date.agenda_items, date_only.agenda_items, false) + date.agenda_items = utils.concat(date.agenda_items, date_not_same.agenda_items, false) table.insert(agenda_days, date) end From 3b1231d1dcc5467c1adc6e7093bd97db17d3786f Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Tue, 23 Nov 2021 23:30:11 +0100 Subject: [PATCH 21/36] not same day --- lua/orgmode/agenda/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 333a6cc4e..7f1b22b2e 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -464,7 +464,7 @@ function Agenda:agenda() for _, item in ipairs(headline_dates) do local agenda_item = AgendaItem:new(item.headline_date, item.headline, day) if agenda_item.is_valid and self.filters:matches(item.headline) then - if agenda_item.is_same_day then + if not agenda_item.is_same_day then table.insert(date_not_same.agenda_items, agenda_item) elseif item.headline_date.date_only then table.insert(date_only.agenda_items, agenda_item) From 6040df242792f14419f1d690b90f9995df35a9bc Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Wed, 24 Nov 2021 00:05:30 +0100 Subject: [PATCH 22/36] working on sorting tasks --- lua/orgmode/agenda/init.lua | 15 +++++++++++++++ lua/orgmode/config/init.lua | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 7f1b22b2e..f2bfba674 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -52,6 +52,13 @@ local function sort_agenda_items(agenda_items) return agenda_items end +local function sort_agenda_items_categories(agenda_items, category_inds) + table.sort(agenda_items, function(a, b) + return category_inds[a.category] < category_inds[b.category] + end) + return agenda_items +end + local function sort_todos(todos) table.sort(todos, function(a, b) if a:get_priority_sort_value() ~= b:get_priority_sort_value() then @@ -441,6 +448,13 @@ function Agenda:prompt() end function Agenda:agenda() + local files = config:get_all_files() + local categories = config:get_categories(files) + local category_inds = {} + for i, category in ipairs(categories) do + category_inds[category] = i + end + local dates = self.from:get_range_until(self.to) local agenda_days = {} @@ -475,6 +489,7 @@ function Agenda:agenda() end date.agenda_items = sort_agenda_items(date.agenda_items) date_not_same.agenda_items = sort_agenda_items(date_not_same.agenda_items) + date_only.agenda_items = sort_agenda_items_categories(date_not_same.agenda_items, category_inds) date.agenda_items = utils.concat(date.agenda_items, date_only.agenda_items, false) date.agenda_items = utils.concat(date.agenda_items, date_not_same.agenda_items, false) diff --git a/lua/orgmode/config/init.lua b/lua/orgmode/config/init.lua index f29c4d09c..6eba185f1 100644 --- a/lua/orgmode/config/init.lua +++ b/lua/orgmode/config/init.lua @@ -64,6 +64,16 @@ function Config:_deprecation_notify(opts) end end +---@return string[] +function Config:get_categories(files) + local categories = {} + for _, item in ipairs(files) do + local category = vim.fn.fnamemodify(item, ':t:r') + table.insert(categories, category) + end + return categories +end + ---@return string[] function Config:get_all_files() local all_filenames = {} From 365815da36c1408eff1d4aeeddd007d5a056c17f Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Wed, 24 Nov 2021 00:18:26 +0100 Subject: [PATCH 23/36] access category through headline --- lua/orgmode/agenda/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index f2bfba674..4d18b2440 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -54,7 +54,7 @@ end local function sort_agenda_items_categories(agenda_items, category_inds) table.sort(agenda_items, function(a, b) - return category_inds[a.category] < category_inds[b.category] + return category_inds[a.headline:get_category()] < category_inds[b.headline:get_category()] end) return agenda_items end From d305438be5691a628562a814ff0962943dbd4943 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Wed, 24 Nov 2021 00:21:47 +0100 Subject: [PATCH 24/36] fix bug --- lua/orgmode/agenda/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 4d18b2440..e7e88a444 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -489,7 +489,7 @@ function Agenda:agenda() end date.agenda_items = sort_agenda_items(date.agenda_items) date_not_same.agenda_items = sort_agenda_items(date_not_same.agenda_items) - date_only.agenda_items = sort_agenda_items_categories(date_not_same.agenda_items, category_inds) + date_only.agenda_items = sort_agenda_items_categories(date_only.agenda_items, category_inds) date.agenda_items = utils.concat(date.agenda_items, date_only.agenda_items, false) date.agenda_items = utils.concat(date.agenda_items, date_not_same.agenda_items, false) From a25b71b12667ecd822285de82065909459bed91b Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Sat, 27 Nov 2021 22:00:03 +0100 Subject: [PATCH 25/36] refactoring everything to the sort function --- lua/orgmode/agenda/init.lua | 68 +++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index e7e88a444..f8638c7b9 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -12,33 +12,68 @@ local Search = require('orgmode.parser.search') local AgendaFilter = require('orgmode.agenda.filter') local hl_map = agenda_highlights.get_agenda_hl_map() +--@return table[] +local function get_category_inds() + local files = config:get_all_files() + local categories = config:get_categories(files) + local category_inds = {} + for i, category in ipairs(categories) do + category_inds[category] = i + end + return category_inds +end + ---@param agenda_items AgendaItem[] ---@return AgendaItem[] local function sort_agenda_items(agenda_items) + local category_inds = get_category_inds() + table.sort(agenda_items, function(a, b) + -- sort items with a time of day in order of scheduling + if not a.headline_date.date_only and not b.headline_date.date_only then + if a.is_today and a.is_same_day then + if b.is_today and b.is_same_day then + return a.headline_date:is_before(b.headline_date) + end + return true + end - if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then - return a.headline_date:is_before(b.headline_date) + if a.is_today and a.is_same_day then + return a.headline_date:is_before(b.headline_date) + end + return false end - return true end - if b.is_today and b.is_same_day then - if a.is_today and a.is_same_day then - return a.headline_date:is_before(b.headline_date) - end + -- sort items with a time of day before ones that have a date only + if not a.headline_date.date_only and b.headline_date.date_only then return false end + if a.headline_date.date_only and not b.headline_date.date_only then + return true + end + + -- else both items are date only, sort in this order: + -- category > priority > overdue deadline > overdue schedule > + -- > today deadline > today schedule + -- if different categories sort by category + if a.headline:get_category() ~= b.headline:get_category() then + return category_inds[a.headline:get_category()] < category_inds[b.headline:get_category()] + end + + -- if different priorities sort by priority if a.headline:get_priority_sort_value() ~= b.headline:get_priority_sort_value() then return a.headline:get_priority_sort_value() > b.headline:get_priority_sort_value() end + -- if same priority sort by overdue if a.headline:has_priority() and b.headline:has_priority() then return a.headline_date:is_before(b.headline_date) end + -- I don't get these ones ... if a.is_in_date_range and not b.is_in_date_range then return false end @@ -448,13 +483,6 @@ function Agenda:prompt() end function Agenda:agenda() - local files = config:get_all_files() - local categories = config:get_categories(files) - local category_inds = {} - for i, category in ipairs(categories) do - category_inds[category] = i - end - local dates = self.from:get_range_until(self.to) local agenda_days = {} @@ -472,27 +500,15 @@ function Agenda:agenda() for _, day in ipairs(dates) do local date = { day = day, agenda_items = {} } - local date_only = { day = day, agenda_items = {} } - local date_not_same = { day = day, agenda_items = {} } for _, item in ipairs(headline_dates) do local agenda_item = AgendaItem:new(item.headline_date, item.headline, day) if agenda_item.is_valid and self.filters:matches(item.headline) then - if not agenda_item.is_same_day then - table.insert(date_not_same.agenda_items, agenda_item) - elseif item.headline_date.date_only then - table.insert(date_only.agenda_items, agenda_item) - else table.insert(date.agenda_items, agenda_item) - end end end date.agenda_items = sort_agenda_items(date.agenda_items) - date_not_same.agenda_items = sort_agenda_items(date_not_same.agenda_items) - date_only.agenda_items = sort_agenda_items_categories(date_only.agenda_items, category_inds) - date.agenda_items = utils.concat(date.agenda_items, date_only.agenda_items, false) - date.agenda_items = utils.concat(date.agenda_items, date_not_same.agenda_items, false) table.insert(agenda_days, date) end From a86f62c33ef02abd0142c80c1b8d80921f09b6ae Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Sun, 28 Nov 2021 21:03:55 +0100 Subject: [PATCH 26/36] reverse time of day based sorting --- lua/orgmode/agenda/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index f8638c7b9..83f4d27a3 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -48,10 +48,10 @@ local function sort_agenda_items(agenda_items) -- sort items with a time of day before ones that have a date only if not a.headline_date.date_only and b.headline_date.date_only then - return false + return true end if a.headline_date.date_only and not b.headline_date.date_only then - return true + return false end -- else both items are date only, sort in this order: @@ -73,7 +73,7 @@ local function sort_agenda_items(agenda_items) return a.headline_date:is_before(b.headline_date) end - -- I don't get these ones ... + -- I don't get these ones - they feel reverse ... if a.is_in_date_range and not b.is_in_date_range then return false end From 7b9c4a2aa280611b74f932950cf15b72fe4e4e4f Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Sun, 28 Nov 2021 21:12:56 +0100 Subject: [PATCH 27/36] print some debug output --- lua/orgmode/agenda/init.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 83f4d27a3..531c903fb 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -30,6 +30,11 @@ local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) -- sort items with a time of day in order of scheduling + print(a) + print("headline date") + print(a.headline_date) + print("headline date.date_only") + print(a.headline_date.date_only) if not a.headline_date.date_only and not b.headline_date.date_only then if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then @@ -47,6 +52,7 @@ local function sort_agenda_items(agenda_items) end -- sort items with a time of day before ones that have a date only + -- seems that the logic is reverse somehow ... if not a.headline_date.date_only and b.headline_date.date_only then return true end From 3394c94ca307750ea2b05ce4d3fcd15dc7c2a1c1 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Sun, 28 Nov 2021 21:17:12 +0100 Subject: [PATCH 28/36] added debug printing function --- lua/orgmode/agenda/init.lua | 10 +++++----- lua/orgmode/utils/init.lua | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 531c903fb..bd55f317d 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -30,11 +30,11 @@ local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) -- sort items with a time of day in order of scheduling - print(a) - print("headline date") - print(a.headline_date) - print("headline date.date_only") - print(a.headline_date.date_only) + utils.tprint(a) + utils.tprint("headline date") + utils.tprint(a.headline_date) + utils.tprint("headline date.date_only") + utils.tprint(a.headline_date.date_only) if not a.headline_date.date_only and not b.headline_date.date_only then if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then diff --git a/lua/orgmode/utils/init.lua b/lua/orgmode/utils/init.lua index 38b93be78..f415d6282 100644 --- a/lua/orgmode/utils/init.lua +++ b/lua/orgmode/utils/init.lua @@ -427,4 +427,31 @@ function utils.promisify(fn) return fn end +---debug printing a table +---source https://stackoverflow.com/questions/41942289/display-contents-of-tables-in-lua +function utils.tprint (tbl, indent) + if not indent then indent = 0 end + local toprint = string.rep(" ", indent) .. "{\r\n" + indent = indent + 2 + for k, v in pairs(tbl) do + toprint = toprint .. string.rep(" ", indent) + if (type(k) == "number") then + toprint = toprint .. "[" .. k .. "] = " + elseif (type(k) == "string") then + toprint = toprint .. k .. "= " + end + if (type(v) == "number") then + toprint = toprint .. v .. ",\r\n" + elseif (type(v) == "string") then + toprint = toprint .. "\"" .. v .. "\",\r\n" + elseif (type(v) == "table") then + toprint = toprint .. tprint(v, indent + 2) .. ",\r\n" + else + toprint = toprint .. "\"" .. tostring(v) .. "\",\r\n" + end + end + toprint = toprint .. string.rep(" ", indent-2) .. "}" + return toprint +end + return utils From ea486afc0835de0902e9666d634f50a97a0d7ffe Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Sun, 28 Nov 2021 21:19:02 +0100 Subject: [PATCH 29/36] fix utils.tprint --- lua/orgmode/utils/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/utils/init.lua b/lua/orgmode/utils/init.lua index f415d6282..075bfca6e 100644 --- a/lua/orgmode/utils/init.lua +++ b/lua/orgmode/utils/init.lua @@ -429,7 +429,7 @@ end ---debug printing a table ---source https://stackoverflow.com/questions/41942289/display-contents-of-tables-in-lua -function utils.tprint (tbl, indent) +function utils.tprint(tbl, indent) if not indent then indent = 0 end local toprint = string.rep(" ", indent) .. "{\r\n" indent = indent + 2 From bbfd6313678a22e54ac949fbda434de06f541179 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Sun, 28 Nov 2021 21:21:22 +0100 Subject: [PATCH 30/36] fix tprint --- lua/orgmode/utils/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/utils/init.lua b/lua/orgmode/utils/init.lua index 075bfca6e..5acbaa04f 100644 --- a/lua/orgmode/utils/init.lua +++ b/lua/orgmode/utils/init.lua @@ -445,7 +445,7 @@ function utils.tprint(tbl, indent) elseif (type(v) == "string") then toprint = toprint .. "\"" .. v .. "\",\r\n" elseif (type(v) == "table") then - toprint = toprint .. tprint(v, indent + 2) .. ",\r\n" + toprint = toprint .. utils.tprint(v, indent + 2) .. ",\r\n" else toprint = toprint .. "\"" .. tostring(v) .. "\",\r\n" end From cc0d1e2342a63ed6c58fe4c1896181f304b2476c Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Sun, 28 Nov 2021 21:23:42 +0100 Subject: [PATCH 31/36] reduce printing --- lua/orgmode/agenda/init.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index bd55f317d..78320af9b 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -30,7 +30,6 @@ local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) -- sort items with a time of day in order of scheduling - utils.tprint(a) utils.tprint("headline date") utils.tprint(a.headline_date) utils.tprint("headline date.date_only") From c5e8eb288b51ff38694c47f6dfd03a5df093be3e Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Sun, 28 Nov 2021 21:24:55 +0100 Subject: [PATCH 32/36] minor fix --- lua/orgmode/agenda/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 78320af9b..2139273e5 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -30,9 +30,9 @@ local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) -- sort items with a time of day in order of scheduling - utils.tprint("headline date") + print("headline date") utils.tprint(a.headline_date) - utils.tprint("headline date.date_only") + print("headline date.date_only") utils.tprint(a.headline_date.date_only) if not a.headline_date.date_only and not b.headline_date.date_only then if a.is_today and a.is_same_day then From 98987718b536098d91b90b4bf2876ca51dd77672 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Sun, 28 Nov 2021 21:25:49 +0100 Subject: [PATCH 33/36] print bool --- lua/orgmode/agenda/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 2139273e5..e7b137ef2 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -33,7 +33,7 @@ local function sort_agenda_items(agenda_items) print("headline date") utils.tprint(a.headline_date) print("headline date.date_only") - utils.tprint(a.headline_date.date_only) + print(a.headline_date.date_only) if not a.headline_date.date_only and not b.headline_date.date_only then if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then From baf1dc113c306f8190265c30482c80036d04a894 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Mon, 29 Nov 2021 12:14:00 +0100 Subject: [PATCH 34/36] no printing --- lua/orgmode/agenda/init.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index e7b137ef2..33972d235 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -30,10 +30,10 @@ local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) -- sort items with a time of day in order of scheduling - print("headline date") - utils.tprint(a.headline_date) - print("headline date.date_only") - print(a.headline_date.date_only) + -- print("headline date") + -- utils.tprint(a.headline_date) + -- print("headline date.date_only") + -- print(a.headline_date.date_only) if not a.headline_date.date_only and not b.headline_date.date_only then if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then From a7b3987f5cce75d39cbe5ea35d11e7d61a326dc0 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Fri, 3 Dec 2021 21:57:09 +0100 Subject: [PATCH 35/36] added deadline logic to sort --- lua/orgmode/agenda/init.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 33972d235..5f0f7f845 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -30,10 +30,6 @@ local function sort_agenda_items(agenda_items) table.sort(agenda_items, function(a, b) -- sort items with a time of day in order of scheduling - -- print("headline date") - -- utils.tprint(a.headline_date) - -- print("headline date.date_only") - -- print(a.headline_date.date_only) if not a.headline_date.date_only and not b.headline_date.date_only then if a.is_today and a.is_same_day then if b.is_today and b.is_same_day then @@ -51,7 +47,7 @@ local function sort_agenda_items(agenda_items) end -- sort items with a time of day before ones that have a date only - -- seems that the logic is reverse somehow ... + -- true means sort a before b if not a.headline_date.date_only and b.headline_date.date_only then return true end @@ -73,12 +69,18 @@ local function sort_agenda_items(agenda_items) return a.headline:get_priority_sort_value() > b.headline:get_priority_sort_value() end - -- if same priority sort by overdue - if a.headline:has_priority() and b.headline:has_priority() then - return a.headline_date:is_before(b.headline_date) + -- if same priority sort by deadline + if a.headline_date:is_deadline() and not b.headline_date:is_deadline() then + return true + elseif not a.headline_date:is_deadline() and b.headline_date:is_deadline() then + return false + else + -- either both are deadlines or both are not deadlines + -- overdue deadline and overdue schedule > deadline today and schedule today + return a.headline_date:is_before(b.headline_date) end - -- I don't get these ones - they feel reverse ... + -- these are probably upcoming events ... if a.is_in_date_range and not b.is_in_date_range then return false end From 3ef9f81d2b57135d26ac42c6e2665ede0f13c2e2 Mon Sep 17 00:00:00 2001 From: Branislav Gerazov Date: Fri, 3 Dec 2021 22:49:59 +0100 Subject: [PATCH 36/36] overdue > deadline --- lua/orgmode/agenda/init.lua | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 5f0f7f845..37358baf0 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -69,26 +69,35 @@ local function sort_agenda_items(agenda_items) return a.headline:get_priority_sort_value() > b.headline:get_priority_sort_value() end - -- if same priority sort by deadline - if a.headline_date:is_deadline() and not b.headline_date:is_deadline() then - return true - elseif not a.headline_date:is_deadline() and b.headline_date:is_deadline() then - return false - else - -- either both are deadlines or both are not deadlines - -- overdue deadline and overdue schedule > deadline today and schedule today + -- overdue > today > future + if a.is_today and a.is_same_day then + if b.is_today and not b.is_same_day then + return a.headline_date:is_before(b.headline_date) + end + end + + if b.is_today and b.is_same_day then + if a.is_today and not a.is_same_day then return a.headline_date:is_before(b.headline_date) + end end - -- these are probably upcoming events ... if a.is_in_date_range and not b.is_in_date_range then return false end - if not a.is_in_date_range and b.is_in_date_range then return true end + -- if same due sort by deadline + if a.headline_date:is_deadline() and not b.headline_date:is_deadline() then + return true + elseif not a.headline_date:is_deadline() and b.headline_date:is_deadline() then + return false + -- either both are deadlines or both are not deadlines + -- overdue deadline and overdue schedule > deadline today and schedule today + end + return a.headline_date:is_before(b.headline_date) end) return agenda_items