diff options
author | max397574 <[email protected]> | 2021-11-10 18:50:49 +0100 |
---|---|---|
committer | max397574 <[email protected]> | 2021-11-10 18:50:49 +0100 |
commit | f99520a99d604a11609891db0d223a9adb806132 (patch) | |
tree | 3117b4639954a1acaa3a6e2b5d67b4572c2b6abf /lua | |
parent | 749f9119a85ba918ee95aba87011e8d7a4c9b2df (diff) |
docs(utils/init): 📚added annotations
Diffstat (limited to 'lua')
-rw-r--r-- | lua/startup/init.lua | 16 | ||||
-rw-r--r-- | lua/startup/utils.lua | 25 |
2 files changed, 41 insertions, 0 deletions
diff --git a/lua/startup/init.lua b/lua/startup/init.lua index 30506a4..98260b3 100644 --- a/lua/startup/init.lua +++ b/lua/startup/init.lua @@ -19,10 +19,14 @@ local settings = require("startup.config") local utils = require("startup.utils") local spaces = utils.spaces +---creates a mapping for the current buffer +---@param mapping string the mapping to use +---@param command string the command to be mapped local buf_map = function(mapping, command) vim.api.nvim_buf_set_keymap(0, "n", mapping, command, opts) end +---open fold under cursor function startup.open_section() vim.api.nvim_buf_set_option(0, "modifiable", true) local line_nr = vim.api.nvim_win_get_cursor(0)[1] @@ -98,6 +102,7 @@ local function create_mappings(mappings) end end +---ask for a filename and create file function startup.new_file() local name = vim.fn.input("Filename: > ") vim.cmd("e " .. name) @@ -105,6 +110,7 @@ end local sections_with_mappings = {} +---check if current line is one of the commands function startup.check_line() local line = vim.api.nvim_get_current_line() for _, section in ipairs(sections_with_mappings) do @@ -116,12 +122,14 @@ function startup.check_line() end end +---open file under cursor function startup.open_file() local line = vim.api.nvim_get_current_line() local filename = line vim.cmd("e " .. filename) end +---open file under cursor in split function startup.open_file_vsplit() local line = vim.api.nvim_get_current_line() local filename = line @@ -157,12 +165,17 @@ function startup.align(dict, alignment) return aligned end +---returns table with empty strings +---@param amount number amount of empty strings local function empty(amount) for _ = 1, amount, 1 do table.insert(startup.lines, { " ", "center", false, "normal" }) end end +---creates mapping names from table of mappings +---@param mappings table +---@return table function startup.mapping_names(mappings) local mapnames = {} local strings = {} @@ -333,6 +346,8 @@ function startup.display() ) end +---Create autocmds for startup.nvim and update settings with update +---@param update table the settings to use function startup.setup(update) if vim.g.startup_nvim_loaded then return @@ -348,6 +363,7 @@ function startup.setup(update) ) end +---Clears the screen and redraws the whole startup screen function startup.redraw() startup.formatted_text = {} for _, line in ipairs(startup.lines) do diff --git a/lua/startup/utils.lua b/lua/startup/utils.lua index 1e882bf..5c82545 100644 --- a/lua/startup/utils.lua +++ b/lua/startup/utils.lua @@ -4,6 +4,8 @@ local new_cursor_pos local help_window -- local startup = require"startup" +---sets cursor to position in current window +---@param cursor table table in form {row,column} local function set_cursor(cursor) vim.api.nvim_win_set_cursor(0, cursor) end @@ -19,10 +21,14 @@ end U.cursor_pos = vim.api.nvim_win_get_cursor(0) +---returns string with specified amount of spaces +---@param amount number the amount of space to return +---@return string function U.spaces(amount) return string.rep(" ", amount) end +---open float with all the keybindings function U.key_help() local settings = require("startup").settings local buf = vim.api.nvim_create_buf(false, true) @@ -53,11 +59,14 @@ function U.key_help() ) end +---close the help window function U.close_help() vim.api.nvim_win_close(help_window, false) -- vim.cmd([[autocmd! CursorMoved * lua require"startup.utils".close_help() ++once]]) end +---the default header +---@return table header strings with the default header function U.default_header() local header = { " /$$ ", @@ -72,6 +81,9 @@ function U.default_header() return header end +---get oldfiles +---@param amount number amount of oldfiles to return +---@return table oldfiles table with all the oldfiles in it function U.get_oldfiles(amount) local oldfiles = { "Last files", "" } local oldfiles_raw = vim.fn.execute("oldfiles") @@ -91,6 +103,9 @@ function U.get_oldfiles(amount) return oldfiles_aligned end +---get oldfiles of current directory +---@param amount number amount of oldfiles to return +---@return table oldfiles table with all the oldfiles in it function U.get_oldfiles_directory(amount) local oldfiles_raw = vim.fn.execute("oldfiles") local oldfiles_amount = 0 @@ -111,6 +126,7 @@ function U.get_oldfiles_directory(amount) return oldfiles_aligned end +---return column on which cursor should be positioned local column = function() local settings = require("startup").settings local column_calc @@ -122,6 +138,7 @@ local column = function() return column_calc end +---reposition cursor if cursor moved up local function move_up() flag = true local i @@ -169,6 +186,7 @@ local function move_up() return end +---reposition cursor if cursor moved down local function move_down() flag = true local i @@ -210,6 +228,7 @@ local function move_down() return end +---reposition cursor after it moved function U.reposition_cursor() if vim.o.filetype ~= "startup" or flag then return @@ -231,6 +250,9 @@ function U.reposition_cursor() U.cursor_pos = vim.api.nvim_win_get_cursor(0) end +---return longest line length +---@param lines table +---@return number longest function U.longest_line(lines) local longest = 0 for _, line in ipairs(lines) do @@ -241,6 +263,7 @@ function U.longest_line(lines) return longest end +---set all the options that should be set for the startup buffer function U.set_buf_options() local settings = require("startup").settings vim.api.nvim_buf_set_option(0, "bufhidden", "wipe") @@ -258,6 +281,8 @@ function U.set_buf_options() vim.cmd([[setlocal nonu nornu]]) end +---validate the settings +---@param options table the settings for a section function U.validate_settings(options) -- NOTE: vim.validate vim.validate({ |