diff options
Diffstat (limited to 'lua')
-rw-r--r-- | lua/startup/config.lua | 2 | ||||
-rw-r--r-- | lua/startup/init.lua | 54 | ||||
-rw-r--r-- | lua/startup/themes/evil_startup.lua | 4 | ||||
-rw-r--r-- | lua/startup/utils.lua | 65 |
4 files changed, 70 insertions, 55 deletions
diff --git a/lua/startup/config.lua b/lua/startup/config.lua index 8508de5..02dde9d 100644 --- a/lua/startup/config.lua +++ b/lua/startup/config.lua @@ -1,3 +1,3 @@ -local settings = require "startup.themes.default" +local settings = require("startup.themes.default") return settings diff --git a/lua/startup/init.lua b/lua/startup/init.lua index 603ae46..cea3fe2 100644 --- a/lua/startup/init.lua +++ b/lua/startup/init.lua @@ -1,5 +1,5 @@ local startup = {} -local ns = vim.api.nvim_create_namespace "startup" +local ns = vim.api.nvim_create_namespace("startup") -- tables with tables: {line, align, cursor should move on, highlight} startup.lines = {} startup.formatted_text = {} @@ -7,16 +7,16 @@ startup.sections = {} startup.section_highlights = {} startup.open_sections = {} startup.good_lines = {} -startup.settings = require"startup.config" +startup.settings = require("startup.config") local section_alignments = {} local current_section = "" local opts = { noremap = true, silent = true } -local settings = require "startup.config" +local settings = require("startup.config") -local utils = require "startup.utils" +local utils = require("startup.utils") local spaces = utils.spaces function startup.open_section() @@ -58,7 +58,7 @@ function startup.open_section() ) end table.insert(startup.open_sections, section_name) - vim.cmd [[silent! %s/\s\+$//]] -- clear trailing whitespace + vim.cmd([[silent! %s/\s\+$//]]) -- clear trailing whitespace vim.api.nvim_win_set_cursor(0, { line_nr, math.floor(vim.o.columns / 2) }) vim.api.nvim_buf_set_option(0, "modifiable", false) end @@ -113,7 +113,7 @@ local function create_mappings(mappings) end function startup.new_file() - local name = vim.fn.input "Filename: > " + local name = vim.fn.input("Filename: > ") vim.cmd("e " .. name) end @@ -213,7 +213,7 @@ function startup.display() local padding_nr = 1 U.set_buf_options() local parts = settings.parts - vim.cmd[[hi link StartupFoldedSection Special]] + vim.cmd([[hi link StartupFoldedSection Special]]) for _, part in ipairs(parts) do empty(settings.options.paddings[padding_nr]) padding_nr = padding_nr + 1 @@ -239,7 +239,7 @@ function startup.display() section_alignments[vim.trim(options.title)] = options.align startup.sections[vim.trim(options.title)] = options.content startup.section_highlights[vim.trim(options.title)] = options.highlight - startup.good_lines[#startup.good_lines+1] = vim.trim(options.title) + startup.good_lines[#startup.good_lines + 1] = vim.trim(options.title) table.insert( startup.lines, { options.title, options.align, true, "StartupFoldedSection" } @@ -255,24 +255,25 @@ function startup.display() elseif options.type == "mapping" then if options.fold_section then section_alignments[vim.trim(options.title)] = options.align - for _, line in ipairs(require"startup".mapping_names(options.content)) do + for _, line in ipairs(require("startup").mapping_names(options.content)) do startup.good_lines[#startup.good_lines + 1] = vim.trim(line) end - startup.sections[vim.trim(options.title)] = require("startup").mapping_names( - options.content - ) + startup.sections[vim.trim(options.title)] = + require("startup").mapping_names( + options.content + ) startup.section_highlights[vim.trim(options.title)] = options.highlight - startup.good_lines[#startup.good_lines+1] = vim.trim(options.title) + startup.good_lines[#startup.good_lines + 1] = vim.trim(options.title) table.insert( startup.lines, { options.title, options.align, true, "StartupFoldedSection" } ) for _, line in ipairs(options.content) do - startup.good_lines[#startup.good_lines+1] = vim.trim(line) + startup.good_lines[#startup.good_lines + 1] = vim.trim(line) end else for _, line in ipairs(require("startup").mapping_names(options.content)) do - startup.good_lines[#startup.good_lines+1] = vim.trim(line) + startup.good_lines[#startup.good_lines + 1] = vim.trim(line) table.insert( startup.lines, { line, options.align, true, options.highlight } @@ -295,9 +296,9 @@ function startup.display() section_alignments[vim.trim(options.title)] = options.align startup.sections[vim.trim(options.title)] = old_files startup.section_highlights[vim.trim(options.title)] = options.highlight - startup.good_lines[#startup.good_lines+1] = vim.trim(options.title) + startup.good_lines[#startup.good_lines + 1] = vim.trim(options.title) for _, line in ipairs(old_files) do - startup.good_lines[#startup.good_lines+1] = vim.trim(line) + startup.good_lines[#startup.good_lines + 1] = vim.trim(line) end table.insert( startup.lines, @@ -305,7 +306,7 @@ function startup.display() ) else for _, line in ipairs(old_files) do - startup.good_lines[#startup.good_lines+1] = vim.trim(line) + startup.good_lines[#startup.good_lines + 1] = vim.trim(line) table.insert( startup.lines, { line, options.align, true, options.highlight } @@ -313,13 +314,16 @@ function startup.display() end end end - create_mappings {} + create_mappings({}) vim.cmd(options.command) end -- print("startup.lines:") -- dump(startup.lines) if settings.folded_section_color ~= "" then - vim.cmd([[highlight StartupFoldedSection guifg=]]..settings.colors.folded_section) + vim.cmd( + [[highlight StartupFoldedSection guifg=]] + .. settings.colors.folded_section + ) end -- current_section = "" for _, line in ipairs(startup.lines) do @@ -331,7 +335,7 @@ function startup.display() vim.api.nvim_buf_set_option(0, "modifiable", true) vim.api.nvim_buf_set_lines(0, 0, -1, true, {}) vim.api.nvim_buf_set_lines(0, 0, -1, false, startup.formatted_text) - vim.cmd [[silent! %s/\s\+$//]] -- clear trailing whitespace + vim.cmd([[silent! %s/\s\+$//]]) -- clear trailing whitespace for linenr, line in ipairs(startup.lines) do vim.api.nvim_buf_add_highlight(0, ns, line[4], linenr - 1, 0, -1) end @@ -342,7 +346,7 @@ function startup.display() math.floor(vim.o.columns / 2), }) -- end) - vim.cmd [[autocmd CursorMoved * lua require"startup.utils".reposition_cursor()]] + vim.cmd([[autocmd CursorMoved * lua require"startup.utils".reposition_cursor()]]) end function startup.setup(update) @@ -352,8 +356,8 @@ function startup.setup(update) vim.g.startup_nvim_loaded = true settings = vim.tbl_deep_extend("force", settings, update or {}) startup.settings = settings - vim.cmd [[autocmd BufRead * lua if vim.fn.argc() == 0 then require("startup").display() end]] - vim.cmd[[autocmd VimResized * lua if vim.bo.ft == "startup" then require"startup".redraw() end]] + vim.cmd([[autocmd BufRead * lua if vim.fn.argc() == 0 then require("startup").display() end]]) + vim.cmd([[autocmd VimResized * lua if vim.bo.ft == "startup" then require"startup".redraw() end]]) end function startup.redraw() @@ -367,7 +371,7 @@ function startup.redraw() vim.api.nvim_buf_set_option(0, "modifiable", true) vim.api.nvim_buf_set_lines(0, 0, -1, true, {}) vim.api.nvim_buf_set_lines(0, 0, -1, false, startup.formatted_text) - vim.cmd [[silent! %s/\s\+$//]] -- clear trailing whitespace + vim.cmd([[silent! %s/\s\+$//]]) -- clear trailing whitespace for linenr, line in ipairs(startup.lines) do vim.api.nvim_buf_add_highlight(0, ns, line[4], linenr - 1, 0, -1) end diff --git a/lua/startup/themes/evil_startup.lua b/lua/startup/themes/evil_startup.lua index d417cbf..68bb80b 100644 --- a/lua/startup/themes/evil_startup.lua +++ b/lua/startup/themes/evil_startup.lua @@ -75,8 +75,8 @@ local settings = { clock = { type = "text", content = function() - local clock = " " .. os.date "%H:%M" - local date = " " .. os.date "%d-%m-%y" + local clock = " " .. os.date("%H:%M") + local date = " " .. os.date("%d-%m-%y") return { clock, date } end, oldfiles_directory = false, diff --git a/lua/startup/utils.lua b/lua/startup/utils.lua index 7822900..3bf126f 100644 --- a/lua/startup/utils.lua +++ b/lua/startup/utils.lua @@ -4,12 +4,12 @@ local new_cursor_pos -- local startup = require"startup" local function set_cursor(cursor) - vim.api.nvim_win_set_cursor(0,cursor) + vim.api.nvim_win_set_cursor(0, cursor) end local function bad_line() - for _, line in ipairs(require"startup".good_lines) do - if line == vim.trim(vim.api.nvim_get_current_line()) and line ~= "" then + for _, line in ipairs(require("startup").good_lines) do + if line == vim.trim(vim.api.nvim_get_current_line()) and line ~= "" then return false end end @@ -85,9 +85,9 @@ end function U.get_oldfiles(amount) local oldfiles = { "Last files", "" } - local oldfiles_raw = vim.fn.execute "oldfiles" + local oldfiles_raw = vim.fn.execute("oldfiles") local oldfiles_amount = 0 - for file in oldfiles_raw:gmatch "[^\n]+" do + for file in oldfiles_raw:gmatch("[^\n]+") do if oldfiles_amount >= amount then break end @@ -103,7 +103,7 @@ function U.get_oldfiles(amount) end function U.get_oldfiles_directory(amount) - local oldfiles_raw = vim.fn.execute "oldfiles" + local oldfiles_raw = vim.fn.execute("oldfiles") local oldfiles_amount = 0 local directory = vim.api.nvim_exec([[pwd]], true) local oldfiles = { "Last files in " .. directory, " " } @@ -146,7 +146,7 @@ local function move_up() flag = false return end - set_cursor({new_cursor_pos[1]+i,column()}) + set_cursor({ new_cursor_pos[1] + i, column() }) i = i + 1 end else @@ -158,21 +158,21 @@ local function move_up() i = 1 end while true do - set_cursor({new_cursor_pos[1]-i,column()}) + set_cursor({ new_cursor_pos[1] - i, column() }) if not bad_line() then flag = false return end i = i + 1 - if new_cursor_pos[1]-i <= 1 then + if new_cursor_pos[1] - i <= 1 then i = 1 - set_cursor({1,column()}) + set_cursor({ 1, column() }) while true do if not bad_line() then flag = false return end - set_cursor({new_cursor_pos[1]+i,column()}) + set_cursor({ new_cursor_pos[1] + i, column() }) i = i + 1 end end @@ -193,7 +193,7 @@ local function move_down() flag = false return end - set_cursor({new_cursor_pos[1]-i,column()}) + set_cursor({ new_cursor_pos[1] - i, column() }) i = i + 1 end i = 0 @@ -206,13 +206,13 @@ local function move_down() i = 1 end while true do - set_cursor({new_cursor_pos[1]+i,column()}) + set_cursor({ new_cursor_pos[1] + i, column() }) if not bad_line() then flag = false return end i = i + 1 - if new_cursor_pos[1]+i >= vim.api.nvim_buf_line_count(0) then + if new_cursor_pos[1] + i >= vim.api.nvim_buf_line_count(0) then set_cursor(U.cursor_pos) flag = false return @@ -229,9 +229,15 @@ function U.reposition_cursor() new_cursor_pos = vim.api.nvim_win_get_cursor(0) if new_cursor_pos[1] > U.cursor_pos[1] then move_down() - elseif (new_cursor_pos[1] < U.cursor_pos[1]) or new_cursor_pos[2] < U.cursor_pos[2] then + elseif + (new_cursor_pos[1] < U.cursor_pos[1]) or new_cursor_pos[2] + < U.cursor_pos[2] + then move_up() - elseif (new_cursor_pos[1] > U.cursor_pos[1]) or new_cursor_pos[2] > U.cursor_pos[2] then + elseif + (new_cursor_pos[1] > U.cursor_pos[1]) or new_cursor_pos[2] + > U.cursor_pos[2] + then move_down() end U.cursor_pos = vim.api.nvim_win_get_cursor(0) @@ -256,23 +262,23 @@ function U.set_buf_options() local settings = require("startup").settings vim.api.nvim_buf_set_option(0, "bufhidden", "wipe") vim.api.nvim_buf_set_option(0, "buftype", "nofile") - vim.cmd [[set wrap]] + vim.cmd([[set wrap]]) if settings.options.disable_statuslines then - vim.cmd [[set laststatus=0]] - vim.cmd [[set showtabline=0]] + vim.cmd([[set laststatus=0]]) + vim.cmd([[set showtabline=0]]) end vim.api.nvim_buf_set_option(0, "filetype", "startup") vim.api.nvim_buf_set_option(0, "swapfile", false) - vim.cmd [[setlocal nonu nornu]] + vim.cmd([[setlocal nonu nornu]]) end function U.validate_settings(options) -- NOTE: vim.validate - vim.validate { + vim.validate({ type = { options.type, function(arg) - for _, v in ipairs { "mapping", "oldfiles", "text" } do + for _, v in ipairs({ "mapping", "oldfiles", "text" }) do if v == arg then return true end @@ -288,7 +294,7 @@ function U.validate_settings(options) align = { options.align, function(arg) - for _, v in ipairs { "right", "left", "center" } do + for _, v in ipairs({ "right", "left", "center" }) do if v == arg then return true end @@ -301,9 +307,13 @@ function U.validate_settings(options) title = { options.title, "string" }, margin = { options.margin, "number" }, command = { options.command, "string" }, - content = {options.content, + content = { + options.content, function(content) - if options.type =="text" and (type(content)== "table" or type(content) == "function") then + if + options.type == "text" + and (type(content) == "table" or type(content) == "function") + then return true elseif options.type == "mapping" and type(content) == "table" then return true @@ -312,14 +322,15 @@ function U.validate_settings(options) end return false end, - "table for type=mapping and table or function for type=text"}, + "table for type=mapping and table or function for type=text", + }, default_color = { options.default_color, "string" }, highlight = { options.highlight, "string" }, oldfiles_amount = { options.oldfiles_amount, "number", }, - } + }) end return U |