diff --git a/BACKLOG.md b/BACKLOG.md index 070de29..20aa381 100644 --- a/BACKLOG.md +++ b/BACKLOG.md @@ -2,17 +2,19 @@ - [ ] maybe a virtual line in the 1st line that shows number of backlinks and maybe other interesting stuff - or put it as an extmark at the end of the first line, meh. -- [ ] better support for #tags -- [ ] some cool buffer showing backlinks (and stuff?) +- [ ] better support for #tags [see also this comment](https://github.com/renerocksai/telekasten.nvim/discussions/23#discussioncomment-1754511) +- [ ] some cool buffer showing backlinks (and stuff?) [see also this comment](https://github.com/renerocksai/telekasten.nvim/discussions/23#discussioncomment-1754511) - maybe another one where we dot-render a graph of linked notes and display it via vimg from telescope_media_files or sth similar - these buffers / this buffer should keep its size even when resizing other splits (like the calendar) - [ ] really good support for special links: inserting, yanking, ... +- [ ] lsp support, lsp completion of everything: notes, headings, paragraphs, tags, ... - [ ] yt video ## Dones +- [x] follow external URLs - [x] telekasten filetype - [x] Telekasten command with completion, command palette - [x] follow #tags diff --git a/lua/telekasten.lua b/lua/telekasten.lua index 4f93fa2..d0be2c1 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -695,6 +695,30 @@ local function check_for_link_or_tag() return taglinks.is_tag_or_link_at(line, col, M.Cfg) end +local function follow_url(url) + -- we just leave it to the OS's handler to deal with what kind of URL it is + local function format_command(cmd) + return 'call jobstart(["' + .. cmd + .. '", "' + .. url + .. '"], {"detach": v:true})' + end + + local command + if vim.fn.has("mac") == 1 then + command = format_command("open") + vim.cmd(command) + else + if vim.fn.has("unix") then + command = format_command("xdg-open") + vim.cmd(command) + else + print("Cannot open URLs on your operating system") + end + end +end + -- -- FollowLink: -- ----------- @@ -725,10 +749,18 @@ local function FollowLink(opts) search_mode = "tag" title = tag else - -- we are in a link - vim.cmd("normal yi]") - title = vim.fn.getreg('"0') - title = title:gsub("^(%[)(.+)(%])$", "%2") + if kind == "link" then + -- we are in a link + vim.cmd("normal yi]") + title = vim.fn.getreg('"0') + title = title:gsub("^(%[)(.+)(%])$", "%2") + else + -- we are in an external [link] + vim.cmd("normal yi)") + local url = vim.fn.getreg('"0') + print(url) + return follow_url(url) + end local parts = vim.split(title, "#")