From ef44657937474145403c2b441b862035914d6a44 Mon Sep 17 00:00:00 2001 From: Nanderty Date: Sun, 26 Mar 2023 16:04:40 +0200 Subject: Snippets --- lua/Snippets/luasniphelpers.lua | 9 +++++++ lua/Snippets/luasniphelperslatex.lua | 26 +++++++++++++++++++ lua/Snippets/tex/environments.lua | 49 ++++++++++++++++++++++++++++++++++++ lua/Snippets/tex/general.lua | 23 +++++++++++++++++ lua/Snippets/tex/greek.lua | 17 +++++++++++++ lua/Snippets/tex/math.lua | 29 +++++++++++++++++++++ lua/plugins/cmp.lua | 6 ++--- lua/plugins/telescope.lua | 17 ------------- 8 files changed, 156 insertions(+), 20 deletions(-) create mode 100644 lua/Snippets/luasniphelpers.lua create mode 100644 lua/Snippets/luasniphelperslatex.lua create mode 100644 lua/Snippets/tex/environments.lua create mode 100644 lua/Snippets/tex/general.lua create mode 100644 lua/Snippets/tex/greek.lua create mode 100644 lua/Snippets/tex/math.lua (limited to 'lua') diff --git a/lua/Snippets/luasniphelpers.lua b/lua/Snippets/luasniphelpers.lua new file mode 100644 index 0000000..5aa3e44 --- /dev/null +++ b/lua/Snippets/luasniphelpers.lua @@ -0,0 +1,9 @@ +local M = {} + +local ls = require("luasnip") +local sn = ls.snippet_node +local i = ls.insert_node + +M.line_begin = require("luasnip.extras.expand_conditions").line_begin + +return M diff --git a/lua/Snippets/luasniphelperslatex.lua b/lua/Snippets/luasniphelperslatex.lua new file mode 100644 index 0000000..a31e714 --- /dev/null +++ b/lua/Snippets/luasniphelperslatex.lua @@ -0,0 +1,26 @@ +local M = {} + +M.in_mathzone = function() + return vim.fn['vimtex#syntax#in_mathzone']() == 1 +end +M.in_text = function() + return not tex_utils.in_mathzone() +end +M.in_comment = function() + return vim.fn['vimtex#syntax#in_comment']() == 1 +end +M.in_env = function(name) + local is_inside = vim.fn['vimtex#env#is_inside'](name) + return (is_inside[1] > 0 and is_inside[2] > 0) +end +M.in_equation = function() + return tex_utils.in_env('equation') +end +M.in_itemize = function() + return tex_utils.in_env('itemize') +end +M.in_tikz = function() + return tex_utils.in_env('tikzpicture') +end + +return M diff --git a/lua/Snippets/tex/environments.lua b/lua/Snippets/tex/environments.lua new file mode 100644 index 0000000..fd19387 --- /dev/null +++ b/lua/Snippets/tex/environments.lua @@ -0,0 +1,49 @@ +local helper = require('Snippets.luasniphelpers') +local helper = require('Snippets.luasniphelpers') + +return { + -- variable environment + s({ trig = 'beg', snippetType = 'autosnippet' }, + fmta( + [[ +\begin{<>} + <> +\end{<>} +]], + { + i(1), + i(2), + rep(1), + } + ), + { condition = helper.line_begin } + ), + -- enumerate environment + s({ trig = 'enu', snippetType = 'autosnippet' }, + fmta( + [[ +\begin{enumerate*} + \item <> +\end{enumerate*} +]], + { + i(1), + } + ), + { condition = helper.line_begin } + ), + -- align environment + s({ trig = 'ali', snippetType = 'autosnippet' }, + fmta( + [[ +\begin{align*} + <> +\end{align*} +]], + { + i(1), + } + ), + { condition = helper.line_begin } + ), +} diff --git a/lua/Snippets/tex/general.lua b/lua/Snippets/tex/general.lua new file mode 100644 index 0000000..ebe76fe --- /dev/null +++ b/lua/Snippets/tex/general.lua @@ -0,0 +1,23 @@ +local tex = require('Snippets.luasniphelperslatex') +local helper = require('Snippets.luasniphelpers') + +return { + s({ trig = "sec", snippetType = "autosnippet" }, + fmta( + '\\section*{<>}', + { + i(1), + } + ), + { condition = line_begin } + ), + s({ trig = "hh", snippetType = "autosnippet" }, + fmta( + '\\SI{<>}{<>}', + { + i(1), + i(2), + } + ) + ), +} diff --git a/lua/Snippets/tex/greek.lua b/lua/Snippets/tex/greek.lua new file mode 100644 index 0000000..f47cdac --- /dev/null +++ b/lua/Snippets/tex/greek.lua @@ -0,0 +1,17 @@ +local tex = require('Snippets.luasniphelperslatex') +local helper = require('Snippets.luasniphelpers') + +return { + s({ trig = "pi", snippetType = "autosnippet" }, + { + t("\\pi"), + }, + { condition = tex.in_mathzone } + ), + s({ trig = "0eps", snippetType = "autosnippet" }, + { + t("\\epsilon_0"), + }, + { condition = tex.in_mathzone } + ), +} diff --git a/lua/Snippets/tex/math.lua b/lua/Snippets/tex/math.lua new file mode 100644 index 0000000..670ed80 --- /dev/null +++ b/lua/Snippets/tex/math.lua @@ -0,0 +1,29 @@ +local tex = require('Snippets.luasniphelperslatex') +local helper = require('Snippets.luasniphelpers') + +return { + s({ trig = '/', snippetType = 'autosnippet' }, + fmta( + '\\frac{<>}{<>}', + { + i(1), + i(2), + } + ), + { condition = tex.in_mathzone } + ), + s({ trig = "in", snippetType = "autosnippet" }, + fmta( + '\\int_{<>}^{<>}', + { + i(1), + i(2), + } + ), + { condition = tex.in_mathzone } + ), + s({ trig = 'df', snippetType = 'autosnippet' }, + { t('\\diff ') }, + { condition = tex.in_mathzone } + ), +} diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index 76e8101..3f7b6ea 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -14,7 +14,7 @@ return { }, config = function(_, opts) require('luasnip').config.set_config(opts) - require('luasnip.loaders.from_lua').lazy_load({ paths = vim.fn.stdpath('config') .. '/Snippets/' }) + require('luasnip.loaders.from_lua').lazy_load({ paths = vim.fn.stdpath('config') .. '/lua/Snippets/' }) end }, { @@ -23,7 +23,7 @@ return { dependencies = { 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', - 'hrsh7th/cmp-path', + 'FelipeLema/cmp-async-path', 'hrsh7th/cmp-calc', 'saadparwaiz1/cmp_luasnip', 'L3MON4D3/LuaSnip', @@ -55,7 +55,7 @@ return { { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'buffer' }, - { name = 'path' }, + { name = 'async_path' }, { name = 'calc' }, }), formatting = { diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index b62373d..3f1a9b8 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -36,11 +36,6 @@ return { }, borderchars = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, }, - extensions = { - sessions_picker = { - sessions_dir = vim.fn.stdpath('data') .. '/session/', - } - }, }, }, { @@ -55,18 +50,6 @@ return { require('telescope').load_extension 'file_browser' end, }, - { - dir = vim.fn.stdpath('data') .. '/localplugins/telemini/', - keys = { - { 'ps', 'Telescope telemini', desc = 'sessions' } - }, - dependencies = { - 'nvim-telescope/telescope.nvim', - }, - config = function() - require('telescope').load_extension 'telemini' - end, - }, { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make', -- cgit v1.2.3