From f6578a821aeef3dcfc504b517ebde531b2959f65 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 16 Feb 2022 08:18:32 +0000 Subject: [PATCH] feat(nvim): add a snippet for `pcall` Useful when adding configuration files for new plugins. --- roles/neovim/files/lua/opdavies/snippets/ft/lua.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/roles/neovim/files/lua/opdavies/snippets/ft/lua.lua b/roles/neovim/files/lua/opdavies/snippets/ft/lua.lua index 13c63fd..acdb3eb 100644 --- a/roles/neovim/files/lua/opdavies/snippets/ft/lua.lua +++ b/roles/neovim/files/lua/opdavies/snippets/ft/lua.lua @@ -5,5 +5,12 @@ local rep = require("luasnip.extras").rep local i = ls.insert_node return { - req = fmt("local {} = require('{}')", { i(1), rep(1) }) + req = fmt("local {} = require('{}')", { i(1), rep(1) }), + + pcall = fmt([[ + local status_ok, {} = pcall(require, "{}") + if not status_ok then + return + end + ]], { i(1), rep(1) }) }