@@ -162,32 +162,8 @@ function Agenda:_build_custom_commands()
162
162
end
163
163
164
164
--- @private
165
- --- @return number buffer number
166
- function Agenda :_open_window ()
167
- -- if an agenda window is already open, return it
168
- for _ , win in ipairs (vim .api .nvim_list_wins ()) do
169
- local buf = vim .api .nvim_win_get_buf (win )
170
- local ft = vim .api .nvim_get_option_value (' filetype' , {
171
- buf = buf ,
172
- })
173
- if ft == ' orgagenda' then
174
- vim .bo [buf ].modifiable = true
175
- colors .highlight ({}, true , buf )
176
- vim .api .nvim_buf_set_lines (buf , 0 , - 1 , true , {})
177
- return buf
178
- end
179
- end
180
-
181
- utils .open_window (' orgagenda' , math.max (34 , config .org_agenda_min_height ), config .win_split_mode , config .win_border )
182
-
183
- vim .cmd ([[ setf orgagenda]] )
184
- vim .cmd ([[ setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap nospell]] )
185
- vim .w .org_window_pos = vim .fn .win_screenpos (0 )
186
- config :setup_mappings (' agenda' , vim .api .nvim_get_current_buf ())
187
- return vim .fn .bufnr ()
188
- end
189
-
190
- function Agenda :prompt ()
165
+ --- @return OrgMenu
166
+ function Agenda :_build_menu ()
191
167
local menu = Menu :new ({
192
168
title = ' Press key for an agenda command' ,
193
169
prompt = ' Press key for an agenda command' ,
@@ -243,6 +219,47 @@ function Agenda:prompt()
243
219
menu :add_option ({ label = ' Quit' , key = ' q' })
244
220
menu :add_separator ({ icon = ' ' , length = 1 })
245
221
222
+ return menu
223
+ end
224
+
225
+ --- @private
226
+ --- @return number buffer number
227
+ function Agenda :_open_window ()
228
+ -- if an agenda window is already open, return it
229
+ for _ , win in ipairs (vim .api .nvim_list_wins ()) do
230
+ local buf = vim .api .nvim_win_get_buf (win )
231
+ local ft = vim .api .nvim_get_option_value (' filetype' , {
232
+ buf = buf ,
233
+ })
234
+ if ft == ' orgagenda' then
235
+ vim .bo [buf ].modifiable = true
236
+ colors .highlight ({}, true , buf )
237
+ vim .api .nvim_buf_set_lines (buf , 0 , - 1 , true , {})
238
+ return buf
239
+ end
240
+ end
241
+
242
+ utils .open_window (' orgagenda' , math.max (34 , config .org_agenda_min_height ), config .win_split_mode , config .win_border )
243
+
244
+ vim .cmd ([[ setf orgagenda]] )
245
+ vim .cmd ([[ setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap nospell]] )
246
+ vim .w .org_window_pos = vim .fn .win_screenpos (0 )
247
+ config :setup_mappings (' agenda' , vim .api .nvim_get_current_buf ())
248
+ return vim .fn .bufnr ()
249
+ end
250
+
251
+ --- @param key string
252
+ function Agenda :open_by_key (key )
253
+ local menu = self :_build_menu ()
254
+ local item = menu :get_entry_by_key (key )
255
+ if not item then
256
+ return utils .echo_error (' No agenda view with key ' .. key )
257
+ end
258
+ return item .action ()
259
+ end
260
+
261
+ function Agenda :prompt ()
262
+ local menu = self :_build_menu ()
246
263
return menu :open ()
247
264
end
248
265
0 commit comments