vim: enforce style in util

This commit is contained in:
Fernando Schauenburg 2024-02-21 20:30:19 +01:00
parent c2b340ef88
commit f513e9346e
4 changed files with 135 additions and 133 deletions

View file

@ -1,135 +1,138 @@
local M = {} local M = {}
-- stylua: ignore start
M.diagnostics = { M.diagnostics = {
Debug = '', Debug = "",
Error = '', Error = "",
Hint = '', Hint = "",
Info = '', Info = "",
Trace = '', Trace = "",
Warn = '', Warn = "",
} }
M.diagnostics_bold = { M.diagnostics_bold = {
Debug = '', Debug = "",
Error = '', Error = "",
Hint = '󰌵 ', Hint = "󰌵 ",
Info = '', Info = "",
Trace = '', Trace = "",
Warn = '', Warn = "",
} }
M.git = { M.git = {
Branch = '󰘬', --  Branch = "󰘬", -- 
file = { file = {
Deleted = '', --  Deleted = "", -- 
Ignored = '', Ignored = "",
Renamed = '', --  Renamed = "", -- 
Staged = '', -- S Staged = "", -- S
Unmerged = '', --  Unmerged = "", -- 
Unstaged = '', --  Unstaged = "", -- 
Untracked = '', -- U Untracked = "", -- U
} }
} }
-- Custom mix of lspkind defaults and VS Code codicons :) -- Custom mix of lspkind defaults and VS Code codicons :)
M.kind = { M.kind = {
Array = '', Array = "",
Boolean = '', Boolean = "",
Class = '', Class = "",
Color = '', Color = "",
Constant = '󰏿 ', --  Constant = "󰏿 ", -- 
Constructor = '', Constructor = "",
Copilot = '', Copilot = "",
Enum = '', --  Enum = "", -- 
EnumMember = '', --  EnumMember = "", -- 
Event = '', Event = "",
Field = '', Field = "",
File = '', File = "",
Folder = '', -- 󰉋 Folder = "", -- 󰉋
Function = '󰊕 ', --  Function = "󰊕 ", -- 
Interface = '', Interface = "",
Key = '', Key = "",
Keyword = '', Keyword = "",
Method = '', Method = "",
Module = '', Module = "",
Namespace = '', Namespace = "",
Null = '', -- 󰟢 Null = "", -- 󰟢
Number = '', Number = "",
Object = '', Object = "",
Operator = '', Operator = "",
Package = '', Package = "",
Property = '', Property = "",
Reference = '', --  Reference = "", -- 
Snippet = '', Snippet = "",
String = '', String = "",
Struct = '', Struct = "",
Text = '', Text = "",
TypeParameter = '', TypeParameter = "",
Unit = '', Unit = "",
Value = '󰎠 ', Value = "󰎠 ",
Variable = '󰀫 ', --  Variable = "󰀫 ", -- 
} }
M.modes = { M.modes = {
Normal = '', -- 'Normal ' 'n' Normal = "", -- "Normal " "n"
OperatorPending = '', -- 'O-Pend ' 'no' OperatorPending = "", -- "O-Pend " "no"
NormalI = '', -- 'Normal ' 'ni' (normal via i_CTRL-O) NormalI = "", -- "Normal " "ni" (normal via i_CTRL-O)
Visual = '󰒉', -- 'Visual ' 'v' Visual = "󰒉", -- "Visual " "v"
VisualBlock = '󰩭', -- 'V-Block' '' VisualBlock = "󰩭", -- "V-Block" ""
Select = '󰒉', -- 'Select ' 's' Select = "󰒉", -- "Select " "s"
SelectBlock = '󰩭', -- 'S-Block' '' SelectBlock = "󰩭", -- "S-Block" ""
Insert = '', -- 'Insert ' 'i' Insert = "", -- "Insert " "i"
Replace = '󰄾', -- 'Replace' 'r' Replace = "󰄾", -- "Replace" "r"
VirtualReplace = '󰶻', -- 'V-Repl ' 'rv' VirtualReplace = "󰶻", -- "V-Repl " "rv"
Command = '', -- 'Command' 'c' Command = "", -- "Command" "c"
Ex = '', -- ' Ex ' 'cv' Ex = "", -- " Ex " "cv"
modeore = '', -- ' modeore 'rm' (modeORE) modeore = "", -- " modeore "rm" (modeORE)
Confirm = '󰭚', -- 'Confirm' 'r?' (:confirm) Confirm = "󰭚", -- "Confirm" "r?" (:confirm)
Shell = '', -- ' Shell ' '!' (external command executing) Shell = "", -- " Shell " "!" (external command executing)
Terminal = '', -- ' Term ' 't' Terminal = "", -- " Term " "t"
} }
M.ui = { M.ui = {
Attention = '', Attention = "",
Bug = '', --  Bug = "", -- 
Checkbox = '', --  󰄬 󰄬  Checkbox = "", --  󰄬 󰄬 
Checkmark = '', --  󰄬 󰄬  Checkmark = "", --  󰄬 󰄬 
ChevronDown = '', --  ChevronDown = "", -- 
ChevronLeft = '', --  ChevronLeft = "", -- 
ChevronRight = '', --  ChevronRight = "", -- 
ChevronUp = '', --  ChevronUp = "", -- 
ChevronSmallDown = '', ChevronSmallDown = "",
ChevronSmallLeft = '', ChevronSmallLeft = "",
ChevronSmallRight = '', ChevronSmallRight = "",
ChevronSmallUp = '', ChevronSmallUp = "",
Circle = '', Circle = "",
Diagnostic = '', Diagnostic = "",
EmptyFolder = '', EmptyFolder = "",
EmptyFolderOpen = '', EmptyFolderOpen = "",
File = '', --  File = "", -- 
FileSymlink = '', --  FileSymlink = "", -- 
Files = '', Files = "",
Fire = '', --  Fire = "", -- 
Folder = '󰉋', Folder = "󰉋",
FolderOpen = '', FolderOpen = "",
FolderSymlink = '', FolderSymlink = "",
Gauge = '󰓅', --  Gauge = "󰓅", -- 
LineLeft = '', LineLeft = "",
LineLeftBold = '', LineLeftBold = "",
LineMiddle = '', LineMiddle = "",
LineMiddleBold = '', LineMiddleBold = "",
Modified = '', Modified = "",
Note = '', --  Note = "", -- 
Paste = '', Paste = "",
Play = '', Play = "",
ReadOnly = '', -- 'RO', ReadOnly = "", -- "RO",
Search = '', --  Search = "", -- 
Sleep = '󰒲', Sleep = "󰒲",
Telescope = '', Telescope = "",
TestTube = '󰙨', -- 󰤑 TestTube = "󰙨", -- 󰤑
Toggle = '󰨚', Toggle = "󰨚",
Warning = '', Warning = "",
} }
return M -- stylua: ignore end
return M

