Compare commits

...

7 Commits

Author SHA1 Message Date
David JULIEN b97d011b55
Merge branch 'dev' into mercury
nvim: shorten path in statusline if needed
2023-02-12 22:30:58 +01:00
David JULIEN 786d119e5c [nvim] feat: shorten path in statusline if needed 2023-02-12 22:30:25 +01:00
David JULIEN b8ef05167f
Merge branch 'dev' into mercury
nvim: fix lua LSP server name
        add mini.indentscope
2023-02-12 20:18:31 +01:00
David JULIEN 475ed9bb31 [nvim] feat: add mini.indentscope 2023-02-12 18:42:36 +01:00
David JULIEN 306a6ef1da [nvim] fix: rename lua LSP server 2023-02-12 18:42:25 +01:00
David JULIEN 9aed284dbe [nvim] feat: add mini.pairs 2023-02-08 22:54:00 +01:00
David JULIEN 3892bc9389 [nvim] cleanup: rename comment.lua to editor.lua
the file will host plugins relative to the editor itself, not only
comments
2023-02-08 22:53:04 +01:00
5 changed files with 190 additions and 142 deletions

View File

@ -1,21 +0,0 @@
-- Author : swytch
-- Created : Sunday Jan. 29, 2023 00:20:31 CET
-- License : GPLv3
-- Description : Mini.comment plugin config file
return {
"echasnovski/mini.comment",
version = "*",
opts = {
mappings = {
comment = "<leader>c",
comment_line = "<leader><Space>",
text_object = "gc",
},
},
config = function(_, opts)
require("mini.comment").setup(opts)
end,
}

View File

@ -0,0 +1,44 @@
-- Author : swytch
-- Created : Sunday Jan. 29, 2023 00:20:31 CET
-- License : GPLv3
-- Description : Mini.comment plugin config file
return {
{
"echasnovski/mini.comment",
version = "*",
opts = {
mappings = {
comment = "<leader>c",
comment_line = "<leader><Space>",
text_object = "gc",
},
},
config = function(_, opts)
require("mini.comment").setup(opts)
end
},
{
"echasnovski/mini.pairs",
version = "*",
config = function() require("mini.pairs").setup() end,
},
{
"echasnovski/mini.indentscope",
version = "*",
opts = function()
local plugin = require("mini.indentscope")
return {
draw = {
animation = plugin.gen_animation.none()
}
}
end,
config = function(_, opts)
require("mini.indentscope").setup(opts)
end,
}
}

View File

@ -9,7 +9,7 @@ _G.lsp_root_dir = vim.fn.stdpath("data") .. "/mason/bin"
local servers = {
"clangd",
"rust_analyzer",
"sumneko_lua",
"lua_ls",
"texlab",
}

View File

