implement #26 : follow external urls

This commit is contained in:
Rene Schallner
2021-12-10 18:22:19 +01:00
parent 4eaf9f10e0
commit 0c6368c6da
2 changed files with 40 additions and 6 deletions

View File

@@ -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

View File

@@ -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, "#")