all repos — dotfiles @ b8b12c23c7cb1a7cc40a137d4b55ed40ba2790e8

linux dotfiles

nvim: add snippets.lua
Prithu Goswami pg@prithu.dev
Tue, 12 Mar 2024 08:34:51 +0530
commit

b8b12c23c7cb1a7cc40a137d4b55ed40ba2790e8

parent

d77dfd2f8fe52be70992c3f170418efba0c72cb6

2 files changed, 43 insertions(+), 0 deletions(-)

jump to
M config/nvim/init.luaconfig/nvim/init.lua

@@ -4,6 +4,7 @@ require 'keymaps'

require 'completion' require 'lsp' require 'highlights' +require 'snippets' -- TODO move each plugin setup to own file local function nvim_tree_on_attach(bufnr)
A config/nvim/lua/snippets.lua

@@ -0,0 +1,42 @@

+local snip_status_ok, ls = pcall(require, "luasnip") +if not snip_status_ok then + return +end + +local s = ls.snippet +local fmt = require("luasnip.extras.fmt").fmt +-- local sn = ls.snippet_node +-- local isn = ls.indent_snippet_node +-- local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +-- local c = ls.choice_node +-- local d = ls.dynamic_node + +local get_title = function(nodes) + local url = nodes[1][1] + vim.notify("Url: " .. url) + local out = "" + local jobid = vim.fn.jobstart({ "fetchtitle", url }, { + stdout_buffered = true, + on_stdout = function(_, data) + if data then + print(vim.inspect(data)) + out = data[1] + end + end + }) + vim.fn.jobwait({jobid}, 3000) + return out +end + +ls.add_snippets("markdown", { + s("mdlink", + fmt("[{}]({})", + { + f(get_title, {1}), + i(1) + } + ) + ) +})