@ -12,7 +12,7 @@ local function gen_section(hl_string, items)
out = out .. " " .. item
end
end
if out ~="" then
if out ~= "" then
return hl_string .. out .. " "
else
return out
@ -22,56 +22,56 @@ end
-- sensible names for vim modes
local function get_mode(m)
local mode_group = {
["n"] = "Normal",
["no"] = "O-Pending",
["nov"] = "O-Pending",
["noV"] = "O-Pending",
["no"] = "O-Pending",
["niI"] = "Normal",
["niR"] = "Normal",
["niV"] = "Normal",
["v"] = "Visual",
["V"] = "V-Line",
[""] = "V-Block",
["s"] = "Select",
["S"] = "S-Line",
[""] = "S-Block",
["i"] = "Insert",
["ic"] = "Insert",
["ix"] = "Insert",
["R"] = "Replace",
["Rc"] = "Replace",
["Rv"] = "V-Replace",
["Rx"] = "Replace",
["c"] = "Command",
["cv"] = "Ex",
["ce"] = "Ex",
["r"] = "Prompt",
["rm"] = "Prompt",
["r?"] = "Prompt",
["!"] = "Shell",
["t"] = "Terminal",
["n"] = "Normal",
["no"] = "O-Pending",
["nov"] = "O-Pending",
["noV"] = "O-Pending",
["no"] = "O-Pending",
["niI"] = "Normal",
["niR"] = "Normal",
["niV"] = "Normal",
["v"] = "Visual",
["V"] = "V-Line",
[""] = "V-Block",
["s"] = "Select",
["S"] = "S-Line",
[""] = "S-Block",
["i"] = "Insert",
["ic"] = "Insert",
["ix"] = "Insert",
["R"] = "Replace",
["Rc"] = "Replace",
["Rv"] = "V-Replace",
["Rx"] = "Replace",
["c"] = "Command",
["cv"] = "Ex",
["ce"] = "Ex",
["r"] = "Prompt",
["rm"] = "Prompt",
["r?"] = "Prompt",
["!"] = "Shell",
["t"] = "Terminal",
}
return mode_group[m] or "None"
end
local function get_mode_display_name(m)
local mode = {
["Normal"] = "[ NRM ]",
["O-Pending"] = "[ OTR ]",
["Visual"] = "[ VSL ]",
["V-Line"] = "[ V·L ]",
["V-Block"] = "[ V·B ]",
["Select"] = "[ SEL ]",
["S-Line"] = "[ S·L ]",
["S-Block"] = "[ S·B ]",
["Insert"] = "[ INS ]",
["Replace"] = "[ RPL ]",
["Command"] = "[ CMD ]",
["Prompt"] = "[ PMT ]",
["Shell"] = "[ SHL ]",
["Terminal"] = "[ TRM ]",
["None"] = "[ --- ]"
["Normal"] = "[ NRM ]",
["O-Pending"] = "[ OTR ]",
["Visual"] = "[ VSL ]",
["V-Line"] = "[ V·L ]",
["V-Block"] = "[ V·B ]",
["Select"] = "[ SEL ]",
["S-Line"] = "[ S·L ]",
["S-Block"] = "[ S·B ]",
["Insert"] = "[ INS ]",
["Replace"] = "[ RPL ]",
["Command"] = "[ CMD ]",
["Prompt"] = "[ PMT ]",
["Shell"] = "[ SHL ]",
["Terminal"] = "[ TRM ]",
["None"] = "[ --- ]"
}
return mode[m]
end
@ -79,25 +79,48 @@ end
-- get the highlight group for a mode group
local function get_mode_color(m)
local color = {
["Normal"] = "%#NormalMode#",
["O-Pending"] = "%#NormalMode#",
["Visual"] = "%#VisualMode#",
["V-Line"] = "%#VisualMode#",
["V-Block"] = "%#VisualMode#",
["Select"] = "%#NormalMode#",
["S-Line"] = "%#NormalMode#",
["S-Block"] = "%#NormalMode#",
["Insert"] = "%#InsertMode#",
["Replace"] = "%#ReplaceMode#",
["Command"] = "%#CommandMode#",
["Prompt"] = "%#NormalMode#",
["Shell"] = "%#NormalMode#",
["Terminal"] = "%#NormalMode#",
["None"] = "%#NormalMode#"
["Normal"] = "%#NormalMode#",
["O-Pending"] = "%#NormalMode#",
["Visual"] = "%#VisualMode#",
["V-Line"] = "%#VisualMode#",
["V-Block"] = "%#VisualMode#",
["Select"] = "%#NormalMode#",
["S-Line"] = "%#NormalMode#",
["S-Block"] = "%#NormalMode#",
["Insert"] = "%#InsertMode#",
["Replace"] = "%#ReplaceMode#",
["Command"] = "%#CommandMode#",
["Prompt"] = "%#NormalMode#",
["Shell"] = "%#NormalMode#",
["Terminal"] = "%#NormalMode#",
["None"] = "%#NormalMode#"
}
return color[m]
end
-- from https://github.com/nvim-lualine/lualine.nvim/blob/master/lua/lualine/components/filename.lua
local function shorten_path(path, max_len)
local sep = '/'
local len = #path
if len <= max_len then
return path
end
local segments = vim.split(path, sep)
for idx = 1, #segments - 1 do
if len <= max_len then
break
end
local segment = segments[idx]
local shortened = segment:sub(1, vim.startswith(segment, '.') and 2 or 1)
segments[idx] = shortened
len = len - (#segment - #shortened)
end
return table.concat(segments, sep)
end
-- from https://github.com/nvim-lua/lsp-status.nvim/blob/master/lua/lsp-status/diagnostics.lua
local function get_lsp_diagnostics()
local result = {}
@ -121,80 +144,82 @@ local function get_lsp_diagnostics()
end
local function process_diagnostics(prefix, n, hl)
if n > 0 then
return hl .. prefix .. n
else
return ""
end
if n > 0 then
return hl .. prefix .. n
else
return ""
end
end
local function spell_check()
if vim.wo.spell then
local lang = vim.o.spelllang
return "[SPELL=" .. lang .. "]"
else
return ""
end
if vim.wo.spell then
local lang = vim.o.spelllang
return "[SPELL=" .. lang .. "]"
else
return ""
end
end
local function statusline_focused()
local diagnostics = get_lsp_diagnostics()
local mode = vim.fn.mode()
local mg = get_mode(mode)
local accent_color = get_mode_color(mg)
local file = vim.fn.expand("%:p:~")
local diagnostics = get_lsp_diagnostics()
local mode = vim.fn.mode()
local mg = get_mode(mode)
local accent_color = get_mode_color(mg)
local winwidth = vim.fn.winwidth(0)
local left = table.concat {
gen_section(accent_color, {get_mode_display_name(mg)}),
gen_section("%#Middle#", {"%f"}),
gen_section("%#Bottom#", {"%m", "%r"}),
gen_section(
"%#Alert#",
{
process_diagnostics(
globals.sign_error .. " ",
diagnostics.error,
"%#DiagnosticVirtualTextError#"
),
process_diagnostics(
globals.sign_warn .. " ",
diagnostics.warn,
"%#DiagnosticVirtualTextWarn#"
),
process_diagnostics(
globals.sign_info .. " ",
diagnostics.info,
"%#DiagnosticVirtualTextInfo#"
)
}
)
}
local right = table.concat {
gen_section(
"%#Bottom#",
{
spell_check(),
vim.bo.filetype
}
),
gen_section("%#Middle#", {"%03.p%%"}),
gen_section("%#Top#", {"-%03.c-"})
}
local left = table.concat {
gen_section(accent_color, { get_mode_display_name(mg) }),
gen_section("%#Middle#", { shorten_path(file, winwidth / 3) }),
gen_section("%#Bottom#", { "%m", "%r" }),
gen_section(
"%#Alert#",
{
process_diagnostics(
globals.sign_error .. " ",
diagnostics.error,
"%#DiagnosticVirtualTextError#"
),
process_diagnostics(
globals.sign_warn .. " ",
diagnostics.warn,
"%#DiagnosticVirtualTextWarn#"
),
process_diagnostics(
globals.sign_info .. " ",
diagnostics.info,
"%#DiagnosticVirtualTextInfo#"
)
}
)
}
local right = table.concat {
gen_section(
"%#Bottom#",
{
spell_check(),
vim.bo.filetype
}
),
gen_section("%#Middle#", { "%03.p%%" }),
gen_section("%#Top#", { "-%03.c-" })
}
return table.concat {
left,
"%#Statusline#",
"%=",
right
}
return table.concat {
left,
"%#Statusline#",
"%=",
right
}
end
local function statusline_not_focused()
return table.concat {
gen_section("%#StatuslineNF#", {"%f", "%m"}),
gen_section("%#StatuslineNF#", { "%f", "%m" }),
"%=",
gen_section("%#StatuslineNF#", {"%03.p%%"}),
gen_section("%#StatuslineNF#", {"-%03.c-"})
gen_section("%#StatuslineNF#", { "%03.p%%" }),
gen_section("%#StatuslineNF#", { "-%03.c-" })
}
end