Skip to content

Commit d3980a5

Browse files
authored
Agenda help improvements (#463)
closes #445
1 parent fc9bb0f commit d3980a5

File tree

2 files changed

+78
-43
lines changed

2 files changed

+78
-43
lines changed

lua/orgmode/agenda/init.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,35 @@ function Agenda:new(opts)
3333
end
3434

3535
---@param View table
36+
---@param type string
3637
---@param opts? table
37-
function Agenda:open_agenda_view(View, opts)
38+
function Agenda:open_agenda_view(View, type, opts)
3839
self:open_window()
3940
self.win_width = utils.winwidth()
4041
local view = View:new(vim.tbl_deep_extend('force', opts or {}, {
4142
filters = self.filters,
4243
win_width = self.win_width,
4344
})):build()
4445
self.views = { view }
46+
vim.b.org_agenda_type = type
4547
return self:_render()
4648
end
4749

4850
function Agenda:agenda(opts)
49-
self:open_agenda_view(AgendaView, opts)
51+
self:open_agenda_view(AgendaView, 'agenda', opts)
5052
end
5153

5254
-- TODO: Introduce searching ALL/DONE
5355
function Agenda:todos()
54-
self:open_agenda_view(AgendaTodosView)
56+
self:open_agenda_view(AgendaTodosView, 'todos')
5557
end
5658

5759
function Agenda:search()
58-
self:open_agenda_view(AgendaSearchView)
60+
self:open_agenda_view(AgendaSearchView, 'search')
5961
end
6062

6163
function Agenda:tags(opts)
62-
self:open_agenda_view(AgendaTagsView, opts)
64+
self:open_agenda_view(AgendaTagsView, 'tags', opts)
6365
end
6466

6567
function Agenda:tags_todo()

lua/orgmode/objects/help.lua

Lines changed: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,41 @@ local helps = {
5757
{ key = 'org_toggle_heading', description = 'Toggle current line to headline and vice versa' },
5858
},
5959
orgagenda = {
60-
{ key = 'org_agenda_later', description = 'Go forward one span' },
61-
{ key = 'org_agenda_earlier', description = 'Go backward one span' },
62-
{ key = 'org_agenda_goto_today', description = "Go to today's span" },
63-
{ key = 'org_agenda_goto_date', description = 'Jump to specific date' },
64-
{ key = 'org_agenda_day_view', description = 'Show day view' },
65-
{ key = 'org_agenda_week_view', description = 'Show week view' },
66-
{ key = 'org_agenda_month_view', description = 'Show month view' },
67-
{ key = 'org_agenda_year_view', description = 'Show year view' },
68-
{ key = 'org_agenda_switch_to', description = 'Open in current window' },
69-
{ key = 'org_agenda_goto', description = 'Open in another window' },
70-
{ key = 'org_agenda_redo', description = 'Reload org files and redraw' },
71-
{ key = 'org_agenda_todo', description = 'Change TODO state of an item' },
72-
{ key = 'org_agenda_clock_in', description = 'Clock in item under cursor' },
73-
{ key = 'org_agenda_clock_out', description = 'Clock out currently active clocked item' },
74-
{ key = 'org_agenda_clock_cancel', description = 'Cancel clocking on currently active clocked item' },
75-
{ key = 'org_agenda_clock_goto', description = 'Jump to currently active clock item' },
76-
{ key = 'org_agenda_set_effort', description = 'Set effort estimate for item under cursor' },
77-
{ key = 'org_agenda_clockreport_mode', description = 'Toggle clock report for current agenda time range' },
78-
{
79-
key = 'org_agenda_filter',
80-
description = 'Open prompt that allows filtering by category, tags and title(vim regex)',
60+
agenda_specific = {
61+
{ key = 'org_agenda_later', description = 'Go forward one span' },
62+
{ key = 'org_agenda_earlier', description = 'Go backward one span' },
63+
{ key = 'org_agenda_goto_today', description = "Go to today's span" },
64+
{ key = 'org_agenda_goto_date', description = 'Jump to specific date' },
65+
{ key = 'org_agenda_day_view', description = 'Show day view' },
66+
{ key = 'org_agenda_week_view', description = 'Show week view' },
67+
{ key = 'org_agenda_month_view', description = 'Show month view' },
68+
{ key = 'org_agenda_year_view', description = 'Show year view' },
69+
},
70+
generic = {
71+
{ key = 'org_agenda_switch_to', description = 'Open in current window' },
72+
{ key = 'org_agenda_goto', description = 'Open in another window' },
73+
{ key = 'org_agenda_redo', description = 'Reload org files and redraw' },
74+
{ key = 'org_agenda_todo', description = 'Change TODO state of an item' },
75+
{ key = 'org_agenda_clock_in', description = 'Clock in item under cursor' },
76+
{ key = 'org_agenda_clock_out', description = 'Clock out currently active clocked item' },
77+
{ key = 'org_agenda_clock_cancel', description = 'Cancel clocking on currently active clocked item' },
78+
{ key = 'org_agenda_clock_goto', description = 'Jump to currently active clock item' },
79+
{ key = 'org_agenda_set_effort', description = 'Set effort estimate for item under cursor' },
80+
{ key = 'org_agenda_clockreport_mode', description = 'Toggle clock report for current agenda time range' },
81+
{
82+
key = 'org_agenda_filter',
83+
description = 'Open prompt that allows filtering by category, tags and title(vim regex)',
84+
},
85+
{ key = 'org_agenda_priority', description = 'Set priority for current item' },
86+
{ key = 'org_agenda_priority_up', description = 'Increase priority for current item' },
87+
{ key = 'org_agenda_priority_down', description = 'Decrease priority for current item' },
88+
{ key = 'org_agenda_toggle_archive_tag', description = 'Toggle "ARCHIVE" tag on current headline' },
89+
{ key = 'org_agenda_set_tags', description = 'Change tags of current headline' },
90+
{ key = 'org_agenda_deadline', description = 'Insert/Update deadline date on current headline' },
91+
{ key = 'org_agenda_schedule', description = 'Insert/Update scheduled date on current headline' },
92+
{ key = 'org_agenda_quit', description = 'Close agenda' },
93+
{ key = 'org_agenda_show_help', description = 'Show this help' },
8194
},
82-
{ key = 'org_agenda_priority', description = 'Set priority for current item' },
83-
{ key = 'org_agenda_priority_up', description = 'Increase priority for current item' },
84-
{ key = 'org_agenda_priority_down', description = 'Decrease priority for current item' },
85-
{ key = 'org_agenda_toggle_archive_tag', description = 'Toggle "ARCHIVE" tag on current headline' },
86-
{ key = 'org_agenda_set_tags', description = 'Change tags of current headline' },
87-
{ key = 'org_agenda_deadline', description = 'Insert/Update deadline date on current headline' },
88-
{ key = 'org_agenda_schedule', description = 'Insert/Update scheduled date on current headline' },
89-
{ key = 'org_agenda_quit', description = 'Close agenda' },
90-
{ key = 'org_agenda_show_help', description = 'Show this help' },
9195
},
9296
capture = {
9397
{ key = 'org_capture_finalize', description = 'Save to default notes file and close the window' },
@@ -165,7 +169,10 @@ function Help._prepare_orgcapture(mappings, max_height)
165169
maps = table.concat(maps, ', ')
166170
end
167171

168-
table.insert(content, string.format(' `%-12s` - %s', maps, item.description))
172+
table.insert(
173+
content,
174+
string.format(' `%-12s` - %s', string.gsub(maps, '<prefix>', mappings.prefix), item.description)
175+
)
169176
end
170177

171178
table.insert(content, ' __Org__')
@@ -186,7 +193,10 @@ function Help._prepare_orgnote(mappings, max_height)
186193
maps = table.concat(maps, ', ')
187194
end
188195

189-
table.insert(content, string.format(' `%-12s` - %s', maps, item.description))
196+
table.insert(
197+
content,
198+
string.format(' `%-12s` - %s', string.gsub(maps, '<prefix>', mappings.prefix), item.description)
199+
)
190200
end
191201

192202
table.insert(content, ' __Org__')
@@ -195,19 +205,34 @@ function Help._prepare_orgnote(mappings, max_height)
195205
end
196206

197207
function Help._prepare_orgagenda(mappings, max_height)
208+
local agenda_mappings = vim.deepcopy(helps.orgagenda.generic)
209+
local height = #helps.orgagenda.generic
210+
211+
local agenda_type_text = ''
212+
if vim.b.org_agenda_type == 'agenda' then
213+
agenda_mappings = utils.concat(vim.deepcopy(helps.orgagenda.agenda_specific), agenda_mappings)
214+
height = height + #helps.orgagenda.agenda_specific
215+
else
216+
agenda_type_text = ' ' .. vim.b.org_agenda_type
217+
end
218+
198219
local scroll_more_text = ''
199-
if #helps.orgagenda > max_height then
220+
if height > max_height then
200221
scroll_more_text = ' (Scroll down for more)'
201222
end
202223

203-
local content = { string.format(' **Orgmode mappings - Agenda%s:**', scroll_more_text), '' }
204-
for _, item in ipairs(helps.orgagenda) do
224+
local content = { string.format(' **Orgmode mappings - Agenda%s%s:**', agenda_type_text, scroll_more_text), '' }
225+
226+
for _, item in ipairs(agenda_mappings) do
205227
local maps = mappings.agenda[item.key]
206228
if type(maps) == 'table' then
207229
maps = table.concat(maps, ', ')
208230
end
209231

210-
table.insert(content, string.format(' `%-12s` - %s', maps, item.description))
232+
table.insert(
233+
content,
234+
string.format(' `%-12s` - %s', string.gsub(maps, '<prefix>', mappings.prefix), item.description)
235+
)
211236
end
212237

213238
table.insert(content, '')
@@ -230,7 +255,10 @@ function Help._prepare_edit_src(mappings, max_height)
230255
maps = table.concat(maps, ', ')
231256
end
232257

233-
table.insert(content, string.format(' `%-12s` - %s', maps, item.description))
258+
table.insert(
259+
content,
260+
string.format(' `%-12s` - %s', string.gsub(maps, '<prefix>', mappings.prefix), item.description)
261+
)
234262
end
235263

236264
return content, true
@@ -261,9 +289,14 @@ function Help.prepare_content(opts)
261289
maps = table.concat(maps, ', ')
262290
end
263291

264-
table.insert(content, string.format(' `%-12s` - %s', maps, item.description))
292+
table.insert(
293+
content,
294+
string.format(' `%-12s` - %s', string.gsub(maps, '<prefix>', mappings.prefix), item.description)
295+
)
265296
end
266297

298+
table.insert(content, ' __Text Objects__')
299+
267300
for _, item in ipairs(helps.text_objects) do
268301
local maps = mappings.text_objects[item.key]
269302
table.insert(content, string.format(' `%-12s` - %s', maps, item.description))

0 commit comments

Comments
 (0)