From 9b36254735c26f806ffa79e97e4e65120de4a012 Mon Sep 17 00:00:00 2001 From: benbrastmckie Date: Fri, 20 Dec 2024 19:39:11 -0800 Subject: [PATCH] added lean --- nvim/after/ftplugin/lean.lua | 1 + nvim/lua/neotex/core/functions.lua | 14 +++++ nvim/lua/neotex/core/init.lua | 4 +- nvim/lua/neotex/core/keymaps.lua | 2 + nvim/lua/neotex/core/options.lua | 1 + nvim/lua/neotex/deprecated/float-term.lua | 57 ++++++++++++++++++++ nvim/lua/neotex/plugins/bufferline.lua | 15 +++--- nvim/lua/neotex/plugins/lean.lua | 63 +++++++++++++++++++++-- nvim/lua/neotex/plugins/lsp/lspconfig.lua | 16 ------ nvim/lua/neotex/plugins/toggleterm.lua | 31 +---------- nvim/lua/neotex/plugins/which-key.lua | 23 +++++++-- 11 files changed, 166 insertions(+), 61 deletions(-) create mode 100644 nvim/after/ftplugin/lean.lua create mode 100644 nvim/lua/neotex/deprecated/float-term.lua diff --git a/nvim/after/ftplugin/lean.lua b/nvim/after/ftplugin/lean.lua new file mode 100644 index 00000000..f3a95c99 --- /dev/null +++ b/nvim/after/ftplugin/lean.lua @@ -0,0 +1 @@ +vim.opt_local.spell = false diff --git a/nvim/lua/neotex/core/functions.lua b/nvim/lua/neotex/core/functions.lua index d0671b81..951d55cf 100644 --- a/nvim/lua/neotex/core/functions.lua +++ b/nvim/lua/neotex/core/functions.lua @@ -2,3 +2,17 @@ function SearchWordUnderCursor() local word = vim.fn.expand('') require('telescope.builtin').live_grep({ default_text = word }) end + +function CloseBuffer() + local current = vim.api.nvim_get_current_buf() + vim.cmd('bdelete') -- Close the current buffer + + -- Get a list of all listed buffers + local buffers = vim.api.nvim_list_bufs() + for _, buf in ipairs(buffers) do + if vim.api.nvim_buf_is_loaded(buf) and vim.bo[buf].buflisted then + vim.api.nvim_set_current_buf(buf) + break + end + end +end diff --git a/nvim/lua/neotex/core/init.lua b/nvim/lua/neotex/core/init.lua index 084800dc..55e32431 100644 --- a/nvim/lua/neotex/core/init.lua +++ b/nvim/lua/neotex/core/init.lua @@ -1,4 +1,4 @@ -require("neotex.core.keymaps") -require("neotex.core.options") require("neotex.core.autocmds") require("neotex.core.functions") +require("neotex.core.keymaps") +require("neotex.core.options") diff --git a/nvim/lua/neotex/core/keymaps.lua b/nvim/lua/neotex/core/keymaps.lua index 724ba904..2beab68b 100644 --- a/nvim/lua/neotex/core/keymaps.lua +++ b/nvim/lua/neotex/core/keymaps.lua @@ -35,6 +35,8 @@ keymap("n", "gcc", "", opts) -- Surround -- vim.keymap.set("v", '', 'S', { remap = true }) -- see surround.lua +-- Terminal +vim.keymap.set("n", "", "Floaterminal", { remap = true }) -- Spelling vim.keymap.set("n", "", function() diff --git a/nvim/lua/neotex/core/options.lua b/nvim/lua/neotex/core/options.lua index bd5114ed..09c2daca 100644 --- a/nvim/lua/neotex/core/options.lua +++ b/nvim/lua/neotex/core/options.lua @@ -17,6 +17,7 @@ local options = { relativenumber = true, -- set relative numbered lines numberwidth = 2, -- set number column width to 2 {default 4} signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time + fillchars = "eob: ", -- don't show tildes cursorline = true, -- highlight the current line -- colorcolumn = "100", -- highlight vertical colorcolumn (moved to after/python.lua) wrap = true, -- display lines as one long line diff --git a/nvim/lua/neotex/deprecated/float-term.lua b/nvim/lua/neotex/deprecated/float-term.lua new file mode 100644 index 00000000..53f7bdb7 --- /dev/null +++ b/nvim/lua/neotex/deprecated/float-term.lua @@ -0,0 +1,57 @@ +vim.keymap.set("t", "", "") + +local state = { + floating = { + buf = -1, + win = -1, + } +} + +local function create_floating_window(opts) + opts = opts or {} + local width = opts.width or math.floor(vim.o.columns * 0.8) + local height = opts.height or math.floor(vim.o.lines * 0.8) + + -- Calculate the position to center the window + local col = math.floor((vim.o.columns - width) / 2) + local row = math.floor((vim.o.lines - height) / 2) + + -- Create a buffer + local buf = nil + if vim.api.nvim_buf_is_valid(opts.buf) then + buf = opts.buf + else + buf = vim.api.nvim_create_buf(false, true) -- No file, scratch buffer + end + + -- Define window configuration + local win_config = { + relative = "editor", + width = width, + height = height, + col = col, + row = row, + style = "minimal", -- No borders or extra UI elements + border = "rounded", + } + + -- Create the floating window + local win = vim.api.nvim_open_win(buf, true, win_config) + + return { buf = buf, win = win } +end + +local toggle_terminal = function() + if not vim.api.nvim_win_is_valid(state.floating.win) then + state.floating = create_floating_window { buf = state.floating.buf } + if vim.bo[state.floating.buf].buftype ~= "terminal" then + vim.cmd.terminal() + end + else + vim.api.nvim_win_hide(state.floating.win) + end +end + +-- Example usage: +-- Create a floating window with default dimensions +vim.api.nvim_create_user_command("Floaterminal", toggle_terminal, {}) diff --git a/nvim/lua/neotex/plugins/bufferline.lua b/nvim/lua/neotex/plugins/bufferline.lua index 44faa552..709daab4 100644 --- a/nvim/lua/neotex/plugins/bufferline.lua +++ b/nvim/lua/neotex/plugins/bufferline.lua @@ -8,17 +8,20 @@ return { options = { mode = "buffers", separator_style = "slant", - close_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + close_command = "bdelete! %d", -- can be a string | function, see "Mouse actions" + right_mouse_command = "bdelete! %d", -- can be a string | function | false, see "Mouse actions" diagnostics = false, -- OR: | "nvim_lsp" diagnostics_update_in_insert = false, show_tab_indicators = false, show_close_icon = false, -- numbers = "ordinal", -- Display buffer numbers as ordinal numbers - sort_by = 'insert_after_current', -- OR: 'insert_at_end' | 'tabs' | 'extension' | 'relative_directory' | 'directory' | 'id' | - -- sort_by = function(buffer_a, buffer_b) - -- -- -- add custom logic - -- return buffer_a.ordinal < buffer_b.ordinal - -- end, + -- sort_by = 'insert_after_current', -- OR: 'insert_at_end' | 'tabs' | 'extension' | 'relative_directory' | 'directory' | 'id' | + sort_by = function(buffer_a, buffer_b) + -- add custom logic + local modified_a = vim.fn.getftime(buffer_a.path) + local modified_b = vim.fn.getftime(buffer_b.path) + return modified_a > modified_b + end, offsets = { { filetype = "NvimTree", diff --git a/nvim/lua/neotex/plugins/lean.lua b/nvim/lua/neotex/plugins/lean.lua index 40f724aa..4187b77e 100644 --- a/nvim/lua/neotex/plugins/lean.lua +++ b/nvim/lua/neotex/plugins/lean.lua @@ -4,12 +4,67 @@ return { dependencies = { 'neovim/nvim-lspconfig', 'nvim-lua/plenary.nvim', - -- you also will likely want nvim-cmp or some completion engine + 'hrsh7th/nvim-cmp', -- Completion engine + 'hrsh7th/cmp-nvim-lsp', -- LSP source for nvim-cmp + -- 'saadparwaiz1/cmp_luasnip', -- Snippet source for nvim-cmp (optional) + 'L3MON4D3/LuaSnip', -- Snippet engine (optional) }, - -- see details below for full configuration options + -- Configuration options for lean.nvim opts = { lsp = {}, - mappings = true, - } + abbreviations = { + enabled = false + }, + -- -- For notifications + -- stderr = { + -- enable = true, + -- on_lines = function(lines) vim.notify(lines) end + -- }, + mappings = true, -- Enable default key mappings + infoview = { + autoopen = true, + } + }, + + -- Configuration function to set up lean.nvim and related settings + config = function(_, opts) + -- Initialize lean.nvim with the provided options + require('lean').setup(opts) + + -- Prevent Infoview Buffer from Appearing in Buffer Lists + vim.api.nvim_create_autocmd("FileType", { + pattern = "leaninfo", -- Infoview buffer filetype + callback = function() + -- Set buffer options to exclude it from buffer lists and normal operations + vim.bo.buflisted = false -- Exclude from buffer lists + vim.bo.bufhidden = "hide" -- Hide the buffer when it's no longer displayed + vim.bo.buftype = "nofile" -- Specify that it's not associated with a file + -- Optional: Prevent modifications to the Infoview buffer + vim.bo.modifiable = false + vim.bo.swapfile = false + end, + group = vim.api.nvim_create_augroup("LeanInfoViewSettings", { clear = true }), + }) + + -- Create an augroup for Lean-related autocommands + local lean_group = vim.api.nvim_create_augroup("LeanCloseInfoview", { clear = true }) + + -- Define the autocommand to close Infoview on BufDelete for Lean files + vim.api.nvim_create_autocmd("BufDelete", { + group = lean_group, + pattern = "*.lean", -- Adjust the pattern if your Lean files have different extensions + callback = function() + -- Attempt to require the lean.infoview module safely + local ok, infoview = pcall(require, "lean.infoview") + if ok and infoview and infoview.close then + infoview.close() + else + -- Optional: Print a warning if the Infoview module isn't available + vim.notify("Failed to close Lean Infoview: lean.infoview module not found", vim.log.levels.WARN) + end + end, + }) + + end } diff --git a/nvim/lua/neotex/plugins/lsp/lspconfig.lua b/nvim/lua/neotex/plugins/lsp/lspconfig.lua index 447cbbc9..f63a0465 100644 --- a/nvim/lua/neotex/plugins/lsp/lspconfig.lua +++ b/nvim/lua/neotex/plugins/lsp/lspconfig.lua @@ -22,22 +22,6 @@ return { vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) end - -- -- configure html server - -- lspconfig["html"].setup({ - -- capabilities = default, - -- }) - - -- -- configure typescript server with plugin - -- lspconfig["tsserver"].setup({ - -- capabilities = default, - -- }) - - -- -- configure emmet language server - -- lspconfig["emmet_ls"].setup({ - -- capabilities = default, - -- filetypes = { "html", "typescriptreact", "javascriptreact" }, -- , "css", "sass", "scss", "less", "svelte" - -- }) - -- configure python server lspconfig["pyright"].setup({ capabilities = default, diff --git a/nvim/lua/neotex/plugins/toggleterm.lua b/nvim/lua/neotex/plugins/toggleterm.lua index 69dbbd50..780c2c83 100644 --- a/nvim/lua/neotex/plugins/toggleterm.lua +++ b/nvim/lua/neotex/plugins/toggleterm.lua @@ -22,38 +22,9 @@ return { background = "Normal", }, }, - -- on_create = fun(t: Terminal), -- function to run when the terminal is first created - -- on_open = fun(t: Terminal), -- function to run when the terminal opens - -- on_close = fun(t: Terminal), -- function to run when the terminal closes - -- on_stdout = fun(t: Terminal, job: number, data: string[], name: string) -- callback for processing output on stdout - -- on_stderr = fun(t: Terminal, job: number, data: string[], name: string) -- callback for processing output on stderr - -- on_exit = fun(t: Terminal, job: number, exit_code: number, name: string) -- function to run when terminal process exits - -- shade_filetypes = {}, - -- autochdir = false, -- when neovim changes it current directory the terminal will change it's own when next it's opened - -- highlights = { - -- -- highlights which map to a highlight group name and a table of it's values - -- -- NOTE: this is only a subset of values, any group placed here will be set for the terminal window split - -- Normal = { - -- guibg = "", - -- }, - -- NormalFloat = { - -- link = 'Normal' - -- }, - -- FloatBorder = { - -- guifg = "", - -- guibg = "", - -- }, - -- }, terminal_mappings = true, -- whether or not the open mapping applies in the opened terminals - persist_mode = false, -- if set to true (default) the previous terminal mode will be remembered + persist_mode = true, -- if set to true (default) the previous terminal mode will be remembered auto_scroll = true, -- automatically scroll to the bottom on terminal output - -- This field is only relevant if direction is set to 'float' - -- winbar = { - -- enabled = false, - -- name_formatter = function(term) -- term: Terminal - -- return term.name - -- end - -- }, } end } diff --git a/nvim/lua/neotex/plugins/which-key.lua b/nvim/lua/neotex/plugins/which-key.lua index a9c4c42b..3303b678 100644 --- a/nvim/lua/neotex/plugins/which-key.lua +++ b/nvim/lua/neotex/plugins/which-key.lua @@ -83,6 +83,7 @@ return { c = { "vert sb", "create split" }, -- k = { "clo", "kill split" }, d = { "update! | bdelete!", "delete buffer" }, + -- d = { ":lua CloseBuffer()", "delete buffer" }, e = { "NvimTreeToggle", "explorer" }, j = { "clo", "drop split" }, -- h = { "Alpha", "home" }, @@ -98,25 +99,27 @@ return { a = { "lua PdfAnnots()", "annotate" }, b = { "terminal bibexport -o %:p:r.bib %:p:r.aux", "bib export" }, c = { ":VimtexClearCache All", "clear vimtex" }, - e = { "e ~/.config/nvim/snippets/tex.snippets", "edit snippets" }, + e = { "VimtexErrors", "error report" }, f = { "lua vim.lsp.buf.format()", "format" }, g = { "e ~/.config/nvim/templates/Glossary.tex", "edit glossary" }, -- h = { "lua _HTOP_TOGGLE()", "htop" }, h = { "LocalHighlightToggle", "highlight" }, k = { "VimtexClean", "kill aux" }, + l = { "LeanInfoviewToggle", "lean info" }, -- l = { "lua vim.g.cmptoggle = not vim.g.cmptoggle", "LSP" }, -- m = { "MarkdownPreview", "markdown preview" }, m = { "TermExec cmd='python3 /home/benjamin/Documents/Philosophy/Projects/ModelChecker/Code/src/model_checker %:p:r.py'", "model checker" }, p = { "TermExec cmd='python %:p:r.py'", "python" }, - r = { "VimtexErrors", "report errors" }, + r = { "AutolistRecalculate", "reorder list" }, t = { "terminal latexindent -w %:p:r.tex", "tex format" }, u = { "cd %:p:h", "update cwd" }, v = { "(vimtex-context-menu)", "vimtex menu" }, w = { "VimtexCountWords!", "word count" }, -- w = { "TermExec cmd='pandoc %:p -o %:p:r.docx'" , "word"}, -- s = { "lua function() require('cmp_vimtex.search').search_menu() end" , "search citations" }, - s = { "TermExec cmd='ssh brastmck@eofe10.mit.edu'", "ssh" }, + s = { "e ~/.config/nvim/snippets/tex.snippets", "snippets edit" }, + S = { "TermExec cmd='ssh brastmck@eofe10.mit.edu'", "ssh" }, }, f = { name = "FIND", @@ -226,6 +229,20 @@ return { v = { "TermExec cmd='zathura %:p:r.pdf &' open=0", "view" }, -- x = { "echo "run: unoconv -f pdf path-to.docx"" , "word to pdf"}, }, + r = { + name = "RUN", + d = { "function() vim.diagnostic.open_float(0, { scope = 'line', header = false, focus = false }) end", "diagnostics" }, + l = { "vim.diagnostics.setloclist", "locate errors" }, + n = { "function() vim.diagnostic.goto_next{popup_opts = {show_header = false}} end", "next" }, + p = { "function() vim.diagnostic.goto_prev{popup_opts = {show_header = false}} end", "prev" }, + -- map('n', 'gi', 'lua vim.lsp.buf.implementation()') + -- map('n', '', 'lua vim.lsp.buf.signature_help()') + -- map('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()') + -- map('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()') + -- map('n', 'D', 'lua vim.lsp.buf.type_definition()') + -- map('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()') + -- map('n', 'f', 'lua vim.lsp.buf.formatting()')prev{popup_opts = {show_header = false}} end", "previous" }, + }, s = { name = "SURROUND", s = { "(nvim-surround-normal)", "surround" },