kitchen sink:
- add code action previews - change indent blankline style - more luasnip snippets - change default mason stuff - customize neorg more - change notify style - change startpage completely - add line info to statusline - change telescope style - change how todo comments look - make indentation work via treesitter
This commit is contained in:
@ -1,8 +1,6 @@
|
||||
if not pcall(require, "el") then
|
||||
return
|
||||
end
|
||||
if not pcall(require, "el") then return end
|
||||
|
||||
local Job = require "plenary.job"
|
||||
local job = require "plenary.job"
|
||||
local el_sub = require "el.subscribe"
|
||||
|
||||
local M = {}
|
||||
@ -71,14 +69,14 @@ local function wrap_fnc(opts, fn)
|
||||
window = { win_id = vim.fn.bufwinid(buffer.bufnr) }
|
||||
end
|
||||
if opts.hide_inactive and window and
|
||||
window.win_id ~= vim.api.nvim_get_current_win() then
|
||||
window.win_id ~= vim.api.nvim_get_current_win() then
|
||||
return ""
|
||||
end
|
||||
return fn(window, buffer)
|
||||
end
|
||||
end
|
||||
|
||||
M.mode = function(opts)
|
||||
function M.mode(opts)
|
||||
opts = opts or {}
|
||||
return wrap_fnc(opts, function(_, _)
|
||||
local fmt = opts.fmt or "%s%s"
|
||||
@ -92,79 +90,49 @@ M.mode = function(opts)
|
||||
end)
|
||||
end
|
||||
|
||||
M.try_devicons = function()
|
||||
if not M._has_devicons then
|
||||
M._has_devicons, M._devicons = pcall(require, "nvim-web-devicons")
|
||||
end
|
||||
return M._devicons
|
||||
end
|
||||
|
||||
M.file_icon = function(opts)
|
||||
opts = opts or {}
|
||||
return el_sub.buf_autocmd("el_file_icon", "BufRead",
|
||||
wrap_fnc(opts, function(_, buffer)
|
||||
if not M.try_devicons() then return "" end
|
||||
local fmt = opts.fmt or "%s"
|
||||
local ext = vim.fn.fnamemodify(buffer.name, ":p:e")
|
||||
local icon, hl = M._devicons.get_icon(buffer.name, ext:lower(), { default = true })
|
||||
-- local icon = extensions.file_icon(_, bufnr)
|
||||
if icon then
|
||||
if opts.hl_icon then
|
||||
local hlgroup = M.extract_hl({
|
||||
bg = { StatusLine = "bg" },
|
||||
fg = { [hl] = "fg" },
|
||||
})
|
||||
icon = set_hl(hlgroup, icon)
|
||||
end
|
||||
return (fmt):format(icon)
|
||||
end
|
||||
return ""
|
||||
end))
|
||||
end
|
||||
|
||||
M.git_branch = function(opts)
|
||||
function M.git_branch(opts)
|
||||
opts = opts or {}
|
||||
return el_sub.buf_autocmd("el_git_branch", "BufEnter",
|
||||
wrap_fnc(opts, function(_, buffer)
|
||||
-- Try fugitive first as it's most reliable
|
||||
local branch = vim.g.loaded_fugitive == 1 and
|
||||
vim.fn.FugitiveHead() or nil
|
||||
-- buffer can be null and code will crash with:
|
||||
-- E5108: Error executing lua ... 'attempt to index a nil value'
|
||||
if not buffer or not (buffer.bufnr > 0) then
|
||||
return
|
||||
end
|
||||
-- fugitive is empty or not loaded, try gitsigns
|
||||
if not branch or #branch == 0 then
|
||||
local ok, res = pcall(vim.api.nvim_buf_get_var,
|
||||
buffer.bufnr, "gitsigns_head")
|
||||
if ok then branch = res end
|
||||
end
|
||||
-- last resort run git command
|
||||
if not branch then
|
||||
local j = Job:new {
|
||||
command = "git",
|
||||
args = { "branch", "--show-current" },
|
||||
cwd = vim.fn.fnamemodify(buffer.name, ":h"),
|
||||
}
|
||||
wrap_fnc(opts, function(_, buffer)
|
||||
-- Try fugitive first as it's most reliable
|
||||
local branch = vim.g.loaded_fugitive == 1 and
|
||||
vim.fn.FugitiveHead() or nil
|
||||
-- buffer can be null and code will crash with:
|
||||
-- E5108: Error executing lua ... 'attempt to index a nil value'
|
||||
if not buffer or not (buffer.bufnr > 0) then
|
||||
return
|
||||
end
|
||||
-- fugitive is empty or not loaded, try gitsigns
|
||||
if not branch or #branch == 0 then
|
||||
local ok, res = pcall(vim.api.nvim_buf_get_var,
|
||||
buffer.bufnr, "gitsigns_head")
|
||||
if ok then branch = res end
|
||||
end
|
||||
-- last resort run git command
|
||||
if not branch then
|
||||
local j = job:new {
|
||||
command = "git",
|
||||
args = { "branch", "--show-current" },
|
||||
cwd = vim.fn.fnamemodify(buffer.name, ":h"),
|
||||
}
|
||||
|
||||
local ok, result = pcall(function()
|
||||
return vim.trim(j:sync()[1])
|
||||
end)
|
||||
if ok then
|
||||
branch = result
|
||||
end
|
||||
local ok, result = pcall(function()
|
||||
return vim.trim(j:sync()[1])
|
||||
end)
|
||||
if ok then
|
||||
branch = result
|
||||
end
|
||||
end
|
||||
|
||||
if branch and #branch > 0 then
|
||||
local fmt = opts.fmt or "%s %s"
|
||||
local icon = opts.icon or ""
|
||||
return set_hl(opts.hl, (fmt):format(icon, branch))
|
||||
end
|
||||
end))
|
||||
if branch and #branch > 0 then
|
||||
local fmt = opts.fmt or "%s %s"
|
||||
local icon = opts.icon or ""
|
||||
return set_hl(opts.hl, (fmt):format(icon, branch))
|
||||
end
|
||||
end))
|
||||
end
|
||||
|
||||
local git_changes_formatter = function(opts)
|
||||
local function git_changes_formatter(opts)
|
||||
local specs = {
|
||||
insert = {
|
||||
regex = "(%d+) insertions?",
|
||||
@ -198,24 +166,24 @@ local git_changes_formatter = function(opts)
|
||||
table.insert(result, set_hl(v.hl, ("%s%d"):format(v.icon, count)))
|
||||
end
|
||||
end
|
||||
return table.concat(result, ", ")
|
||||
return table.concat(result, " ")
|
||||
end
|
||||
end
|
||||
|
||||
-- requires gitsigns
|
||||
M.git_changes_buf = function(opts)
|
||||
function M.git_changes_buf(opts)
|
||||
opts = opts or {}
|
||||
local formatter = opts.formatter or git_changes_formatter(opts)
|
||||
return wrap_fnc(opts, function(window, buffer)
|
||||
local stats = {}
|
||||
if buffer and buffer.bufnr > 0 then
|
||||
local ok, res = pcall(vim.api.nvim_buf_get_var,
|
||||
buffer.bufnr, "vgit_status")
|
||||
buffer.bufnr, "vgit_status")
|
||||
if ok then stats = res end
|
||||
end
|
||||
if buffer and buffer.bufnr > 0 then
|
||||
local ok, res = pcall(vim.api.nvim_buf_get_var,
|
||||
buffer.bufnr, "gitsigns_status_dict")
|
||||
buffer.bufnr, "gitsigns_status_dict")
|
||||
if ok then stats = res end
|
||||
end
|
||||
local counts = {
|
||||
@ -235,82 +203,79 @@ M.git_changes_buf = function(opts)
|
||||
end)
|
||||
end
|
||||
|
||||
M.git_changes_all = function(opts)
|
||||
function M.git_changes_all(opts)
|
||||
opts = opts or {}
|
||||
local formatter = opts.formatter or git_changes_formatter(opts)
|
||||
return el_sub.buf_autocmd("el_git_changes", "BufWritePost",
|
||||
wrap_fnc(opts, function(window, buffer)
|
||||
if not buffer or
|
||||
not (buffer.bufnr > 0) or
|
||||
vim.bo[buffer.bufnr].bufhidden ~= "" or
|
||||
vim.bo[buffer.bufnr].buftype == "nofile" or
|
||||
vim.fn.filereadable(buffer.name) ~= 1 then
|
||||
return
|
||||
end
|
||||
wrap_fnc(opts, function(window, buffer)
|
||||
if not buffer or
|
||||
not (buffer.bufnr > 0) or
|
||||
vim.bo[buffer.bufnr].bufhidden ~= "" or
|
||||
vim.bo[buffer.bufnr].buftype == "nofile" or
|
||||
vim.fn.filereadable(buffer.name) ~= 1 then
|
||||
return
|
||||
end
|
||||
|
||||
local j = Job:new {
|
||||
command = "git",
|
||||
args = { "diff", "--shortstat" },
|
||||
-- makes no sense to run for one file as
|
||||
-- 'file(s) changed' will always be 1
|
||||
-- args = { "diff", "--shortstat", buffer.name },
|
||||
cwd = vim.fn.fnamemodify(buffer.name, ":h"),
|
||||
}
|
||||
local j = job:new {
|
||||
command = "git",
|
||||
args = { "diff", "--shortstat" },
|
||||
-- makes no sense to run for one file as
|
||||
-- 'file(s) changed' will always be 1
|
||||
-- args = { "diff", "--shortstat", buffer.name },
|
||||
cwd = vim.fn.fnamemodify(buffer.name, ":h"),
|
||||
}
|
||||
|
||||
local ok, git_changes = pcall(function()
|
||||
return formatter(window, buffer, vim.trim(j:sync()[1]))
|
||||
end)
|
||||
local ok, git_changes = pcall(function()
|
||||
return formatter(window, buffer, vim.trim(j:sync()[1]))
|
||||
end)
|
||||
|
||||
if ok then
|
||||
local fmt = opts.fmt or "%s"
|
||||
return git_changes and fmt:format(git_changes) or nil
|
||||
end
|
||||
end))
|
||||
if ok then
|
||||
local fmt = opts.fmt or "%s"
|
||||
return git_changes and fmt:format(git_changes) or nil
|
||||
end
|
||||
end))
|
||||
end
|
||||
|
||||
local function lsp_srvname(bufnr)
|
||||
local buf_clients = vim.lsp.buf_get_clients(bufnr)
|
||||
function M.lsp_srvname(opts)
|
||||
local fmt = opts.fmt or "%s"
|
||||
local icon = opts.icon or ""
|
||||
local buf_clients = vim.lsp.buf_get_clients(0)
|
||||
if not buf_clients or #buf_clients == 0 then
|
||||
return nil
|
||||
return ""
|
||||
end
|
||||
local names = ""
|
||||
for i, c in ipairs(buf_clients) do
|
||||
if i > 1 then names = names .. ", " end
|
||||
names = names .. c.name
|
||||
end
|
||||
return names
|
||||
return icon..fmt:format(names)
|
||||
end
|
||||
|
||||
local function diag_formatter(opts)
|
||||
return function(_, buffer, counts)
|
||||
local items = {}
|
||||
local icons = {
|
||||
["errors"] = { opts.icon_err or "E", opts.hl_err },
|
||||
["warnings"] = { opts.icon_warn or "W", opts.hl_warn },
|
||||
["infos"] = { opts.icon_info or "I", opts.hl_info },
|
||||
["hints"] = { opts.icon_hint or "H", opts.hl_hint },
|
||||
["errors"] = { opts.icon_err or "x", opts.hl_err or "DiagnosticError"},
|
||||
["warnings"] = { opts.icon_warn or "!", opts.hl_warn or "DiagnosticWarn"},
|
||||
["infos"] = { opts.icon_info or "i", opts.hl_info or "DiagnosticInfo"},
|
||||
["hints"] = { opts.icon_hint or "h", opts.hl_hint or "DiagnosticHint"},
|
||||
}
|
||||
for _, k in ipairs({ "errors", "warnings", "infos", "hints" }) do
|
||||
if counts[k] > 0 then
|
||||
table.insert(items,
|
||||
set_hl(icons[k][2], ("%s:%s"):format(icons[k][1], counts[k])))
|
||||
set_hl(icons[k][2], ("%s:%s"):format(icons[k][1], counts[k])))
|
||||
end
|
||||
end
|
||||
local fmt = opts.fmt or "%s"
|
||||
local lsp_name = opts.lsp and lsp_srvname(buffer.bufnr)
|
||||
if not lsp_name and vim.tbl_isempty(items) then
|
||||
if vim.tbl_isempty(items) then
|
||||
return ""
|
||||
else
|
||||
local contents = lsp_name
|
||||
if not vim.tbl_isempty(items) then
|
||||
contents = ("%s %s"):format(lsp_name, table.concat(items, " "))
|
||||
end
|
||||
return fmt:format(contents)
|
||||
return fmt:format(table.concat(items, " "))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local get_buffer_counts = function(diagnostic, _, buffer)
|
||||
local function get_buffer_counts(diagnostic, _, buffer)
|
||||
local counts = { 0, 0, 0, 0 }
|
||||
local diags = diagnostic.get(buffer.bufnr)
|
||||
if diags and not vim.tbl_isempty(diags) then
|
||||
@ -328,13 +293,23 @@ local get_buffer_counts = function(diagnostic, _, buffer)
|
||||
}
|
||||
end
|
||||
|
||||
M.diagnostics = function(opts)
|
||||
function M.diagnostics(opts)
|
||||
opts = opts or {}
|
||||
local formatter = opts.formatter or diag_formatter(opts)
|
||||
return el_sub.buf_autocmd("el_buf_diagnostic", "LspAttach,DiagnosticChanged",
|
||||
wrap_fnc(opts, function(window, buffer)
|
||||
return formatter(window, buffer, get_buffer_counts(vim.diagnostic, window, buffer))
|
||||
end))
|
||||
wrap_fnc(opts, function(window, buffer)
|
||||
return formatter(window, buffer, get_buffer_counts(vim.diagnostic, window, buffer))
|
||||
end))
|
||||
end
|
||||
|
||||
function M.line(opts)
|
||||
opts = opts or {}
|
||||
local fmt = opts.fmt or "%s"
|
||||
return wrap_fnc(opts, function(_, _)
|
||||
local al = vim.api.nvim_buf_line_count(0)
|
||||
local cl = vim.api.nvim_win_get_cursor(0)[1]
|
||||
return (fmt):format(cl.."/"..al.." "..math.floor((cl / al) * 100).."%%")
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
|
Reference in New Issue
Block a user