vim-settings/neovim/lua/plugins/lualine.lua

98 lines
2.7 KiB
Lua
Raw Normal View History

local M = {}
2021-12-09 06:13:53 +00:00
local utils = require("utils")
-- Only return interesting ffenc (not utf-8[unix])
function M.custom_ffenc()
local enc = vim.bo.fenc
local format = vim.bo.fileformat
if enc ~= "utf-8" or format ~= "unix" then
return enc .. "[" .. format .. "]"
end
2021-10-21 17:24:28 +00:00
return ""
end
function M.mixed_indent()
2021-12-15 17:37:51 +00:00
local mixed = vim.fn.search([[\v^(\t+ | +\t)]], "nw")
if mixed > 0 then
return "i:" .. mixed
end
2021-12-15 17:37:51 +00:00
local space_indent = vim.fn.search([[\v^ +]], "nw")
local tab_indent = vim.fn.search([[\v^\t+]], "nw")
if tab_indent > 0 and space_indent > 0 then
return "i:" .. require("math").max(tab_indent, space_indent)
end
2021-10-21 17:24:28 +00:00
return ""
end
function M.trailing_whitespace()
2021-12-15 17:37:51 +00:00
local line = vim.fn.search([[\s\+$]], "nw")
if line ~= 0 then
return "tw:" .. line
end
2021-10-21 17:24:28 +00:00
return ""
end
-- Configure lualine witha provided theme
function M.config_lualine(theme_name)
-- Theme name transformations
if theme_name == nil then
theme_name = "auto"
2021-09-28 01:00:17 +00:00
elseif theme_name:find("wombat") then
theme_name = "wombat"
elseif theme_name == "wombuddy" then
theme_name = "wombat"
end
2021-12-09 06:13:53 +00:00
local gps = {}
if utils.is_plugin_loaded("nvim-gps") then
gps = require("nvim-gps")
2021-12-15 17:37:51 +00:00
gps.setup({
2021-12-09 06:13:53 +00:00
icons = {
["class-name"] = "(c) ",
["function-name"] = "(ƒ) ",
["method-name"] = "(m) ",
["container-name"] = "",
["tag-name"] = "(t) ",
2021-12-15 17:37:51 +00:00
},
})
2021-12-09 06:13:53 +00:00
end
2021-12-15 00:20:07 +00:00
local diagnostic_plugin = "nvim_diagnostic"
2021-12-15 17:37:51 +00:00
if vim.fn.has("nvim-0.6.0") ~= 1 then
2021-12-15 00:20:07 +00:00
diagnostic_plugin = "nvim_lsp"
end
2021-12-15 17:37:51 +00:00
require("lualine").setup({
options = {
theme = theme_name,
icons_enabled = false,
2021-12-15 17:37:51 +00:00
component_separators = { left = "|", right = "|" },
section_separators = { left = "", right = "" },
},
sections = {
2021-12-15 17:37:51 +00:00
lualine_a = {
{
"mode",
fmt = function(str)
return str:sub(1, 1)
end,
},
},
2021-12-15 00:20:07 +00:00
lualine_b = { "FugitiveHead", "diff" },
2022-06-16 19:50:49 +00:00
lualine_c = { { "filename", path = 1 }, { gps.get_location, cond = gps.is_available } },
2021-12-15 00:20:07 +00:00
lualine_x = { M.custom_ffenc, "filetype" },
lualine_y = { "progress", "location" },
lualine_z = {
2021-12-15 00:20:07 +00:00
{ "diagnostics", sources = { diagnostic_plugin } },
{ M.mixed_indent, color = { bg = "#de4f1f" } },
{ M.trailing_whitespace, color = { bg = "#de4f1f" } },
},
},
2021-12-15 17:37:51 +00:00
})
end
return M