diff --git a/init.lua b/init.lua index 4eae8e7..2c4e8a8 100644 --- a/init.lua +++ b/init.lua @@ -90,8 +90,10 @@ P.S. You can delete this when you're done too. It's your config now! :) vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' +vim.g.tex_flavor = 'latex' + -- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.opt` @@ -102,7 +104,7 @@ vim.g.have_nerd_font = false vim.opt.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! --- vim.opt.relativenumber = true +vim.opt.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.opt.mouse = 'a' @@ -156,6 +158,9 @@ vim.opt.cursorline = true -- Minimal number of screen lines to keep above and below the cursor. vim.opt.scrolloff = 10 +vim.opt.shiftwidth = 4 +vim.opt.tabstop = 4 + -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` @@ -164,7 +169,7 @@ vim.opt.scrolloff = 10 vim.keymap.set('n', '', 'nohlsearch') -- Diagnostic keymaps -vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) +vim.keymap.set('n', 'd', vim.diagnostic.setloclist, { desc = 'Open Diagnostic Quickfix list' }) -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- for people to discover. Otherwise, you normally need to press , which @@ -228,7 +233,7 @@ vim.opt.rtp:prepend(lazypath) -- NOTE: Here is where you install your plugins. require('lazy').setup({ -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). - 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically + -- 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically -- NOTE: Plugins can also be added by using a table, -- with the first argument being the link and the following @@ -315,12 +320,8 @@ require('lazy').setup({ -- Document existing key chains spec = { - { 'c', group = '[C]ode', mode = { 'n', 'x' } }, - { 'd', group = '[D]ocument' }, - { 'r', group = '[R]ename' }, - { 's', group = '[S]earch' }, - { 'w', group = '[W]orkspace' }, - { 't', group = '[T]oggle' }, + { 'f', group = 'Telescope Find' }, + { 'c', group = 'Config Toggle' }, { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, }, }, @@ -402,39 +403,39 @@ require('lazy').setup({ -- See `:help telescope.builtin` local builtin = require 'telescope.builtin' - vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) - vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) - vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) - vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) - vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) - vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) - vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) - vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + vim.keymap.set('n', 'fh', builtin.help_tags, { desc = 'Telescope Help Tags' }) + vim.keymap.set('n', 'fk', builtin.keymaps, { desc = 'Telescope Keymaps' }) + vim.keymap.set('n', 'ff', builtin.find_files, { desc = 'Telescope Find Files' }) + -- vim.keymap.set('n', 'fs', builtin.builtin, { desc = '[F]ind [S]elect Telescope' }) + -- vim.keymap.set('n', 'fw', builtin.grep_string, { desc = '[F]ind current [W]ord' }) + vim.keymap.set('n', 'fg', builtin.live_grep, { desc = 'Telescope Live Grep' }) + -- vim.keymap.set('n', 'fd', builtin.diagnostics, { desc = '[F]ind [D]iagnostics' }) + -- vim.keymap.set('n', 'fr', builtin.resume, { desc = '[F]ind [R]esume' }) + -- vim.keymap.set('n', 'f.', builtin.oldfiles, { desc = '[F]ind Recent Files ("." for repeat)' }) + vim.keymap.set('n', '', builtin.buffers, { desc = 'Telescope Buffers' }) -- Slightly advanced example of overriding default behavior and theme - vim.keymap.set('n', '/', function() - -- You can pass additional configuration to Telescope to change the theme, layout, etc. - builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { - winblend = 10, - previewer = false, - }) - end, { desc = '[/] Fuzzily search in current buffer' }) + -- vim.keymap.set('n', '/', function() + -- You can pass additional configuration to Telescope to change the theme, layout, etc. + -- builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + -- winblend = 10, + -- previewer = false, + -- }) + -- end, { desc = '[/] Fuzzily search in current buffer' }) -- It's also possible to pass additional configuration options. -- See `:help telescope.builtin.live_grep()` for information about particular keys - vim.keymap.set('n', 's/', function() + vim.keymap.set('n', 'f/', function() builtin.live_grep { grep_open_files = true, prompt_title = 'Live Grep in Open Files', } - end, { desc = '[S]earch [/] in Open Files' }) + end, { desc = 'Telescope Live Grep in Open Files' }) -- Shortcut for searching your Neovim configuration files - vim.keymap.set('n', 'sn', function() + vim.keymap.set('n', 'fn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } - end, { desc = '[S]earch [N]eovim files' }) + end, { desc = 'Telescope Nvim Files' }) end, }, @@ -514,39 +515,39 @@ require('lazy').setup({ -- Jump to the definition of the word under your cursor. -- This is where a variable was first declared, or where a function is defined, etc. -- To jump back, press . - map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + map('gd', require('telescope.builtin').lsp_definitions, 'Goto Definition') -- Find references for the word under your cursor. - map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + map('grr', require('telescope.builtin').lsp_references, 'Goto References') -- Jump to the implementation of the word under your cursor. -- Useful when your language has ways of declaring types without an actual implementation. - map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + map('gI', require('telescope.builtin').lsp_implementations, 'Goto Implementation') -- Jump to the type of the word under your cursor. -- Useful when you're not sure what type a variable is and you want to see -- the definition of its *type*, not where it was *defined*. - map('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') + map('gDt', require('telescope.builtin').lsp_type_definitions, 'Goto Type Definition') -- Fuzzy find all the symbols in your current document. -- Symbols are things like variables, functions, types, etc. - map('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') + map('fd', require('telescope.builtin').lsp_document_symbols, 'Telescope Document Symbols') -- Fuzzy find all the symbols in your current workspace. -- Similar to document symbols, except searches over your entire project. - map('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + map('fw', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Telescope Workspace Symbols') -- Rename the variable under your cursor. -- Most Language Servers support renaming across files, etc. - map('rn', vim.lsp.buf.rename, '[R]e[n]ame') + map('grn', vim.lsp.buf.rename, 'Rename') -- Execute a code action, usually your cursor needs to be on top of an error -- or a suggestion from your LSP for this to activate. - map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' }) + map('gra', vim.lsp.buf.code_action, 'Code Action', { 'n', 'x' }) -- WARN: This is not Goto Definition, this is Goto Declaration. -- For example, in C this would take you to the header. - map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + map('gDd', vim.lsp.buf.declaration, 'Goto Declaration') -- The following two autocommands are used to highlight references of the -- word under your cursor when your cursor rests there for a little while. @@ -582,9 +583,9 @@ require('lazy').setup({ -- -- This may be unwanted, since they displace some of your code if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then - map('th', function() + map('ch', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) - end, '[T]oggle Inlay [H]ints') + end, 'Toggle Inlay Hints') end end, }) @@ -618,8 +619,8 @@ require('lazy').setup({ local servers = { -- clangd = {}, -- gopls = {}, - -- pyright = {}, - -- rust_analyzer = {}, + pyright = {}, + rust_analyzer = {}, -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- -- Some languages (like typescript) have entire language plugins that can be useful: @@ -639,7 +640,7 @@ require('lazy').setup({ callSnippet = 'Replace', }, -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings - -- diagnostics = { disable = { 'missing-fields' } }, + diagnostics = { disable = { 'missing-fields' } }, }, }, }, @@ -675,6 +676,7 @@ require('lazy').setup({ require('lspconfig')[server_name].setup(server) end, }, + automatic_installation = true, } end, }, @@ -685,12 +687,12 @@ require('lazy').setup({ cmd = { 'ConformInfo' }, keys = { { - 'f', + 'p', function() require('conform').format { async = true, lsp_format = 'fallback' } end, mode = '', - desc = '[F]ormat buffer', + desc = 'format', }, }, opts = { @@ -738,6 +740,9 @@ require('lazy').setup({ end return 'make install_jsregexp' end)(), + config = function(_, _) + -- require('luasnip.loaders.from_lua').lazy_load { paths = './lua/luasnippets/' } + end, dependencies = { -- `friendly-snippets` contains a variety of premade snippets. -- See the README about individual language/framework/plugin snippets: @@ -750,8 +755,10 @@ require('lazy').setup({ -- }, }, }, - 'saadparwaiz1/cmp_luasnip', - + { + 'franchioping/cmp_luasnip', + dev = true, + }, -- Adds other completion capabilities. -- nvim-cmp does not ship with all sources by default. They are split -- into multiple repos for maintenance purposes. @@ -762,7 +769,7 @@ require('lazy').setup({ -- See `:help cmp` local cmp = require 'cmp' local luasnip = require 'luasnip' - luasnip.config.setup {} + luasnip.config.setup { enable_autosnippets = true } cmp.setup { snippet = { @@ -789,7 +796,7 @@ require('lazy').setup({ -- Accept ([y]es) the completion. -- This will auto-import if your LSP supports it. -- This will expand snippets if the LSP sent a snippet. - [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping.confirm { select = true }, -- If you prefer more traditional completion keymaps, -- you can uncomment the following lines @@ -800,7 +807,7 @@ require('lazy').setup({ -- Manually trigger a completion from nvim-cmp. -- Generally you don't need this, because nvim-cmp will display -- completions whenever it has completion options available. - [''] = cmp.mapping.complete {}, + [''] = cmp.mapping.complete {}, -- Think of as moving to the right of your snippet expansion. -- So if you have a snippet that's like: @@ -810,12 +817,12 @@ require('lazy').setup({ -- -- will move you to the right of each of the expansion locations. -- is similar, except moving you backwards. - [''] = cmp.mapping(function() - if luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() + [''] = cmp.mapping(function() + if luasnip.locally_jumpable(1) then + luasnip.jump(1) end end, { 'i', 's' }), - [''] = cmp.mapping(function() + [''] = cmp.mapping(function() if luasnip.locally_jumpable(-1) then luasnip.jump(-1) end @@ -831,7 +838,10 @@ require('lazy').setup({ group_index = 0, }, { name = 'nvim_lsp' }, - { name = 'luasnip' }, + { name = 'luasnip', opts = { label_aliases = { + ['(?/', 'gcc', { remap = true }) +-- vim.keymap.set('v', '/', 'gc', { remap = true }) +-- + +local operator_rhs = function() + return require('vim._comment').operator() +end +vim.keymap.set({ 'x' }, '/', operator_rhs, { expr = true, desc = 'Toggle comment' }) + +local line_rhs = function() + return require('vim._comment').operator() .. '_' +end +vim.keymap.set('n', '/', line_rhs, { expr = true, desc = 'Toggle comment line' }) + +vim.g.tex_flavor = 'latex' + +local list_snips = function() + local ft_list = require('luasnip').available()[vim.o.filetype] + local ft_snips = {} + for _, item in pairs(ft_list) do + ft_snips[item.trigger] = item.name + end + print(vim.inspect(ft_snips)) +end + +vim.api.nvim_create_user_command('SnipList', list_snips, {}) + +local list_all_snips = function() + local ft_lists = require('luasnip').available() + local ft_snips = {} + for _, ft_list in pairs(ft_lists) do + for _, item in pairs(ft_list) do + ft_snips[item.trigger] = item.name + end + end + print(vim.inspect(ft_snips)) +end + +vim.api.nvim_create_user_command('SnipListAll', list_all_snips, {}) diff --git a/lua/custom/plugins/general.lua b/lua/custom/plugins/general.lua new file mode 100644 index 0000000..daf2b50 --- /dev/null +++ b/lua/custom/plugins/general.lua @@ -0,0 +1,21 @@ +return { + -- { + -- 'akinsho/toggleterm.nvim', + -- version = '*', + -- opts = {--[[ things you want to change go here]] + -- }, + -- keys = { + -- { 't', ':ToggleTerm direction=float', desc = 'Terminal', silent = true }, + -- }, + -- config = function() + -- local opts = { buffer = 0 } + -- vim.keymap.set('t', '', [[]], opts) + -- vim.keymap.set('t', 'jk', [[]], opts) + -- vim.keymap.set('t', '', [[wincmd h]], opts) + -- vim.keymap.set('t', '', [[wincmd j]], opts) + -- vim.keymap.set('t', '', [[wincmd k]], opts) + -- vim.keymap.set('t', '', [[wincmd l]], opts) + -- vim.keymap.set('t', '', [[]], opts) + -- end, + -- }, +} diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua deleted file mode 100644 index be0eb9d..0000000 --- a/lua/custom/plugins/init.lua +++ /dev/null @@ -1,5 +0,0 @@ --- You can add your own plugins here or in other files in this directory! --- I promise not to create any merge conflicts in this directory :) --- --- See the kickstart.nvim README for more information -return {} diff --git a/lua/custom/plugins/latex-tools.lua b/lua/custom/plugins/latex-tools.lua new file mode 100644 index 0000000..d2a8bba --- /dev/null +++ b/lua/custom/plugins/latex-tools.lua @@ -0,0 +1,29 @@ +return { + + { + 'lervag/vimtex', + lazy = false, -- we don't want to lazy load VimTeX + -- tag = "v2.15", -- uncomment to pin to a specific release + init = function() + -- VimTeX configuration goes here, e.g. + vim.g.vimtex_view_method = 'zathura' + end, + -- config = function() + -- vim.g.vimtex_indent_enabled = 0 + -- end, + }, + { + 'franchioping/luasnip-latex-snippets.nvim', + dev = true, + }, + -- { + -- 'iurimateus/luasnip-latex-snippets.nvim', + -- -- vimtex isn't required if using treesitter + -- requires = { 'L3MON4D3/LuaSnip', 'lervag/vimtex' }, + -- config = function() + -- require('luasnip-latex-snippets').setup() + -- -- or setup({ use_treesitter = true }) + -- require('luasnip').config.setup { enable_autosnippets = true } + -- end, + -- }, +} diff --git a/lua/custom/plugins/neo-tree.lua b/lua/custom/plugins/neo-tree.lua new file mode 100644 index 0000000..ed9c20f --- /dev/null +++ b/lua/custom/plugins/neo-tree.lua @@ -0,0 +1,22 @@ +-- You can add your own plugins here or in other files in this directory! +-- I promise not to create any merge conflicts in this directory :) +-- +-- See the kickstart.nvim README for more information +return { + + { + 'nvim-neo-tree/neo-tree.nvim', + branch = 'v3.x', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended + 'MunifTanjim/nui.nvim', + -- "3rd/image.nvim", -- Optional image support in preview window: See `# Preview Mode` for more information + }, + + cmd = 'Neotree', + keys = { + { 'e', ':Neotree toggle', desc = 'Explorer', silent = true }, + }, + }, +} diff --git a/lua/custom/plugins/telescope-undo.lua b/lua/custom/plugins/telescope-undo.lua new file mode 100644 index 0000000..94ff206 --- /dev/null +++ b/lua/custom/plugins/telescope-undo.lua @@ -0,0 +1,32 @@ +return { + 'debugloop/telescope-undo.nvim', + dependencies = { -- note how they're inverted to above example + { + 'nvim-telescope/telescope.nvim', + dependencies = { 'nvim-lua/plenary.nvim' }, + }, + }, + keys = { + { -- lazy style key map + 'fu', + 'Telescope undo', + desc = 'Telescope Undo History', + }, + }, + opts = { + -- don't use `defaults = { }` here, do this in the main telescope spec + extensions = { + undo = { + -- telescope-undo.nvim config, see below + }, + -- no other extensions here, they can have their own spec too + }, + }, + config = function(_, opts) + -- Calling telescope's setup from multiple specs does not hurt, it will happily merge the + -- configs for us. We won't use data, as everything is in it's own namespace (telescope + -- defaults, as well as each extension). + require('telescope').setup(opts) + require('telescope').load_extension 'undo' + end, +} diff --git a/lua/kickstart/plugins/lint.lua b/lua/kickstart/plugins/lint.lua index 907c6bf..e81cc33 100644 --- a/lua/kickstart/plugins/lint.lua +++ b/lua/kickstart/plugins/lint.lua @@ -5,9 +5,9 @@ return { event = { 'BufReadPre', 'BufNewFile' }, config = function() local lint = require 'lint' - lint.linters_by_ft = { - markdown = { 'markdownlint' }, - } + -- lint.linters_by_ft = { + -- markdown = { 'markdownlint' }, + -- } -- To allow other plugins to add linters to require('lint').linters_by_ft, -- instead set linters_by_ft like this: diff --git a/lua/luasnippets/all.lua b/lua/luasnippets/all.lua new file mode 100644 index 0000000..224458d --- /dev/null +++ b/lua/luasnippets/all.lua @@ -0,0 +1,31 @@ +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 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 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 ms = ls.multi_snippet +local k = require('luasnip.nodes.key_indexer').new_key + +return { + s('date', t(os.date '%Y-%m-%d')), +} diff --git a/lua/luasnippets/tex_old/postfix.lua b/lua/luasnippets/tex_old/postfix.lua new file mode 100644 index 0000000..e12e186 --- /dev/null +++ b/lua/luasnippets/tex_old/postfix.lua @@ -0,0 +1,80 @@ +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 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 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 ms = ls.multi_snippet +local k = require('luasnip.nodes.key_indexer').new_key + +local utils = require 'luasnip-latex-snippets.util.utils' +local is_math = utils.with_opts(utils.is_math, false) -- true to use treesitter +local not_math = utils.with_opts(utils.not_math, false) -- true to use treesitter +local as = require('luasnip').extend_decorator.apply(s, { snippetType = 'autosnippet' }) + +local ret = {} + +-- dynamic node +-- generally, postfix comes in the form PRE-CAPTURE-POST, so in this case, arg1 is the "pre" text, arg2 the "post" text +local dynamic_postfix = function(_, parent, _, user_arg1, user_arg2) + local capture = parent.snippet.env.POSTFIX_MATCH + if #capture > 0 then + return sn( + nil, + fmta( + [[ + <><><><> + ]], + { t(user_arg1), t(capture), t(user_arg2), i(0) } + ) + ) + else + local visual_placeholder = '' + if #parent.snippet.env.SELECT_RAW > 0 then + visual_placeholder = parent.snippet.env.SELECT_RAW + end + return sn( + nil, + fmta( + [[ + <><><><> + ]], + { t(user_arg1), i(1, visual_placeholder), t(user_arg2), i(0) } + ) + ) + end +end + +local function postfix_std(trig, result_start, result_end) + return postfix( + { trig = trig, snippetType = 'autosnippet' }, + { d(1, dynamic_postfix, {}, { user_args = { result_start, result_end } }) }, + { condition = is_math, show_condition = is_math } + ) +end + +-- table.insert(ret, postfix_std('vec', '\\vec{', '}')) +-- table.insert(ret, postfix_std('hat', '\\hat{', '}')) +-- table.insert(ret, postfix_std('dot', '\\dot{', '}')) +-- table.insert(ret, postfix_std('bar', '\\bar{', '}')) + +return ret diff --git a/lua/luasnippets/tex_old/ranges.lua b/lua/luasnippets/tex_old/ranges.lua new file mode 100644 index 0000000..a029f5f --- /dev/null +++ b/lua/luasnippets/tex_old/ranges.lua @@ -0,0 +1,87 @@ +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 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 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 ms = ls.multi_snippet +local k = require('luasnip.nodes.key_indexer').new_key + +local utils = require 'luasnip-latex-snippets.util.utils' +local is_math = utils.with_opts(utils.is_math, false) -- true to use treesitter +local not_math = utils.with_opts(utils.not_math, false) -- true to use treesitter +local as = require('luasnip').extend_decorator.apply(s, { snippetType = 'autosnippet' }) + +local ret = {} +-- +-- table.insert( +-- ret, +-- as( +-- { +-- trig = 'rancc', +-- regTrig = true, +-- name = 'range closed close', +-- dscr = 'ranges typing x_ -> x_{}', +-- }, +-- fmta([[ \left[ <> ; <> \right] ]], { +-- i(1), +-- i(2), +-- }), +-- { condition = is_math } +-- ) +-- ) + +local leters = { 'c', 'o' } +for index, value in ipairs(leters) do + for index2, value2 in ipairs(leters) do + local char1 + local char2 + if index == 1 then + char1 = '[' + else + char1 = ']' + end + if index2 == 1 then + char2 = ']' + else + char2 = '[' + end + table.insert( + ret, + as( + { + trig = 'ran' .. value .. value2, + regTrig = true, + name = 'range ' .. value .. value2 .. ' - ' .. char1 .. char2, + dscr = 'ranges', + }, + fmta('\\left' .. char1 .. ' <> ; <> \\right' .. char2, { + i(1), + i(2), + }), + { condition = is_math } + ) + ) + end +end + +return ret diff --git a/lua/luasnippets/tex_old/tex.lua b/lua/luasnippets/tex_old/tex.lua new file mode 100644 index 0000000..c5775d1 --- /dev/null +++ b/lua/luasnippets/tex_old/tex.lua @@ -0,0 +1,52 @@ +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 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 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 ms = ls.multi_snippet +local k = require('luasnip.nodes.key_indexer').new_key + +local utils = require 'luasnip-latex-snippets.util.utils' +local is_math = utils.with_opts(utils.is_math, false) -- true to use treesitter +local not_math = utils.with_opts(utils.not_math, false) -- true to use treesitter +local as = require('luasnip').extend_decorator.apply(s, { snippetType = 'autosnippet' }) + +local ret = { + as( + { + trig = '(%a)_', + regTrig = true, + name = 'auto subscript underscore', + dscr = 'Auto subscript: typing x_ -> x_{}', + }, + fmta([[<>_{<>}]], { + f(function(_, snip) + return snip.captures[1] + end), + i(1), + }), + { condition = is_math } + ), +} + +return {}