From 068180bbb97b7d3dee5c7b4947eaba9f43322e61 Mon Sep 17 00:00:00 2001 From: Fredrik Lanker Date: Thu, 16 Apr 2026 18:53:02 +0200 Subject: [PATCH] feat(agenda): customizable scheduled/deadline prefix Adds org_agenda_scheduled_leaders and org_agenda_deadline_leaders for configuring the texts preceding scheduled and deadline items in the agenda. --- doc/orgmode.txt | 25 +++++++++++++++++++++++++ docs/configuration.org | 25 +++++++++++++++++++++++++ lua/orgmode/agenda/agenda_item.lua | 13 +++++++++---- lua/orgmode/config/_meta.lua | 2 ++ lua/orgmode/config/defaults.lua | 2 ++ 5 files changed, 63 insertions(+), 4 deletions(-) diff --git a/doc/orgmode.txt b/doc/orgmode.txt index 7508b63d4..960c93d4a 100644 --- a/doc/orgmode.txt +++ b/doc/orgmode.txt @@ -1183,6 +1183,31 @@ Additional files to search from agenda search prompt. Currently it accepts only a single value: `agenda-archives`. Example value: `{'agenda-archives'}` +org_agenda_scheduled_leaders *orgmode-org_agenda_scheduled_leaders* + +- Type: `string[]` +- Default: `{'Scheduled:', 'Sched. %dx:'}` + +Text preceding scheduled items in the agenda view. This is a list with two +strings. The first applies when the item is scheduled on the current day. The +second applies when it has been scheduled previously, it may contain a %d +indicating that this is the nth time that this item is scheduled, due to +automatic rescheduling of unfinished items for the following day. So this +number is one larger than the number of days that passed since this item was +scheduled first. + + +org_agenda_deadline_leaders *orgmode-org_agenda_deadline_leaders* + +- Type: `string[]` +- Default: `{'Deadline:', 'In %d d.:', "%d d. ago"},` + +Text preceding deadline items in the agenda view. This is a list with three +strings. The first applies when the item has its deadline on the current day. +The second applies when the deadline is in the future, the third one when it is +in the past. The strings may contain %d to capture the number of days. + + CALENDAR SETTINGS *orgmode-configuration-calendar-settings* Adjust behavior of the calendar modal (ex: diff --git a/docs/configuration.org b/docs/configuration.org index da4ba9c4b..780fa08db 100644 --- a/docs/configuration.org +++ b/docs/configuration.org @@ -1120,6 +1120,31 @@ Additional files to search from agenda search prompt. Currently it accepts only a single value: =agenda-archives=. Example value: ={'agenda-archives'}= +*** org_agenda_scheduled_leaders +:PROPERTIES: +:CUSTOM_ID: org_agenda_scheduled_leaders +:END: +- Type: =string[]= +- Default: ={'Scheduled:', 'Sched. %dx:'}= +Text preceding scheduled items in the agenda view. This is a list with two +strings. The first applies when the item is scheduled on the current day. The +second applies when it has been scheduled previously, it may contain a %d +indicating that this is the nth time that this item is scheduled, due to +automatic rescheduling of unfinished items for the following day. So this +number is one larger than the number of days that passed since this item was +scheduled first. + +*** org_agenda_deadline_leaders +:PROPERTIES: +:CUSTOM_ID: org_agenda_deadline_leaders +:END: +- Type: =string[]= +- Default: ={'Deadline:', 'In %d d.:', "%d d. ago"},= +Text preceding deadline items in the agenda view. This is a list with three +strings. The first applies when the item has its deadline on the current day. +The second applies when the deadline is in the future, the third one when it is +in the past. The strings may contain %d to capture the number of days. + ** Calendar settings :PROPERTIES: :CUSTOM_ID: calendar-settings diff --git a/lua/orgmode/agenda/agenda_item.lua b/lua/orgmode/agenda/agenda_item.lua index b68c4f493..db55484ea 100644 --- a/lua/orgmode/agenda/agenda_item.lua +++ b/lua/orgmode/agenda/agenda_item.lua @@ -157,19 +157,24 @@ function AgendaItem:_generate_label() local time = self.headline_date:has_time() and add_padding(self:_format_time(self.headline_date)) or '' if self.headline_date:is_deadline() then if self.is_same_day then - return time .. 'Deadline:' + return time .. config.org_agenda_deadline_leaders[1] + end + local diff = self.date:diff(self.headline_date) + if diff < 0 then + return config.org_agenda_deadline_leaders[2]:gsub('%%d', math.abs(diff)) + else + return config.org_agenda_deadline_leaders[3]:gsub('%%d', math.abs(diff)) end - return self.headline_date:humanize(self.date) .. ':' end if self.headline_date:is_scheduled() then if self.is_same_day then - return time .. 'Scheduled:' + return time .. config.org_agenda_scheduled_leaders[1] end local diff = math.abs(self.date:diff(self.headline_date)) - return 'Sched. ' .. diff .. 'x:' + return config.org_agenda_scheduled_leaders[2]:gsub('%%d', diff) end if self.headline_date.is_date_range_start then diff --git a/lua/orgmode/config/_meta.lua b/lua/orgmode/config/_meta.lua index edd4a828b..dad163537 100644 --- a/lua/orgmode/config/_meta.lua +++ b/lua/orgmode/config/_meta.lua @@ -220,6 +220,8 @@ ---@field org_agenda_remove_tags? boolean If true, tags will be removed from the all agenda views. Default: false ---@field org_agenda_use_time_grid? boolean If true, Render time grid in agenda as set by org_agenda_time_grid. Default: true ---@field org_agenda_show_future_repeats? boolean | 'next' If true, show all future repeats. If `next`, show only next repeat. If false, do hnot show any repeats. Default: true +---@field org_agenda_scheduled_leaders? string[] Text preceding scheduled items in the agenda view. This is a list with two strings: the first applies when the item is scheduled on the current day, the second applies when it has been scheduled previously. Default: { 'Scheduled:', 'Sched. %dx:' } +---@field org_agenda_deadline_leaders? string[] Text preceding deadline items in the agenda view. This is a list with three strings. The first applies when the item has its deadline on the current day. The second applies when the deadline is in the future, the third one when it is in the past. Default: {'Deadline:', 'In %d d.:', "%d d. ago"} ---@field org_agenda_time_grid? OrgAgendaTimeGridOpts Agenda time grid configuration. Default: { type = { 'daily', 'today', 'require-timed' }, times = { 800, 1000, 1200, 1400, 1600, 1800, 2000 }, time_separator = '┄┄┄┄┄', time_label = '┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄' } ---@field org_agenda_current_time_string? string String to indicate current time on the time grid. Default: '<- now -----------------------------------------------' ---@field org_priority_highest? string | number Highest priority level. Default: 'A' diff --git a/lua/orgmode/config/defaults.lua b/lua/orgmode/config/defaults.lua index 2a5ebd64f..e6bac1300 100644 --- a/lua/orgmode/config/defaults.lua +++ b/lua/orgmode/config/defaults.lua @@ -43,6 +43,8 @@ local DefaultConfig = { org_agenda_current_time_string = '<- now -----------------------------------------------', org_agenda_use_time_grid = true, org_agenda_show_future_repeats = true, + org_agenda_scheduled_leaders = { 'Scheduled:', 'Sched. %dx:' }, + org_agenda_deadline_leaders = { 'Deadline:', 'In %d d.:', '%d d. ago:' }, org_priority_highest = 'A', org_priority_default = 'B', org_priority_lowest = 'C',