View file

@ -22,13 +22,14 @@ end
---Get selected text. ---Get selected text.
---@return string: selected text, or work under cursor if not in visual mode. ---@return string: selected text, or work under cursor if not in visual mode.
M.get_selected_text = function() M.get_selected_text = function()
if vim.fn.mode() ~= 'v' then return vim.fn.expand '<cword>' end if vim.fn.mode() ~= "v" then
return vim.fn.expand("<cword>")
end
return M.preserve_register('v', function() return M.preserve_register("v", function()
vim.cmd [[noautocmd sil norm "vy]] vim.cmd([[noautocmd sil norm "vy]])
return vim.fn.getreg 'v' return vim.fn.getreg("v")
end) end)
end end
return M return M

View file

@ -1,17 +1,17 @@
local M = {} local M = {}
local util = require('fschauen.util') local util = require("fschauen.util")
local exists = util.exists local exists = util.exists
local find_module_sources = function(modname) local find_module_sources = function(modname)
modname = modname:gsub('^%.+', ''):gsub('/', '.') modname = modname:gsub("^%.+", ""):gsub("/", ".")
local base = 'lua/' .. modname:gsub('%.', '/') local base = "lua/" .. modname:gsub("%.", "/")
local candidates = { base .. '.lua', base .. '/init.lua' } local candidates = { base .. ".lua", base .. "/init.lua" }
local results = {} local results = {}
for _, directory in ipairs(vim.opt.runtimepath:get()) do for _, directory in ipairs(vim.opt.runtimepath:get()) do
for _, candidate in ipairs(candidates) do for _, candidate in ipairs(candidates) do
local path = directory .. '/' .. candidate local path = directory .. "/" .. candidate
if exists(path) then if exists(path) then
table.insert(results, path) table.insert(results, path)
end end
@ -21,14 +21,14 @@ local find_module_sources = function(modname)
end end
M.execute_lines = function(first, last) M.execute_lines = function(first, last)
first = first or vim.fn.line('.') first = first or vim.fn.line(".")
last = last or first last = last or first
local code = vim.fn.join(vim.fn.getline(first, last), '\n') local code = vim.fn.join(vim.fn.getline(first, last), "\n")
loadstring(code)() loadstring(code)()
end end
M.execute_selection = function() M.execute_selection = function()
local selection = { vim.fn.line('v'), vim.fn.line('.') } local selection = { vim.fn.line("v"), vim.fn.line(".") }
table.sort(selection) table.sort(selection)
M.execute_lines(unpack(selection)) M.execute_lines(unpack(selection))
end end
@ -37,20 +37,20 @@ M.execute_file = function(path)
if path then if path then
vim.cmd.luafile(path) vim.cmd.luafile(path)
else else
M.execute_lines(1, vim.fn.line('$')) M.execute_lines(1, vim.fn.line("$"))
end end
end end
M.go_to_module = function(modname) M.go_to_module = function(modname)
modname = modname or vim.fn.expand('<cfile>') modname = modname or vim.fn.expand("<cfile>")
local sources = find_module_sources(modname) local sources = find_module_sources(modname)
if #sources == 0 then if #sources == 0 then
vim.notify('Not found: ' .. modname, vim.log.levels.WARN) vim.notify("Not found: " .. modname, vim.log.levels.WARN)
elseif #sources == 1 then elseif #sources == 1 then
vim.cmd.edit(sources[1]) vim.cmd.edit(sources[1])
else else
vim.ui.select(sources, { prompt = 'Which one?' }, function(choice) vim.ui.select(sources, { prompt = "Which one?" }, function(choice)
if choice then if choice then
vim.cmd.edit(choice) vim.cmd.edit(choice)
end end
@ -59,4 +59,3 @@ M.go_to_module = function(modname)
end end
return M return M

View file

@ -12,18 +12,17 @@ end
M.toggle_list = function() M.toggle_list = function()
vim.wo.list = not vim.wo.list vim.wo.list = not vim.wo.list
vim.cmd [[set list?]] vim.cmd([[set list?]])
end end
M.toggle_wrap = function() M.toggle_wrap = function()
vim.wo.wrap = not vim.wo.wrap vim.wo.wrap = not vim.wo.wrap
vim.cmd [[set wrap?]] vim.cmd([[set wrap?]])
end end
M.toggle_spell = function() M.toggle_spell = function()
vim.wo.spell = not vim.wo.spell vim.wo.spell = not vim.wo.spell
vim.cmd [[set spell?]] vim.cmd([[set spell?]])
end end
return M return M