From 0daf201a8faed0b5eb4a9b545bcc963f9a2793a5 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Fri, 11 Oct 2024 13:48:08 +0200 Subject: [PATCH] Neovim: Add sample LaTeX snippet --- home/modules/neovim/default.nix | 14 ++++++++--- home/modules/neovim/snippets_latex.lua | 33 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 home/modules/neovim/snippets_latex.lua diff --git a/home/modules/neovim/default.nix b/home/modules/neovim/default.nix index 444d8ab5..570b27ea 100644 --- a/home/modules/neovim/default.nix +++ b/home/modules/neovim/default.nix @@ -112,6 +112,9 @@ in { # For this its probably important to set the default filetype to tex (see extraConfigLua) "ftplugin/tex/mappings.lua".text = mylib.generators.toLuaKeymap (import ./mappings_latex.nix {}); "ftplugin/markdown/mappings.lua".text = mylib.generators.toLuaKeymap (import ./mappings_markdown.nix {}); + + # Luasnip searches the luasnippets folder in the runtimepath + "luasnippets/tex.lua".text = builtins.readFile ./snippets_latex.lua; }; # extraLuaPackages = with pkgs.lua51Packages; []; @@ -1052,8 +1055,15 @@ in { config = '' function(_, opts) require("luasnip").config.set_config(opts) + + -- Load snippets. Because we don't set "path", the nvim runtimepath is searched. + -- Snippet files are added through nixvim's extraFiles (see at the top). + require("luasnip.loaders.from_lua").lazy_load({}) end ''; + opts = { + enable_autosnippets = false; + }; }; ltex-extra = { @@ -1779,9 +1789,7 @@ in { lint # Lint documents on save lspconfig # Language server configurations for different languages lualine # Status line - - luasnip # Snippets # TODO: How to add snippets, maybe use luasnip from nixvim directly? - + luasnip # Snippets ltex-extra # Additional ltex lsp support, e.g. for add-to-dictionary action markview # Markdown support # TODO: Disable in help buffers + confiure a bit more diff --git a/home/modules/neovim/snippets_latex.lua b/home/modules/neovim/snippets_latex.lua new file mode 100644 index 00000000..c6aec086 --- /dev/null +++ b/home/modules/neovim/snippets_latex.lua @@ -0,0 +1,33 @@ +return { + -- The first list contains manually expanded snippts + -- + -- The fmta function accepts a string ([[]] denote multiline strings) and node table. + -- The node table entry order corresponds to the delimiters, + -- the indices denote the jumping order, 0 is jumped to last. + -- + -- Example: + -- s("beg", fmta([[ + -- \begin{<>} + -- <> + -- \end{<>}]], + -- { i(1), i(0), rep(1) } + -- )), + -- + -- The first jumping position (1) fills the \begin{<>} (and \end{<>} because of the repeat). + -- The last jumping position (0) fills the body. + + -- \begin{environment} + s( + "beg", + fmta( + [[ + \begin{<>} + <> + \end{<>} + ]], + { i(1), i(0), rep(1) } + ) + ), +}, { + -- The second list contains autosnippets +}