more work on latex snippets
This commit is contained in:
parent
0418fee519
commit
a84b807d88
|
@ -8,7 +8,7 @@ local f = luasnip.function_node
|
|||
luasnip.setup({
|
||||
history = true,
|
||||
enable_autosnippets = true,
|
||||
update_events = {"TextChanged", "TextChangedI"},
|
||||
update_events = { "TextChanged", "TextChangedI" },
|
||||
snip_env = {
|
||||
s = function(...)
|
||||
local snip = luasnip.s(...)
|
||||
|
|
|
@ -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 s = ls.snippet
|
||||
-- local sn = ls.snippet_node
|
||||
-- local isn = ls.indent_snippet_node
|
||||
-- local t = ls.text_node
|
||||
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 r = ls.restore_node
|
||||
-- local events = require("luasnip.util.events")
|
||||
-- local ai = require("luasnip.nodes.absolute_indexer")
|
||||
-- local extras = require("luasnip.extras")
|
||||
-- local l = extras.lambda
|
||||
-- local rep = extras.rep
|
||||
-- local p = extras.partial
|
||||
-- local m = extras.match
|
||||
-- local n = extras.nonempty
|
||||
-- local dl = extras.dynamic_lambda
|
||||
local c = ls.choice_node
|
||||
local d = ls.dynamic_node
|
||||
local r = ls.restore_node
|
||||
local events = require("luasnip.util.events")
|
||||
local ai = require("luasnip.nodes.absolute_indexer")
|
||||
local extras = require("luasnip.extras")
|
||||
local l = extras.lambda
|
||||
local rep = extras.rep
|
||||
local p = extras.partial
|
||||
local m = extras.match
|
||||
local n = extras.nonempty
|
||||
local dl = extras.dynamic_lambda
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
-- local fmta = require("luasnip.extras.fmt").fmta
|
||||
-- local conds = require("luasnip.extras.expand_conditions")
|
||||
-- local postfix = require("luasnip.extras.postfix").postfix
|
||||
-- local types = require("luasnip.util.types")
|
||||
-- local parse = require("luasnip.util.parser").parse_snippet
|
||||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
local conds = require("luasnip.extras.expand_conditions")
|
||||
local postfix = require("luasnip.extras.postfix").postfix
|
||||
local types = require("luasnip.util.types")
|
||||
local parse = require("luasnip.util.parser").parse_snippet
|
||||
local ms = ls.multi_snippet
|
||||
|
||||
local function has_value(tab, val)
|
||||
|
@ -44,6 +45,24 @@ local function cond_space(args, _)
|
|||
return ' '
|
||||
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 {
|
||||
}, {
|
||||
s({ trig = "^beg", regTrig = true, wordTrig = false, name = "begin{} / end{}" }, fmt([[
|
||||
|
@ -89,5 +108,20 @@ return {
|
|||
}, fmt([[
|
||||
\\frac{{{}}}{{{}}}
|
||||
]], { 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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue