Skip to content

Commit 3cbc864

Browse files
committed
docs: document org_agenda_prefix_format
1 parent e26dcf3 commit 3cbc864

6 files changed

Lines changed: 132 additions & 7 deletions

File tree

doc/orgmode.txt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,59 @@ Separator used to separate multiple agenda views generated by
845845
`@org.agenda.separator` hl group.
846846

847847

848+
org_agenda_prefix_format *orgmode-org_agenda_prefix_format*
849+
850+
- Type: `{ agenda?: string, todo?: string, tags?: string, search?: string,
851+
tags_todo?: string }`
852+
- Default:
853+
>lua
854+
{
855+
agenda = ' %-12:c%?t% s',
856+
todo = ' %-12:c',
857+
tags = ' %-12:c',
858+
tags_todo = ' %-12:c',
859+
search = ' %-12:c',
860+
}
861+
<
862+
863+
Format for the prefix of each line in the agenda view. The format string can
864+
contain placeholders that will be replaced with actual values. Format of the
865+
placeholder: `%[specifiers][variable]` or `%[specifiers](lua expression)`.
866+
867+
**Specifiers:**
868+
869+
- `-` - Left align the value (default is right align)
870+
- `[number]` - Set fixed width for the value
871+
- `?` - Optional placeholder. If the value is empty, the placeholder (and surrounding spaces) will be omitted.
872+
873+
**Variables:**
874+
875+
- `c` - Category of the headline
876+
- `:c` - Category of the headline followed by a colon
877+
- `s` - Planning info (Deadline, Scheduled, etc.)
878+
- `t` - Time range (e.g. 10:00-11:00)
879+
- `T` - Tags
880+
- `e` - Effort property
881+
- `l` - Headline level
882+
- `b` - Breadcrumbs (parent headline titles separated by `->`)
883+
884+
**Lua expressions:** Anything inside `%()` will be evaluated as a Lua
885+
expression. The expression has access to following variables:
886+
887+
- `headline` - |orgmode-orgheadline| object
888+
- `item` - |orgmode-orgagendaitem| object (only in `agenda` view)
889+
- `metadata` - Metadata table containing `category_length`
890+
891+
Example:
892+
893+
>lua
894+
org_agenda_prefix_format = {
895+
agenda = ' %-12:c %?t %s ',
896+
todo = ' %-12:c %(headline:get_property("PRIORITY") or "C") '
897+
}
898+
<
899+
900+
848901
org_agenda_remove_tags *orgmode-org_agenda_remove_tags*
849902

850903
- Type: `boolean`

docs/configuration.org

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,56 @@ Separator used to separate multiple agenda views generated by
788788
[[#org_agenda_custom_commands][org_agenda_custom_commands]].
789789
To change the highlight, override =@org.agenda.separator= hl group.
790790

791+
*** org_agenda_prefix_format
792+
:PROPERTIES:
793+
:CUSTOM_ID: org_agenda_prefix_format
794+
:END:
795+
- Type: ={ agenda?: string, todo?: string, tags?: string, search?: string, tags_todo?: string }=
796+
- Default:
797+
#+begin_src lua
798+
{
799+
agenda = ' %-12:c%?t% s',
800+
todo = ' %-12:c',
801+
tags = ' %-12:c',
802+
tags_todo = ' %-12:c',
803+
search = ' %-12:c',
804+
}
805+
#+end_src
806+
807+
Format for the prefix of each line in the agenda view.
808+
The format string can contain placeholders that will be replaced with actual values.
809+
Format of the placeholder: =%[specifiers][variable]= or =%[specifiers](lua expression)=.
810+
811+
*Specifiers:*
812+
- =-= - Left align the value (default is right align)
813+
- =[number]= - Set fixed width for the value
814+
- =?= - Optional placeholder. If the value is empty, the placeholder (and surrounding spaces) will be omitted.
815+
816+
*Variables:*
817+
- =c= - Category of the headline
818+
- =:c= - Category of the headline followed by a colon
819+
- =s= - Planning info (Deadline, Scheduled, etc.)
820+
- =t= - Time range (e.g. 10:00-11:00)
821+
- =T= - Tags
822+
- =e= - Effort property
823+
- =l= - Headline level
824+
- =b= - Breadcrumbs (parent headline titles separated by =->=)
825+
826+
*Lua expressions:*
827+
Anything inside =%()= will be evaluated as a Lua expression.
828+
The expression has access to following variables:
829+
- =headline= - [[#org-headline][OrgHeadline]] object
830+
- =item= - [[#org-agenda-item][OrgAgendaItem]] object (only in =agenda= view)
831+
- =metadata= - Metadata table containing =category_length=
832+
833+
Example:
834+
#+begin_src lua
835+
org_agenda_prefix_format = {
836+
agenda = ' %-12:c %?t %s ',
837+
todo = ' %-12:c %(headline:get_property("PRIORITY") or "C") '
838+
}
839+
#+end_src
840+
791841
*** org_agenda_remove_tags
792842
:PROPERTIES:
793843
:CUSTOM_ID: org_agenda_remove_tags

lua/orgmode/agenda/agenda_item.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ function AgendaItem:_generate_marker()
189189
return ''
190190
end
191191

192-
193192
function AgendaItem:_generate_label()
194193
local include_time = self.time ~= ''
195194
if (self.headline_date:is_deadline() or self.headline_date:is_scheduled()) and not self.is_same_day then

lua/orgmode/agenda/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ function Agenda:_build_custom_commands()
156156
opts_by_type[opts.type].category_filter = opts.org_agenda_category_filter_preset
157157
opts_by_type[opts.type].highlighter = self.highlighter
158158
opts_by_type[opts.type].remove_tags = utils.if_nil(opts.org_agenda_remove_tags, parent_opts.org_agenda_remove_tags)
159-
opts_by_type[opts.type].org_agenda_prefix_format = utils.if_nil(opts.org_agenda_prefix_format, parent_opts.org_agenda_prefix_format)
159+
opts_by_type[opts.type].org_agenda_prefix_format =
160+
utils.if_nil(opts.org_agenda_prefix_format, parent_opts.org_agenda_prefix_format)
160161
opts_by_type[opts.type].id = id
161162

162163
return opts_by_type[opts.type]

lua/orgmode/agenda/types/todo.lua

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,14 @@ function OrgAgendaTodosType:_get_header()
108108
end
109109

110110
---@param bufnr? number
111-
function OrgAgendaTodosType:render(bufnr)
111+
---@param current_line? number
112+
function OrgAgendaTodosType:render(bufnr, current_line)
112113
self.bufnr = bufnr or 0
114+
local was_line_in_view = true
115+
if self.view then
116+
was_line_in_view = self.view:is_in_range(current_line)
117+
end
118+
113119
local headlines, category_length = self:_get_headlines()
114120

115121
local prefix_formats = self.org_agenda_prefix_format or config.org_agenda_prefix_format
@@ -141,9 +147,25 @@ function OrgAgendaTodosType:render(bufnr)
141147
end
142148

143149
self.view = agendaView:render()
150+
if was_line_in_view then
151+
self:_jump_to_item(current_line)
152+
end
144153
return self.view
145154
end
146155

156+
---@private
157+
function OrgAgendaTodosType:_jump_to_item(line)
158+
local agenda_line = self:get_line(line)
159+
if not agenda_line or not agenda_line.headline then
160+
return
161+
end
162+
for _, l in ipairs(self.view.lines) do
163+
if l.headline and l.headline:id_get_or_create() == agenda_line.headline:id_get_or_create() then
164+
return vim.fn.cursor({ l.line_nr, 0 })
165+
end
166+
end
167+
end
168+
147169
---@private
148170
---@param headline OrgHeadline
149171
---@param metadata table<string, any>

tests/plenary/agenda/formatter_spec.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('Agenda formatter', function()
1818
local headline = generate_headline(string.format('<%s>', today:to_string()))
1919
local agenda_item = AgendaItem:new(headline:get_all_dates()[1], headline, today)
2020
local metadata = { category_length = 10 }
21-
21+
2222
local format = '%c'
2323
local result = Formatter.format(format, agenda_item, metadata)
2424
assert.are.same('agenda_test', result)
@@ -86,16 +86,16 @@ describe('Agenda formatter', function()
8686
local headline = generate_headline(string.format('<%s>', today:to_string()))
8787
local agenda_item = AgendaItem:new(headline:get_all_dates()[1], headline, today)
8888
local metadata = { category_length = 10 }
89-
89+
9090
-- Define a global function for testing
9191
_G.test_prefix = function()
92-
return "SHORT"
92+
return 'SHORT'
9393
end
9494

9595
local format = '%(test_prefix())'
9696
local result = Formatter.format(format, agenda_item, metadata)
9797
assert.are.same('SHORT', result)
98-
98+
9999
-- Test with width and alignment
100100
format = '%10(test_prefix())'
101101
result = Formatter.format(format, agenda_item, metadata)

0 commit comments

Comments
 (0)