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 1
1
local OrgApi = require (' orgmode.api' )
2
+ local OrgAgendaApi = require (' orgmode.api.agenda' )
2
3
3
4
local M = {}
4
5
89
90
--- In case of nested sections, it is the closest headline within the headline
90
91
--- tree.
91
92
---
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
94
96
function 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
96
106
end
97
107
98
108
--- Get the API headline object for a given filename and line number
@@ -153,7 +163,7 @@ function M.get_link_destination(entry, opts)
153
163
if entry .value .headline and opts .original_file and entry .filename == opts .original_file then
154
164
return M .get_intra_file_link (entry )
155
165
end
156
-
166
+
157
167
-- Use inter-file format for everything else
158
168
return M .get_inter_file_link (entry )
159
169
end
Original file line number Diff line number Diff line change @@ -15,6 +15,16 @@ return function(opts)
15
15
}, ' headlines' )
16
16
17
17
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
18
28
19
29
pickers
20
30
.new (opts , {
You can’t perform that action at this time.
0 commit comments