diff options
author | max397574 <[email protected]> | 2021-12-23 15:19:00 +0100 |
---|---|---|
committer | max397574 <[email protected]> | 2021-12-23 15:19:00 +0100 |
commit | 11e66ab23fb404a4917a0d411aff66667b7fd86d (patch) | |
tree | f74d25b613d1c85bb34b4eeac733ef553018f0e9 | |
parent | 580e5057c2caf29934692d98b90151bb7b698ce8 (diff) |
chore: autoformat with stylua
-rw-r--r-- | lua/startup/init.lua | 59 | ||||
-rw-r--r-- | lua/startup/themes/dashboard.lua | 24 | ||||
-rw-r--r-- | lua/startup/themes/startify.lua | 12 | ||||
-rw-r--r-- | lua/startup/utils.lua | 72 |
4 files changed, 96 insertions, 71 deletions
diff --git a/lua/startup/init.lua b/lua/startup/init.lua index 82f339d..b37629e 100644 --- a/lua/startup/init.lua +++ b/lua/startup/init.lua @@ -52,9 +52,15 @@ local buf_map = function(mapping, command) end function startup.commands(arg) - if arg=="redraw" then startup.redraw() end - if arg == "display" then startup.display() end - if arg == "breaking_changes" then utils.breaking_changes() end + if arg == "redraw" then + startup.redraw() + end + if arg == "display" then + startup.display() + end + if arg == "breaking_changes" then + utils.breaking_changes() + end end ---open fold under cursor @@ -96,7 +102,10 @@ function startup.open_section() end table.insert(startup.open_sections, section_name) vim.cmd([[silent! %s/\s\+$//]]) -- clear trailing whitespace - vim.api.nvim_win_set_cursor(0, { line_nr, math.floor(vim.fn.winwidth(startup.window_id) / 2) }) + vim.api.nvim_win_set_cursor( + 0, + { line_nr, math.floor(vim.fn.winwidth(startup.window_id) / 2) } + ) set_buf_opt(0, "modifiable", false) -- startup.redraw() end @@ -177,11 +186,11 @@ end ---open file under cursor function startup.open_file() local filename = vim.trim(get_cur_line()) - filename = string.gsub(filename,"%[%d%] (.+)","%1") - filename = vim.fn.fnamemodify(filename,":p") + filename = string.gsub(filename, "%[%d%] (.+)", "%1") + filename = vim.fn.fnamemodify(filename, ":p") local trimmed_oldfiles = vim.tbl_map(function(ele) ele = vim.trim(ele) - ele = string.gsub(ele,"%[%d%] (.+)","%1") + ele = string.gsub(ele, "%[%d%] (.+)", "%1") return ele end, directory_oldfiles) if vim.tbl_contains(trimmed_oldfiles, filename) then @@ -197,11 +206,11 @@ end ---open file under cursor in split function startup.open_file_vsplit() local filename = vim.trim(get_cur_line()) - filename = string.gsub(filename,"%[%d%] (.+)","%1") - filename = vim.fn.fnamemodify(filename,":p") + filename = string.gsub(filename, "%[%d%] (.+)", "%1") + filename = vim.fn.fnamemodify(filename, ":p") local trimmed_oldfiles = vim.tbl_map(function(ele) ele = vim.trim(ele) - ele = string.gsub(ele,"%[%d%] (.+)","%1") + ele = string.gsub(ele, "%[%d%] (.+)", "%1") return ele end, directory_oldfiles) if vim.tbl_contains(trimmed_oldfiles, filename) then @@ -243,7 +252,9 @@ function startup.align(dict, alignment) for _, line in ipairs(dict) do table.insert( aligned, - utils.spaces(vim.fn.winwidth(startup.window_id) - max_len - margin_calculated - 10) .. line + utils.spaces( + vim.fn.winwidth(startup.window_id) - max_len - margin_calculated - 10 + ) .. line ) end end @@ -258,7 +269,9 @@ function startup.mapping_names(mappings) local mapnames = {} local strings = {} if not (mappings[1] or mappings[2]) then - log.warn("It looks like you use old syntax. Check `:Startup breaking_changes`") + log.warn( + "It looks like you use old syntax. Check `:Startup breaking_changes`" + ) old_cmd_syntax = true for title, command in pairs(mappings) do if settings.options.mapping_keys then @@ -280,19 +293,19 @@ function startup.mapping_names(mappings) else for _, mapping in pairs(mappings) do if settings.options.mapping_keys then - table.insert(strings, mapping[1]..mapping[3]) + table.insert(strings, mapping[1] .. mapping[3]) else - table.insert(strings,mapping[1]) + table.insert(strings, mapping[1]) end end local length = utils.longest_line(strings) + 18 for _, mapping in pairs(mappings) do if settings.options.mapping_keys then local space = utils.spaces(length - #mapping[3] - #mapping[1]) - table.insert(mapnames, mapping[1]..space..parse_mapping(mapping[3])) + table.insert(mapnames, mapping[1] .. space .. parse_mapping(mapping[3])) else local space = utils.spaces(length - #mapping[1]) - table.insert(mapnames,mapping[1]..space) + table.insert(mapnames, mapping[1] .. space) end end end @@ -441,8 +454,10 @@ function startup.display() set_buf_opt(0, "modifiable", false) vim.api.nvim_win_set_cursor(0, { 1, 1 }) vim.api.nvim_win_set_cursor(0, { - #settings.header.content + settings.options.paddings[1] + 1, - math.floor(vim.fn.winwidth(startup.window_id) / 2), + 1, + 2, + -- #settings.header.content + settings.options.paddings[1] + 1, + -- math.floor(vim.fn.winwidth(startup.window_id) / 2), }) vim.cmd( [[autocmd CursorMoved * lua require"startup.utils".reposition_cursor()]] @@ -463,7 +478,9 @@ function startup.setup(update) settings = require("startup.themes.dashboard") end startup.settings = settings - vim.cmd([[command! -nargs=* Startup :lua require'startup'.commands('<args>')]]) + vim.cmd( + [[command! -nargs=* Startup :lua require'startup'.commands('<args>')]] + ) vim.cmd( [[autocmd VimEnter * lua if vim.fn.argc() == 0 then require("startup").display() end]], [[autocmd BufRead * lua if vim.fn.argc() == 0 then require("startup").display() end]] @@ -499,9 +516,9 @@ function startup.redraw(other_file) set_buf_opt(0, "modifiable", false) if other_file then vim.fn.feedkeys("gg", "n") - vim.api.nvim_win_set_cursor(startup.window_id,{1,cursor[2]}) + vim.api.nvim_win_set_cursor(startup.window_id, { 1, cursor[2] }) vim.fn.win_gotoid(temp_id) - vim.api.nvim_win_set_cursor(0,temp_cursor) + vim.api.nvim_win_set_cursor(0, temp_cursor) end end diff --git a/lua/startup/themes/dashboard.lua b/lua/startup/themes/dashboard.lua index b781fc9..817ab17 100644 --- a/lua/startup/themes/dashboard.lua +++ b/lua/startup/themes/dashboard.lua @@ -8,12 +8,12 @@ local settings = { title = "Header", margin = 5, content = { - ' ███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗', - ' ████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║', - ' ██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║', - ' ██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║', - ' ██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║', - ' ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝', + " ███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗", + " ████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║", + " ██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║", + " ██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║", + " ██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║", + " ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝", }, highlight = "Statement", default_color = "", @@ -28,12 +28,12 @@ local settings = { title = "Basic Commands", margin = 5, content = { - {" Find File", "Telescope find_files", "<leader>ff" }, - {" Find Word", "Telescope live_grep", "<leader>lg" }, - {" Recent Files", "Telescope oldfiles", "<leader>of" }, - {" File Browser", "Telescope file_browser", "<leader>fb" }, - {" Colorschemes", "Telescope colorscheme", "<leader>cs" }, - {" New File", "lua require'startup'.new_file()", "<leader>nf" }, + { " Find File", "Telescope find_files", "<leader>ff" }, + { " Find Word", "Telescope live_grep", "<leader>lg" }, + { " Recent Files", "Telescope oldfiles", "<leader>of" }, + { " File Browser", "Telescope file_browser", "<leader>fb" }, + { " Colorschemes", "Telescope colorscheme", "<leader>cs" }, + { " New File", "lua require'startup'.new_file()", "<leader>nf" }, }, highlight = "String", default_color = "", diff --git a/lua/startup/themes/startify.lua b/lua/startup/themes/startify.lua index bcb50e5..7e743e9 100644 --- a/lua/startup/themes/startify.lua +++ b/lua/startup/themes/startify.lua @@ -8,13 +8,13 @@ if not user_bookmarks then bookmark_texts = {} end - for key, file in pairs(user_bookmarks) do - bookmark_texts[#bookmark_texts + 1] = key .. " " .. file - end +for key, file in pairs(user_bookmarks) do + bookmark_texts[#bookmark_texts + 1] = key .. " " .. file +end - for key, file in pairs(user_bookmarks) do - user_bookmark_mappings[key] = "<cmd>e " .. file .. "<CR>" - end +for key, file in pairs(user_bookmarks) do + user_bookmark_mappings[key] = "<cmd>e " .. file .. "<CR>" +end local cow = { " \\ ^__^", " \\ (oo)\\_______", diff --git a/lua/startup/utils.lua b/lua/startup/utils.lua index 96183dc..7bb4c68 100644 --- a/lua/startup/utils.lua +++ b/lua/startup/utils.lua @@ -4,7 +4,7 @@ local flag = false local new_cursor_pos local help_window -local log = require"startup.log" +local log = require("startup.log") local oldfiles_total = 0 local all_oldfiles = {} @@ -31,7 +31,8 @@ function U.breaking_changes() "n", "q", "<cmd>q<CR>", - { noremap = true, silent = true, nowait = true }) + { noremap = true, silent = true, nowait = true } + ) local lines = { "", " # Breaking Changes in startup.nvim", @@ -43,46 +44,43 @@ function U.breaking_changes() "", " ### Old syntax:", " ```lua", - ' content = {', + " content = {", ' [" Find File"] = { "Telescope find_files", "<leader>ff" }', ' [" Find Word"] = { "Telescope live_grep", "<leader>lg" }', ' [" Recent Files"] = { "Telescope oldfiles", "<leader>of" }', ' [" File Browser"] = { "Telescope file_browser", "<leader>fb" }', ' [" Colorschemes"] = { "Telescope colorscheme", "<leader>cs" }', [[ [" New File"] = { "lua require'startup'.new_file()", "<leader>nf" }]], - ' }', + " }", " ```", "", " ### New syntax:", " ```lua", - ' content = {', + " content = {", ' {" Find File", "Telescope find_files", "<leader>ff" }', ' {" Find Word", "Telescope live_grep", "<leader>lg" }', ' {" Recent Files", "Telescope oldfiles", "<leader>of" }', ' {" File Browser", "Telescope file_browser", "<leader>fb" }', ' {" Colorschemes", "Telescope colorscheme", "<leader>cs" }', [[ {" New File", "lua require'startup'.new_file()", "<leader>nf" }]], - ' }', + " }", " ```", } vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) local width = vim.api.nvim_win_get_width(0) local height = vim.api.nvim_win_get_height(0) - local win = vim.api.nvim_open_win( - buf, - true, - { - relative = "win", - win = 0, - -- width = math.floor(width * 0.8), - width = 85, - height = math.floor(height * 0.9), - col = math.floor((width-80) * 0.4), - row = math.floor(height * 0.1), - border = "shadow", - style = "minimal", - }) - -- vim.api.nvim_buf_add_highlight(buf, ns, "Special", 1, 0, -1) + local win = vim.api.nvim_open_win(buf, true, { + relative = "win", + win = 0, + -- width = math.floor(width * 0.8), + width = 85, + height = math.floor(height * 0.9), + col = math.floor((width - 80) * 0.4), + row = math.floor(height * 0.1), + border = "shadow", + style = "minimal", + }) + -- vim.api.nvim_buf_add_highlight(buf, ns, "Special", 1, 0, -1) vim.api.nvim_win_set_option(win, "winblend", 0) vim.api.nvim_buf_set_option(buf, "modifiable", false) vim.api.nvim_buf_set_option(buf, "filetype", "markdown") @@ -181,13 +179,17 @@ function U.key_help() table.insert(lines, " User Mappings:") table.insert(lines, "") for _, lhs in pairs(user_mappings) do - table.insert(user_map_commands,lhs) + table.insert(user_map_commands, lhs) end length = U.longest_line(user_map_commands) for rhs, lhs in pairs(user_mappings) do table.insert( lines, - " " .. lhs .. ":" .. U.spaces(length+3 - #lhs) .. parse_mapping(rhs) + " " + .. lhs + .. ":" + .. U.spaces(length + 3 - #lhs) + .. parse_mapping(rhs) ) end end @@ -208,8 +210,8 @@ function U.key_help() if not vim.tbl_isempty(user_mappings) then vim.api.nvim_buf_add_highlight(buf, ns, "Special", 7, 1, -1) for i = 9, 9 + vim.tbl_count(user_mappings), 1 do - vim.api.nvim_buf_add_highlight(buf, ns, "String", i, length+5, -1) - vim.api.nvim_buf_add_highlight(buf, ns, "Number", i, 1, length+5) + vim.api.nvim_buf_add_highlight(buf, ns, "String", i, length + 5, -1) + vim.api.nvim_buf_add_highlight(buf, ns, "Number", i, 1, length + 5) end end vim.api.nvim_win_set_option(help_window, "winblend", 20) @@ -316,7 +318,11 @@ function U.get_oldfiles_directory(amount) oldfiles_total = oldfiles_total + 1 end oldfiles = oldfiles_shortened - table.insert(oldfiles, 1, "Last Files in " .. string.gsub(directory, home, "~") .. ":") + table.insert( + oldfiles, + 1, + "Last Files in " .. string.gsub(directory, home, "~") .. ":" + ) table.insert(oldfiles, 2, "") local length = U.longest_line(oldfiles) + 2 @@ -331,7 +337,7 @@ function U.oldfiles_mappings() if not all_oldfiles then return end - for i = 0, #all_oldfiles>=10 and 9 or #all_oldfiles-1, 1 do + for i = 0, #all_oldfiles >= 10 and 9 or #all_oldfiles - 1, 1 do vim.api.nvim_buf_set_keymap( 0, "n", @@ -348,7 +354,9 @@ local column = function() local column_calc local cursor_column = settings.options.cursor_column or 0.5 if cursor_column < 1 then - column_calc = math.floor(vim.fn.winwidth(require"startup".window_id) * cursor_column) + column_calc = math.floor( + vim.fn.winwidth(require("startup").window_id) * cursor_column + ) else column_calc = cursor_column end @@ -498,10 +506,10 @@ function U.set_buf_options() ) vim.cmd( [[autocmd BufEnter * lua if vim.opt.filetype~="startup" then vim.opt.laststatus=]] - .. last_status - .. [[;vim.opt.showtabline=]] - .. tab_line - .. [[ end]] + .. last_status + .. [[;vim.opt.showtabline=]] + .. tab_line + .. [[ end]] ) end |