File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change 11local OrgApi = require (' orgmode.api' )
2+ local OrgAgendaApi = require (' orgmode.api.agenda' )
23
34local M = {}
45
8990--- In case of nested sections, it is the closest headline within the headline
9091--- tree.
9192---
92- --- The precondition to run this function successfully is, that the cursor is
93- --- placed in an orgfile when the function is called.
93+ --- Works in both org files and agenda views:
94+ --- - For org files: Uses treesitter parser to search the tree
95+ --- - For agenda views: Uses the agenda API to get the headline at cursor
9496function M .get_closest_headline ()
95- return OrgApi .current ():get_closest_headline ()
97+ -- Handle different buffer types explicitly
98+ if vim .bo .filetype == ' org' then
99+ return OrgApi .current ():get_closest_headline ()
100+ elseif vim .bo .filetype == ' orgagenda' then
101+ return OrgAgendaApi .get_headline_at_cursor ()
102+ end
103+
104+ -- Not in org or agenda buffer
105+ return nil
96106end
97107
98108--- Get the API headline object for a given filename and line number
@@ -153,7 +163,7 @@ function M.get_link_destination(entry, opts)
153163 if entry .value .headline and opts .original_file and entry .filename == opts .original_file then
154164 return M .get_intra_file_link (entry )
155165 end
156-
166+
157167 -- Use inter-file format for everything else
158168 return M .get_inter_file_link (entry )
159169end
Original file line number Diff line number Diff line change @@ -15,6 +15,16 @@ return function(opts)
1515 }, ' headlines' )
1616
1717 local closest_headline = org .get_closest_headline ()
18+
19+ if not closest_headline then
20+ local filetype = vim .bo .filetype
21+ if filetype == ' org' then
22+ vim .notify (' No headline found at cursor position in org file' , vim .log .levels .WARN )
23+ else
24+ vim .notify (' No headline found at cursor position. Make sure cursor is on a valid agenda item or org headline.' , vim .log .levels .WARN )
25+ end
26+ return
27+ end
1828
1929 pickers
2030 .new (opts , {
You can’t perform that action at this time.
0 commit comments