You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extend API to get links to headline and org file (#768)
* feat(api): Extend API to get links
Considers id links, if org-id-link-to-org-use-id is set.
Creates ids on file and headline level if needed.
* chore: Remove stale require
* chore: tiny refactoring to align similar methods
Adapt the style of get_link_to_headline to new get_link_to_file
- avoid empty declaration of `id`
- move initialization of `path` close to it's usage
* refactor: make get_link member functions
Simplify the code by providing member functions on org.api.file and
org.api.headline.
* fix: handle unloaded buffers
---------
Co-authored-by: Sebastian Flügge <[email protected]>
Copy file name to clipboardExpand all lines: lua/orgmode/api/file.lua
+28Lines changed: 28 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
---@diagnosticdisable:invisible
2
2
localOrgHeadline=require('orgmode.api.headline')
3
+
localHyperlinks=require('orgmode.org.hyperlinks')
4
+
localorg=require('orgmode')
3
5
4
6
---@classOrgApiFile
5
7
---@fieldcategorystring current file category name. By default it's only filename without extension unless defined differently via #+CATEGORY directive
@@ -92,4 +94,30 @@ function OrgFile:get_closest_headline(cursor)
92
94
returnnil
93
95
end
94
96
97
+
--- Get a link destination as string
98
+
---
99
+
--- Depending if org_id_link_to_org_use_id is set the format is
100
+
---
101
+
--- id:<uuid>::*title and the id is created if not existing
102
+
--- or
103
+
--- file:<filepath>::*title
104
+
---
105
+
--- The result is meant to be used as link_location for OrgApi.insert_link.
106
+
--- @returnstring
107
+
functionOrgFile:get_link()
108
+
localfilename=self.filename
109
+
localbufnr=vim.fn.bufnr(filename)
110
+
111
+
ifbufnr==-1ornotvim.api.nvim_buf_is_loaded(bufnr) then
0 commit comments