From 6093a012761a2c22e399bffca569be539b15dadf Mon Sep 17 00:00:00 2001 From: Citlali del Rey Date: Tue, 6 Feb 2024 23:03:12 -0800 Subject: [PATCH] Updates, change vim keybinds --- fish/config.fish | 1 + mpd.conf | 2 +- nvim/init.vim | 17 +++++++ nvim/lua/lsp.lua | 8 +++- nvim/lua/snip_util.lua | 15 ++++++ nvim/lua/tex_tsutil.lua | 73 ++++++++++++++++++++++++++++++ nvim/luasnippets/all.lua | 0 nvim/luasnippets/tex/math_auto.lua | 16 +++++++ nvim/luasnippets/tex/text_auto.lua | 24 ++++++++++ 9 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 nvim/lua/snip_util.lua create mode 100644 nvim/lua/tex_tsutil.lua create mode 100644 nvim/luasnippets/all.lua create mode 100644 nvim/luasnippets/tex/math_auto.lua create mode 100644 nvim/luasnippets/tex/text_auto.lua diff --git a/fish/config.fish b/fish/config.fish index 308cc49..4cbaf72 100644 --- a/fish/config.fish +++ b/fish/config.fish @@ -12,6 +12,7 @@ fish_add_path -a /opt/homebrew/bin "/opt/homebrew/sbin" fish_add_path ~/Library/bin fish_add_path ~/Library/Application\ Support/Cargo/bin fish_add_path ~/.dotnet/tools +fish_add_path ~/Library/Application\ Support/Go/bin set -gx HOMEBREW_PREFIX "/opt/homebrew"; set -gx HOMEBREW_CELLAR "/opt/homebrew/Cellar"; diff --git a/mpd.conf b/mpd.conf index 3ec1355..5f1a875 100644 --- a/mpd.conf +++ b/mpd.conf @@ -365,7 +365,7 @@ audio_output { type "osx" name "CoreAudio Default" mixer_type "software" - replay_gain_handler "none" + replay_gain_handler "software" hog_device "no" enabled "yes" always_on "no" diff --git a/nvim/init.vim b/nvim/init.vim index f7d5799..68bf9ec 100644 --- a/nvim/init.vim +++ b/nvim/init.vim @@ -113,3 +113,20 @@ nnoremap fh Telescope help_tags filetype plugin on filetype indent on + +" Use Skim as the VimTeX PDF viewer +let g:vimtex_view_method = 'skim' + +" press to expand or jump in a snippet. These can also be mapped separately +" via luasnip-expand-snippet and luasnip-jump-next. +imap luasnip#expand_or_jumpable() ? 'luasnip-expand-or-jump' : '' +" -1 for jumping backwards. +inoremap lua require'luasnip'.jump(-1) + +snoremap lua require('luasnip').jump(1) +snoremap lua require('luasnip').jump(-1) + +" For changing choices in choiceNodes (not strictly necessary for a basic setup). +imap luasnip#choice_active() ? 'luasnip-next-choice' : '' +smap luasnip#choice_active() ? 'luasnip-next-choice' : '' + diff --git a/nvim/lua/lsp.lua b/nvim/lua/lsp.lua index c1f82f4..0a27afd 100644 --- a/nvim/lua/lsp.lua +++ b/nvim/lua/lsp.lua @@ -64,6 +64,7 @@ local lspkind = require('lspkind') luasnip.config.set_config { region_check_events = {'CursorMoved', 'InsertEnter'}, delete_check_events = {'TextChanged', 'InsertLeave'}, + enable_autosnippets = true, } cmp.setup { @@ -79,10 +80,13 @@ cmp.setup { mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - [''] = cmp.mapping(function(fallback) + + --[[[''] = cmp.mapping(function(fallback) if luasnip.expandable() then luasnip.expand() elseif cmp.visible() then @@ -105,7 +109,7 @@ cmp.setup { else fallback() end - end, {"i", "s", "c"}), + end, {"i", "s", "c"}),]] }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, diff --git a/nvim/lua/snip_util.lua b/nvim/lua/snip_util.lua new file mode 100644 index 0000000..c04a086 --- /dev/null +++ b/nvim/lua/snip_util.lua @@ -0,0 +1,15 @@ +local M = {} + +M.pipe = function(fns) + return function(...) + for _, fn in ipairs(fns) do + if not fn(...) then + return false + end + end + + return true + end +end + +return M diff --git a/nvim/lua/tex_tsutil.lua b/nvim/lua/tex_tsutil.lua new file mode 100644 index 0000000..29430c5 --- /dev/null +++ b/nvim/lua/tex_tsutil.lua @@ -0,0 +1,73 @@ +local M = {} + +local MATH_NODES = { + displayed_equation = true, + inline_formula = true, + math_environment = true, +} + +local TEXT_NODES = { + text_mode = true, + label_definition = true, + label_reference = true, +} + +local function get_node_at_cursor() + local pos = vim.api.nvim_win_get_cursor(0) + -- Subtract one to account for 1-based row indexing in nvim_win_get_cursor + local row, col = pos[1] - 1, pos[2] + + local parser = vim.treesitter.get_parser(0, "latex") + if not parser then + return + end + + local root_tree = parser:parse({ row, col, row, col })[1] + local root = root_tree and root_tree:root() + if not root then + return + end + + return root:named_descendant_for_range(row, col, row, col) +end + +function M.in_text() + local node = get_node_at_cursor() + while node do + if node:type() == "text_mode" then + --if check_parent then + -- For \text{} + local parent = node:parent() + if parent and MATH_NODES[parent:type()] then + return false + end + --end + + return true + elseif MATH_NODES[node:type()] then + return false + end + node = node:parent() + end + return true +end + +function M.in_mathzone() + local node = get_node_at_cursor() + while node do + if TEXT_NODES[node:type()] then + return false + elseif MATH_NODES[node:type()] then + return true + end + node = node:parent() + end + return false +end + +M.no_backslash = function(line_to_cursor, matched_trigger) + return not line_to_cursor:find("\\%a+$", -#line_to_cursor) +end + +return M + diff --git a/nvim/luasnippets/all.lua b/nvim/luasnippets/all.lua new file mode 100644 index 0000000..e69de29 diff --git a/nvim/luasnippets/tex/math_auto.lua b/nvim/luasnippets/tex/math_auto.lua new file mode 100644 index 0000000..a6271a1 --- /dev/null +++ b/nvim/luasnippets/tex/math_auto.lua @@ -0,0 +1,16 @@ +local ls = require("luasnip") +local util = require("tex_tsutil") + +return { +ls.snippet( + { + trig = "df", + wordTrig = false, + name = "diff", + snippetType = "autosnippet", + condition = util.in_mathzone, + }, { + t("\\diff "), + } +), +} diff --git a/nvim/luasnippets/tex/text_auto.lua b/nvim/luasnippets/tex/text_auto.lua new file mode 100644 index 0000000..bfed423 --- /dev/null +++ b/nvim/luasnippets/tex/text_auto.lua @@ -0,0 +1,24 @@ +local ls = require("luasnip") +local tu = require("tex_tsutil") +local su = require("snip_util") + +local conds = require("luasnip.extras.expand_conditions") + +local cond = su.pipe({ conds.line_begin, tu.in_text }) + + +-- Use extend_decorator to add the same condition to all. +local s = ls.extend_decorator.apply(ls.snippet, { + condition = cond, + snippetType = "autosnippet", +}) + +local ps = ls.extend_decorator.apply(ls.parser.parse_snippet, { + condition = cond, + snippetType = "autosnippet", +}) + +return { + ps({ trig = "bgn", name = "Environment"}, + "\\begin{$1}\n\t$0\n\\end{$1}"), +}