vim: better structure for utils
This commit is contained in:
parent
5f2dd220d9
commit
e34671ddaa
15 changed files with 34 additions and 37 deletions
|
@ -1,6 +1,6 @@
|
||||||
vim.bo.tabstop = 2
|
vim.bo.tabstop = 2
|
||||||
|
|
||||||
local lua = require('fschauen.util').lua
|
local lua = require('fschauen.util.lua')
|
||||||
|
|
||||||
local opts = function(desc)
|
local opts = function(desc)
|
||||||
return { desc = desc, buffer = true }
|
return { desc = desc, buffer = true }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local icons = require('fschauen.icons')
|
local icons = require('fschauen.util.icons')
|
||||||
|
|
||||||
-- Show/navigate warning and errors by default.
|
-- Show/navigate warning and errors by default.
|
||||||
M.severity = vim.diagnostic.severity.WARN
|
M.severity = vim.diagnostic.severity.WARN
|
||||||
|
|
|
@ -89,7 +89,7 @@ M.config = function(--[[plugin]]_, --[[opts]]_)
|
||||||
path = '',
|
path = '',
|
||||||
},
|
},
|
||||||
|
|
||||||
symbol_map = require('fschauen.icons').kind,
|
symbol_map = require('fschauen.util.icons').kind,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ M.event = 'LspAttach'
|
||||||
|
|
||||||
M.opts = {
|
M.opts = {
|
||||||
text = {
|
text = {
|
||||||
done = require('fschauen.icons').ui.Checkmark,
|
done = require('fschauen.util.icons').ui.Checkmark,
|
||||||
spinner = {
|
spinner = {
|
||||||
'▱▱▱▱▱▱▱',
|
'▱▱▱▱▱▱▱',
|
||||||
'▰▱▱▱▱▱▱',
|
'▰▱▱▱▱▱▱',
|
||||||
|
|
|
@ -17,7 +17,7 @@ M.keys = {
|
||||||
M.main = 'ibl'
|
M.main = 'ibl'
|
||||||
|
|
||||||
M.opts = function(--[[plugin]]_, opts)
|
M.opts = function(--[[plugin]]_, opts)
|
||||||
local icons = require('fschauen.icons')
|
local icons = require('fschauen.util.icons')
|
||||||
return vim.tbl_deep_extend('force', opts, {
|
return vim.tbl_deep_extend('force', opts, {
|
||||||
enabled = false,
|
enabled = false,
|
||||||
indent = {
|
indent = {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
local M = { 'nvim-lualine/lualine.nvim' }
|
local M = { 'nvim-lualine/lualine.nvim' }
|
||||||
|
|
||||||
local icons = require('fschauen.icons')
|
local icons = require('fschauen.util.icons')
|
||||||
local orange = '#d65d0e'
|
local orange = '#d65d0e'
|
||||||
local bright = '#ffffff' -- alternative: '#f9f5d7'
|
local bright = '#ffffff' -- alternative: '#f9f5d7'
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ M.keys = {
|
||||||
}
|
}
|
||||||
|
|
||||||
M.opts = function(--[[plugin]]_, opts)
|
M.opts = function(--[[plugin]]_, opts)
|
||||||
local icons = require('fschauen.icons')
|
local icons = require('fschauen.util.icons')
|
||||||
return vim.tbl_deep_extend('force', opts, {
|
return vim.tbl_deep_extend('force', opts, {
|
||||||
disable_hint = true,
|
disable_hint = true,
|
||||||
signs = {
|
signs = {
|
||||||
|
|
|
@ -21,7 +21,7 @@ M.keys = {
|
||||||
M.lazy = false
|
M.lazy = false
|
||||||
|
|
||||||
M.opts = function(--[[plugin]]_, opts)
|
M.opts = function(--[[plugin]]_, opts)
|
||||||
local icons = require('fschauen.icons')
|
local icons = require('fschauen.util.icons')
|
||||||
return vim.tbl_deep_extend('force', opts, {
|
return vim.tbl_deep_extend('force', opts, {
|
||||||
icons = {
|
icons = {
|
||||||
ERROR = icons.diagnostics_bold.Error,
|
ERROR = icons.diagnostics_bold.Error,
|
||||||
|
|
|
@ -10,7 +10,7 @@ M.keys = {
|
||||||
}
|
}
|
||||||
|
|
||||||
M.opts = function(--[[plugin]]_, opts)
|
M.opts = function(--[[plugin]]_, opts)
|
||||||
local icons = require('fschauen.icons')
|
local icons = require('fschauen.util.icons')
|
||||||
return vim.tbl_deep_extend('force', opts, {
|
return vim.tbl_deep_extend('force', opts, {
|
||||||
disable_netrw = true, -- replace netrw with nvim-tree
|
disable_netrw = true, -- replace netrw with nvim-tree
|
||||||
hijack_cursor = true, -- keep the cursor on begin of the filename
|
hijack_cursor = true, -- keep the cursor on begin of the filename
|
||||||
|
|
|
@ -125,7 +125,7 @@ M.keys = {
|
||||||
M.opts = function(--[[plugin]]_, opts)
|
M.opts = function(--[[plugin]]_, opts)
|
||||||
local actions = require('telescope.actions')
|
local actions = require('telescope.actions')
|
||||||
local layout = require('telescope.actions.layout')
|
local layout = require('telescope.actions.layout')
|
||||||
local icons = require('fschauen.icons')
|
local icons = require('fschauen.util.icons')
|
||||||
local trouble = vim.F.npcall(require, 'trouble.providers.telescope') or {}
|
local trouble = vim.F.npcall(require, 'trouble.providers.telescope') or {}
|
||||||
|
|
||||||
local mappings = {
|
local mappings = {
|
||||||
|
|
|
@ -12,7 +12,7 @@ M.keys = {
|
||||||
}
|
}
|
||||||
|
|
||||||
M.opts = function(--[[plugin]]_, opts)
|
M.opts = function(--[[plugin]]_, opts)
|
||||||
local icons = require('fschauen.icons')
|
local icons = require('fschauen.util.icons')
|
||||||
return vim.tbl_deep_extend('force', opts, {
|
return vim.tbl_deep_extend('force', opts, {
|
||||||
keywords = {
|
keywords = {
|
||||||
TODO = { icon = icons.ui.Checkbox },
|
TODO = { icon = icons.ui.Checkbox },
|
||||||
|
|
|
@ -16,7 +16,7 @@ M.keys = {
|
||||||
|
|
||||||
M.config = function(--[[plugin]]_, --[[opts]]_)
|
M.config = function(--[[plugin]]_, --[[opts]]_)
|
||||||
require('virt-column').setup {
|
require('virt-column').setup {
|
||||||
char = require('fschauen.icons').ui.LineMiddle,
|
char = require('fschauen.util.icons').ui.LineMiddle,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
9
config/nvim/lua/fschauen/util/init.lua
Normal file
9
config/nvim/lua/fschauen/util/init.lua
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.exists = function(path)
|
||||||
|
local stat = vim.loop.fs_stat(path)
|
||||||
|
return (stat and stat.type) or false
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
|
@ -1,17 +1,9 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.file_exists = function(path)
|
local util = require('fschauen.util')
|
||||||
local stat = vim.loop.fs_stat(path)
|
local exists = util.exists
|
||||||
return stat and stat.type == 'file'
|
|
||||||
end
|
|
||||||
|
|
||||||
M.edit_file = function(path)
|
local find_module_sources = function(modname)
|
||||||
if not pcall(vim.api.nvim_command, string.format('edit %s', path)) then
|
|
||||||
vim.notify('Could not open ' .. path, vim.log.levels.ERROR)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local find_lua_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' }
|
||||||
|
@ -20,7 +12,7 @@ local find_lua_module_sources = function(modname)
|
||||||
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 M.file_exists(path) then
|
if exists(path) then
|
||||||
table.insert(results, path)
|
table.insert(results, path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,47 +20,43 @@ local find_lua_module_sources = function(modname)
|
||||||
return results
|
return results
|
||||||
end
|
end
|
||||||
|
|
||||||
local lua = {}
|
M.execute_lines = function(first, last)
|
||||||
|
|
||||||
lua.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
|
||||||
|
|
||||||
lua.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)
|
||||||
lua.execute_lines(unpack(selection))
|
M.execute_lines(unpack(selection))
|
||||||
end
|
end
|
||||||
|
|
||||||
lua.execute_file = function(path)
|
M.execute_file = function(path)
|
||||||
if path then
|
if path then
|
||||||
vim.cmd.luafile(path)
|
vim.cmd.luafile(path)
|
||||||
else
|
else
|
||||||
lua.execute_lines(1, vim.fn.line('$'))
|
M.execute_lines(1, vim.fn.line('$'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
lua.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_lua_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
|
||||||
M.edit_file(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
|
||||||
M.edit_file(choice)
|
vim.cmd.edit(choice)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lua = lua
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Reference in a new issue