From 737acecf1ba51039178c52c23d763b7da04c8781 Mon Sep 17 00:00:00 2001 From: max397574 Date: Tue, 9 Nov 2021 07:17:30 +0100 Subject: =?UTF-8?q?refactor(all):=20=F0=9F=94=84make=20some=20things=20sim?= =?UTF-8?q?pler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/startup/init.lua | 60 +++++++++++++++++---------------------------------- lua/startup/utils.lua | 23 +------------------- 2 files changed, 21 insertions(+), 62 deletions(-) (limited to 'lua/startup') diff --git a/lua/startup/init.lua b/lua/startup/init.lua index 59747c2..ef23d5a 100644 --- a/lua/startup/init.lua +++ b/lua/startup/init.lua @@ -17,8 +17,11 @@ local opts = { noremap = true, silent = true } local settings = require("startup.config") local utils = require("startup.utils") +local U = require("startup.utils") local spaces = utils.spaces +local buf_map = function(mapping,command) vim.api.nvim_buf_set_keymap(0,"n",mapping,command,opts) end + function startup.open_section() vim.api.nvim_buf_set_option(0, "modifiable", true) local line_nr = vim.api.nvim_win_get_cursor(0)[1] @@ -26,10 +29,7 @@ function startup.open_section() local section_align = section_alignments[section_name] local section_highlight = startup.section_highlights[section_name] local section_entries = startup.sections[section_name] - if section_name == "" then - return - end - if section_entries == nil then + if section_entries == nil or section_name == "" then return end section_entries = require("startup").align(section_entries, section_align) @@ -64,41 +64,21 @@ function startup.open_section() end local function create_mappings(mappings) - vim.api.nvim_buf_set_keymap( - 0, - "n", + buf_map( settings.mappings.execute_command, - ":lua require'startup'.check_line()", - opts - ) - vim.api.nvim_buf_set_keymap( - 0, - "n", + ":lua require'startup'.check_line()") + buf_map( settings.mappings.open_file, - "lua require('startup').open_file()", - opts - ) - vim.api.nvim_buf_set_keymap( - 0, - "n", + "lua require('startup').open_file()") + buf_map( settings.mappings.open_section, - "lua require'startup'.open_section()", - opts - ) - vim.api.nvim_buf_set_keymap( - 0, - "n", + "lua require'startup'.open_section()") + buf_map( settings.mappings.open_file_split, - "lua require('startup').open_file_vsplit()", - opts - ) - vim.api.nvim_buf_set_keymap( - 0, - "n", + "lua require('startup').open_file_vsplit()") + buf_map( settings.mappings.open_help, - "lua require'startup.utils'.key_help()", - opts - ) + "lua require'startup.utils'.key_help()") if mappings ~= {} then for _, cmd in pairs(mappings) do vim.api.nvim_buf_set_keymap( @@ -224,11 +204,11 @@ function startup.display() if options.highlight == "" then vim.cmd( "highlight Startup" - .. part - .. " guifg=" - .. options.default_color - .. " guibg=" - .. settings.colors.background + .. part + .. " guifg=" + .. options.default_color + .. " guibg=" + .. settings.colors.background ) options.highlight = "Startup" .. part end @@ -318,7 +298,7 @@ function startup.display() if settings.folded_section_color ~= "" then vim.cmd( [[highlight StartupFoldedSection guifg=]] - .. settings.colors.folded_section + .. settings.colors.folded_section ) end -- current_section = "" diff --git a/lua/startup/utils.lua b/lua/startup/utils.lua index 62d9cca..76b6f4b 100644 --- a/lua/startup/utils.lua +++ b/lua/startup/utils.lua @@ -1,4 +1,4 @@ -U = {} +local U = {} local flag = false local new_cursor_pos local help_window @@ -17,13 +17,6 @@ local function bad_line() return true end --- local colors = require("startup.config").colors -local colors = { - background = "#1f2227", - heading_fg = "#009900", - tools_fg = "#009900", -} - U.cursor_pos = vim.api.nvim_win_get_cursor(0) function U.spaces(amount) @@ -34,20 +27,6 @@ function U.key_help() local settings = require("startup").settings local buf = vim.api.nvim_create_buf(false, true) vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe") - vim.api.nvim_buf_set_keymap( - buf, - "n", - "", - "q", - { noremap = true, silent = true, nowait = true } - ) - vim.api.nvim_buf_set_keymap( - buf, - "n", - "q", - "q", - { noremap = true, silent = true, nowait = true } - ) local lines = { " Startup.nvim Mappings ", "", -- cgit v1.2.3