File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -102,4 +102,22 @@ function OrgAgenda.open_by_key(key)
102102 return orgmode .agenda :open_by_key (key )
103103end
104104
105+ --- Get the headline at the cursor position in the agenda view
106+ --- @return OrgApiHeadline | nil
107+ function OrgAgenda .get_headline_at_cursor ()
108+ local line_nr = vim .fn .line (' .' )
109+ local agenda_views = orgmode .agenda .views
110+
111+ for _ , view in ipairs (agenda_views ) do
112+ local agenda_line = view :get_line (line_nr )
113+ if agenda_line then
114+ local headline = agenda_line .headline
115+ if headline then
116+ local file = require (' orgmode.api' ).load (headline .file .filename )
117+ return file :get_headline_on_line (headline :get_range ().start_line )
118+ end
119+ end
120+ end
121+ end
122+
105123return OrgAgenda
Original file line number Diff line number Diff line change @@ -93,6 +93,14 @@ function OrgFile:get_closest_headline(cursor)
9393 return nil
9494end
9595
96+ --- @param line_number number
97+ --- @return OrgApiHeadline | nil
98+ function OrgFile :get_headline_on_line (line_number )
99+ return vim .tbl_filter (function (headline )
100+ return headline .position .start_line == line_number
101+ end , self .headlines )[1 ]
102+ end
103+
96104--- Get a link destination as string
97105---
98106--- Depending if org_id_link_to_org_use_id is set the format is
You can’t perform that action at this time.
0 commit comments