From bd4d79f7f3f4a8354322995407b1030b042e31a9 Mon Sep 17 00:00:00 2001 From: Franchioping Date: Wed, 26 Nov 2025 21:21:58 +0000 Subject: [PATCH] neovim stuffs, tex, esp32 --- init.lua | 63 +++++++++++++++++++----------- lazy-lock.json | 45 +++++++++++---------- lua/custom/plugins/general.lua | 29 ++++++++++++++ lua/custom/plugins/latex-tools.lua | 14 ++++++- lua/luasnippets/tex/conditions.lua | 49 +++++++++++++++++++++++ lua/luasnippets/tex/postfix.lua | 35 +++++++++++------ lua/luasnippets/tex/ranges.lua | 4 +- lua/luasnippets/tex/tex.lua | 7 ++-- 8 files changed, 184 insertions(+), 62 deletions(-) create mode 100644 lua/luasnippets/tex/conditions.lua diff --git a/init.lua b/init.lua index 2ecdeda..e0af9b1 100644 --- a/init.lua +++ b/init.lua @@ -462,7 +462,7 @@ require('lazy').setup({ -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})` { 'williamboman/mason.nvim', opts = {} }, 'williamboman/mason-lspconfig.nvim', - 'WhoIsSethDaniel/mason-tool-installer.nvim', + -- 'WhoIsSethDaniel/mason-tool-installer.nvim', -- Useful status updates for LSP. { 'j-hui/fidget.nvim', opts = {} }, @@ -471,6 +471,16 @@ require('lazy').setup({ 'hrsh7th/cmp-nvim-lsp', }, config = function() + vim.lsp.config('clangd', { + cmd = { 'clangd' }, + filetypes = { 'c', 'cpp', 'objc', 'objcpp' }, + autostart = true, + }) + vim.lsp.enable 'clangd' + if os.getenv 'NVIM_ESP32_ENV' then + local esp32 = require 'esp32' + vim.lsp.config('clangd', esp32.lsp_config()) + end -- Brief aside: **What is LSP?** -- -- LSP is an initialism you've probably heard, but might not understand what it is. @@ -625,7 +635,6 @@ require('lazy').setup({ -- - settings (table): Override the default settings passed when initializing the server. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { - clangd = {}, -- gopls = {}, rust_analyzer = {}, -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs @@ -666,11 +675,11 @@ require('lazy').setup({ -- -- You can add other tools here that you want Mason to install -- for you, so that they are available from within Neovim. - local ensure_installed = vim.tbl_keys(servers or {}) - vim.list_extend(ensure_installed, { - 'stylua', -- Used to format Lua code - }) - require('mason-tool-installer').setup { ensure_installed = ensure_installed } + -- local ensure_installed = vim.tbl_keys(servers or {}) + -- vim.list_extend(ensure_installed, { + -- 'stylua', -- Used to format Lua code + -- }) + -- require('mason-tool-installer').setup { ensure_installed = ensure_installed } require('mason-lspconfig').setup { handlers = { @@ -683,7 +692,7 @@ require('lazy').setup({ require('lspconfig')[server_name].setup(server) end, }, - automatic_installation = true, + -- automatic_installation = true, } end, }, @@ -723,6 +732,7 @@ require('lazy').setup({ formatters_by_ft = { lua = { 'stylua' }, markdown = { 'markdownlint' }, + json = { 'fixjson', 'jq' }, -- Conform can also run multiple formatters sequentially -- python = { "isort", "black" }, -- @@ -850,6 +860,7 @@ require('lazy').setup({ name = 'luasnip', option = { show_autosnippets = true, + use_show_condition = false, -- label_aliases = { -- ['(? 0 and is_inside[2] > 0) +end + +function M.in_preamble() + return not env 'document' +end + +function M.in_text() + return env 'document' and not M.in_math() +end + +function M.in_tikz() + return env 'tikzpicture' +end + +function M.in_bullets() + return env 'itemize' or env 'enumerate' +end + +function M.in_align() + return env 'align' or env 'align*' or env 'aligned' +end + +return M diff --git a/lua/luasnippets/tex/postfix.lua b/lua/luasnippets/tex/postfix.lua index e0fb378..bee3e1b 100644 --- a/lua/luasnippets/tex/postfix.lua +++ b/lua/luasnippets/tex/postfix.lua @@ -26,8 +26,8 @@ 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.luasnippets.tex.utils' -local is_math = utils.conditions.is_math +local conditions = require 'luasnippets.tex.conditions' +local is_math = conditions.is_math local as = require('luasnip').extend_decorator.apply(s, { snippetType = 'autosnippet' }) @@ -36,6 +36,7 @@ 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) + print(table.concat(parent.snippet, '\n')) local capture = parent.snippet.env.POSTFIX_MATCH if #capture > 0 then return sn( @@ -64,17 +65,29 @@ local dynamic_postfix = function(_, parent, _, user_arg1, user_arg2) 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 } +-- 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 + +-- Helper: creates a regex-triggered snippet that wraps the next character(s) +-- after in ... +local function postfix_std(prefix, before, after) + return s( + { trig = prefix .. '(%a)', regTrig = true, wordTrig = false, snippetType = 'autosnippet' }, + f(function(_, snip) + local captured = snip.captures[1] + return before .. captured .. after + end) ) 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{', '}')) +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/ranges.lua b/lua/luasnippets/tex/ranges.lua index 31d36f4..bb5bdb4 100644 --- a/lua/luasnippets/tex/ranges.lua +++ b/lua/luasnippets/tex/ranges.lua @@ -26,9 +26,9 @@ 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.luasnippets.tex.utils' +local conditions = require 'luasnippets.tex.conditions' -local is_math = utils.conditions.is_math +local is_math = conditions.is_math local as = require('luasnip').extend_decorator.apply(s, { snippetType = 'autosnippet' }) local ret = {} diff --git a/lua/luasnippets/tex/tex.lua b/lua/luasnippets/tex/tex.lua index dc7338a..628adec 100644 --- a/lua/luasnippets/tex/tex.lua +++ b/lua/luasnippets/tex/tex.lua @@ -26,10 +26,9 @@ 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.luasnippets.tex.utils' - -local is_math = utils.conditions.is_math +local conditions = require 'luasnippets.tex.conditions' +local is_math = conditions.is_math local as = require('luasnip').extend_decorator.apply(s, { snippetType = 'autosnippet' }) local ret = { @@ -50,4 +49,4 @@ local ret = { ), } -return {} +return ret