more work on latex snippets
This commit is contained in:
parent
0418fee519
commit
a84b807d88
2 changed files with 56 additions and 22 deletions
.config/nvim/lua/snippets
|
@ -1,30 +1,31 @@
|
||||||
-- NOTE: These snippets are for taking notes quickly
|
-- Copied from Gilles Castel (R.I.P.)
|
||||||
|
-- https://castel.dev/post/lecture-notes-1/
|
||||||
|
|
||||||
local ls = require("luasnip")
|
local ls = require("luasnip")
|
||||||
local s = ls.snippet
|
local s = ls.snippet
|
||||||
-- local sn = ls.snippet_node
|
local sn = ls.snippet_node
|
||||||
-- local isn = ls.indent_snippet_node
|
local isn = ls.indent_snippet_node
|
||||||
-- local t = ls.text_node
|
local t = ls.text_node
|
||||||
local i = ls.insert_node
|
local i = ls.insert_node
|
||||||
local f = ls.function_node
|
local f = ls.function_node
|
||||||
-- local c = ls.choice_node
|
local c = ls.choice_node
|
||||||
-- local d = ls.dynamic_node
|
local d = ls.dynamic_node
|
||||||
-- local r = ls.restore_node
|
local r = ls.restore_node
|
||||||
-- local events = require("luasnip.util.events")
|
local events = require("luasnip.util.events")
|
||||||
-- local ai = require("luasnip.nodes.absolute_indexer")
|
local ai = require("luasnip.nodes.absolute_indexer")
|
||||||
-- local extras = require("luasnip.extras")
|
local extras = require("luasnip.extras")
|
||||||
-- local l = extras.lambda
|
local l = extras.lambda
|
||||||
-- local rep = extras.rep
|
local rep = extras.rep
|
||||||
-- local p = extras.partial
|
local p = extras.partial
|
||||||
-- local m = extras.match
|
local m = extras.match
|
||||||
-- local n = extras.nonempty
|
local n = extras.nonempty
|
||||||
-- local dl = extras.dynamic_lambda
|
local dl = extras.dynamic_lambda
|
||||||
local fmt = require("luasnip.extras.fmt").fmt
|
local fmt = require("luasnip.extras.fmt").fmt
|
||||||
-- local fmta = require("luasnip.extras.fmt").fmta
|
local fmta = require("luasnip.extras.fmt").fmta
|
||||||
-- local conds = require("luasnip.extras.expand_conditions")
|
local conds = require("luasnip.extras.expand_conditions")
|
||||||
-- local postfix = require("luasnip.extras.postfix").postfix
|
local postfix = require("luasnip.extras.postfix").postfix
|
||||||
-- local types = require("luasnip.util.types")
|
local types = require("luasnip.util.types")
|
||||||
-- local parse = require("luasnip.util.parser").parse_snippet
|
local parse = require("luasnip.util.parser").parse_snippet
|
||||||
local ms = ls.multi_snippet
|
local ms = ls.multi_snippet
|
||||||
|
|
||||||
local function has_value(tab, val)
|
local function has_value(tab, val)
|
||||||
|
@ -44,6 +45,24 @@ local function cond_space(args, _)
|
||||||
return ' '
|
return ' '
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function sub_capture(index, first, last)
|
||||||
|
return f(function(_, snip, user_arg1) return snip.captures[user_arg1]:sub(first, last) end, nil,
|
||||||
|
{ user_args = { index } })
|
||||||
|
end
|
||||||
|
|
||||||
|
local function in_comment()
|
||||||
|
return vim.fn['vimtex#syntax#in_comment']() == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local function in_math()
|
||||||
|
return vim.fn['vimtex#syntax#in_mathzone']() == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local function in_env(name)
|
||||||
|
local x, y = vim.fn['vimtex#env#is_inside'](name)
|
||||||
|
return (x ~= '0' and y ~= '0')
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
}, {
|
}, {
|
||||||
s({ trig = "^beg", regTrig = true, wordTrig = false, name = "begin{} / end{}" }, fmt([[
|
s({ trig = "^beg", regTrig = true, wordTrig = false, name = "begin{} / end{}" }, fmt([[
|
||||||
|
@ -89,5 +108,20 @@ return {
|
||||||
}, fmt([[
|
}, fmt([[
|
||||||
\\frac{{{}}}{{{}}}
|
\\frac{{{}}}{{{}}}
|
||||||
]], { capture(1), i(1) })),
|
]], { capture(1), i(1) })),
|
||||||
|
s({ trig = "(%b())/", name = "Fraction", regTrig = true }, fmt([[
|
||||||
|
\\frac{{{}}}{{{}}}
|
||||||
|
]], { sub_capture(1, 2, -2), i(1) })),
|
||||||
|
s({ trig = "([A-Za-z])bar", regTrig = true, name = "Overline" }, fmt([[
|
||||||
|
\overline{{{}}}
|
||||||
|
]], { capture(1) })),
|
||||||
|
s({ trig = "bar", name = "Overline" }, fmt([[
|
||||||
|
\overline{{{}}}
|
||||||
|
]], { i(1) })),
|
||||||
|
s({ trig = "([A-Za-z])hat", regTrig = true, name = "Hat" }, fmt([[
|
||||||
|
\hat{{{}}}
|
||||||
|
]], { capture(1) })),
|
||||||
|
s({ trig = "hat", name = "Hat" }, fmt([[
|
||||||
|
\hat{{{}}}
|
||||||
|
]], { i(1) })),
|
||||||
-- TODO: continue porting these snippets: https://castel.dev/post/lecture-notes-1/#fractions
|
-- TODO: continue porting these snippets: https://castel.dev/post/lecture-notes-1/#fractions
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue