From 5d609f7cc46816387f7238e120ebdfeb936e9cc8 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Tue, 27 Dec 2022 17:45:05 -0600 Subject: revert(nvim): remove alpha --- nvim/.config/nvim/lua/tobyvin/keymaps.lua | 1 - nvim/.config/nvim/lua/tobyvin/plugins/alpha.lua | 158 --------------------- nvim/.config/nvim/lua/tobyvin/plugins/gitsigns.lua | 8 +- nvim/.config/nvim/lua/tobyvin/utils/buffer.lua | 86 ----------- 4 files changed, 5 insertions(+), 248 deletions(-) delete mode 100644 nvim/.config/nvim/lua/tobyvin/plugins/alpha.lua (limited to 'nvim') diff --git a/nvim/.config/nvim/lua/tobyvin/keymaps.lua b/nvim/.config/nvim/lua/tobyvin/keymaps.lua index 2258162..d767ab2 100644 --- a/nvim/.config/nvim/lua/tobyvin/keymaps.lua +++ b/nvim/.config/nvim/lua/tobyvin/keymaps.lua @@ -14,7 +14,6 @@ vim.keymap.set("n", "gn", "bnext", { desc = "bnext" }) vim.keymap.set("n", "gp", "bprev", { desc = "bprev" }) vim.keymap.set("n", "gk", utils.documentation.open, { desc = "documentation" }) vim.keymap.set("n", "K", hover, { expr = true, desc = "hover" }) -vim.keymap.set("n", "c", utils.buffer.bdelete, { desc = "bdelete" }) vim.keymap.set("n", "", "zz", { desc = "up half page and center" }) vim.keymap.set("n", "", "zz", { desc = "down half page and center" }) vim.keymap.set("n", "", "m +1", { desc = "move line down" }) diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/alpha.lua b/nvim/.config/nvim/lua/tobyvin/plugins/alpha.lua deleted file mode 100644 index 73581ff..0000000 --- a/nvim/.config/nvim/lua/tobyvin/plugins/alpha.lua +++ /dev/null @@ -1,158 +0,0 @@ -local M = { - "goolord/alpha-nvim", - lazy = false, -} - -function M.init() - vim.api.nvim_create_autocmd("User", { - group = vim.api.nvim_create_augroup("alpha_user", { clear = true }), - pattern = "BDeleteLast", - callback = function(args) - local bufnr = vim.F.if_nil(args.data.buf, args.buf) - if vim.api.nvim_buf_get_option(bufnr, "filetype") ~= "alpha" then - require("alpha").start(false) - end - end, - desc = "Run Alpha when last buffer closed", - }) -end - -function M.config() - local alpha = require("alpha") - local utils = require("tobyvin.utils") - local width = 60 - - local file_button = function(filename, sc) - local short_fn = utils.fs.shorten_path(filename, width - 4) - local hl = {} - - local fn_start = short_fn:match(".*[/\\]") - if fn_start ~= nil then - table.insert(hl, { "Comment", 0, #fn_start }) - end - - local edit = function() - vim.cmd.edit(filename) - end - - return { - type = "button", - val = short_fn, - on_press = edit, - opts = { - position = "center", - shortcut = "[" .. sc .. "]", - cursor = width - 2, - width = width, - align_shortcut = "right", - hl = hl, - hl_shortcut = { { "Special", 0, 1 }, { "Number", 1, #sc + 1 }, { "Special", #sc + 1, #sc + 2 } }, - shrink_margin = false, - keymap = { "n", sc:gsub("%s", ""), edit, { desc = "oldfile_" .. sc } }, - }, - } - end - - local mru_filter = function(filename) - local ignored_ft = { "gitcommit" } - local cwd = vim.fn.getcwd() - local filetype, _ = vim.filetype.match({ filename = filename }) - filetype = filetype or "" - local ignored = false - for _, pattern in pairs(ignored_ft) do - ignored = ignored or filetype:match(pattern) ~= nil - end - return not ignored and (vim.fn.filereadable(filename) == 1) and vim.startswith(filename, cwd) - end - - local mru_cache = nil - local get_mru = function() - if mru_cache == nil then - local oldfiles = { unpack(vim.tbl_filter(mru_filter, vim.v.oldfiles), 1, 20) } - local tbl = {} - for i, filename in ipairs(oldfiles) do - tbl[i] = file_button(filename, tostring(i % 10)) - end - mru_cache = { { - type = "group", - val = tbl, - } } - end - return mru_cache - end - - alpha.keymaps_element.button = function(el, _, state) - if el.opts and el.opts.keymap then - if type(el.opts.keymap[1]) == "table" then - for _, map in el.opts.keymap do - map[4].buffer = state.buffer - vim.keymap.set(unpack(map)) - end - else - local map = el.opts.keymap - map[4].buffer = state.buffer - vim.keymap.set(unpack(map)) - end - end - end - - local fortune = require("alpha.fortune") - - local function info_value() - local plugins = require("lazy").stats().count - local v = vim.version() or {} - - local info = string.format("VIM: v%d.%d.%d PLUGINS: %d", v.major, v.minor, v.patch, plugins) - if require("lazy.status").has_updates() then - local updates = require("lazy.status").updates() - info = string.format("%s ( %s )", info, updates) - end - return info - end - - local config = { - layout = { - { - type = "text", - val = { - " ", - " ███╗ ██╗███████╗ ██████╗ ██╗ ██╗██╗███╗ ███╗ ", - " ████╗ ██║██╔════╝██╔═══██╗██║ ██║██║████╗ ████║ ", - " ██╔██╗ ██║█████╗ ██║ ██║██║ ██║██║██╔████╔██║ ", - " ██║╚██╗██║██╔══╝ ██║ ██║╚██╗ ██╔╝██║██║╚██╔╝██║ ", - " ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║ ", - " ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ ", - }, - opts = { - position = "center", - hl = "DevIconVim", - }, - }, - { - type = "text", - val = info_value, - opts = { - hl = "DevIconVim", - position = "center", - }, - }, - { - type = "text", - val = fortune({ max_width = 60 }), - opts = { - position = "center", - hl = "Statement", - }, - }, - { type = "padding", val = 1 }, - { - type = "group", - val = get_mru, - }, - }, - } - - alpha.setup(config) -end - -return M diff --git a/nvim/.config/nvim/lua/tobyvin/plugins/gitsigns.lua b/nvim/.config/nvim/lua/tobyvin/plugins/gitsigns.lua index c8d13a5..3f3e97b 100644 --- a/nvim/.config/nvim/lua/tobyvin/plugins/gitsigns.lua +++ b/nvim/.config/nvim/lua/tobyvin/plugins/gitsigns.lua @@ -7,11 +7,13 @@ local M = { function M.config() local gitsigns = require("gitsigns") - local utils = require("tobyvin.utils") - local with_range = function(callback) return function() - callback(utils.buffer.get_visual_range()) + callback(function() + local start_pos = vim.fn.getpos("v") + local end_pos = vim.fn.getcurpos() + return { start_pos[2], end_pos[2] } + end) end end diff --git a/nvim/.config/nvim/lua/tobyvin/utils/buffer.lua b/nvim/.config/nvim/lua/tobyvin/utils/buffer.lua index 9ddabaa..e3b943c 100644 --- a/nvim/.config/nvim/lua/tobyvin/utils/buffer.lua +++ b/nvim/.config/nvim/lua/tobyvin/utils/buffer.lua @@ -38,90 +38,4 @@ M.popup = function(file_path) vim.api.nvim_buf_set_option(0, "modifiable", false) end -M.bselect = function() - local buffers = vim.tbl_filter(function(bufnr) - return vim.api.nvim_buf_is_valid(bufnr) and vim.bo[bufnr].buflisted - end, vim.api.nvim_list_bufs()) - - local opts = { - prompt = "Switch buffer: ", - format_item = function(bufnr) - local path = vim.api.nvim_buf_get_name(bufnr) - local relpath = Path:new(path):make_relative() - return string.format("%s: %s", bufnr, relpath) - end, - } - - vim.ui.select(buffers, opts, function(_, idx) - if idx ~= nil then - vim.api.nvim_set_current_buf(buffers[idx]) - end - end) -end - ---- @class BdeleteOptions ---- @field force boolean Force deletion and ignore unsaved changes. ---- @field unload boolean Unloaded only, do not delete. See |:bunload| - ---- Wrapper around nvim_buf_delete that preserves window layout ---- @param buffer number? Buffer handle, or 0 for current buffer ---- @param opts BdeleteOptions? Optional parameters -M.bdelete = function(buffer, opts) - if buffer == nil then - buffer = vim.fn.bufnr() - end - - if opts == nil then - opts = { - force = false, - unload = true, - } - end - - if not opts.force and vim.bo[buffer].modified then - local bufname = vim.fn.bufname() - - return vim.ui.select({ "write", "discard", "abort" }, { - prompt = string.format("No write since last change for buffer %s:", bufname), - kind = "select_normal", - }, function(_, idx) - if idx == 1 then - vim.cmd("write") - M.bdelete(buffer) - elseif idx == 2 then - M.bdelete(buffer, { force = true }) - else - vim.notify( - string.format("No write since last change for buffer %d", bufname), - vim.log.levels.ERROR, - { title = "Aborting..." } - ) - end - end) - end - - local is_last_buffer = true - if vim.bo[buffer].buflisted then - ---@diagnostic disable-next-line: param-type-mismatch - local windows = vim.fn.getbufinfo(buffer)[1].windows - - for _, window in ipairs(windows) do - local alt_buffer = vim.fn.bufnr("#") - if vim.api.nvim_buf_is_valid(alt_buffer) and vim.bo[alt_buffer].buflisted then - vim.api.nvim_win_set_buf(window, alt_buffer) - is_last_buffer = false - end - end - end - - if is_last_buffer and (#vim.fn.getbufinfo({ buflisted = 1 }) == 1) then - vim.api.nvim_exec_autocmds("User", { pattern = "BDeleteLast", data = { buf = buffer } }) - end - - if vim.api.nvim_buf_is_valid(buffer) then - vim.bo[buffer].buflisted = false - pcall(vim.api.nvim_buf_delete, buffer, opts) - end -end - return M -- cgit v1.2.3-70-g09d2