Skip to content

Commit

Permalink
chore: format with stylua
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Jul 31, 2023
1 parent 5706f1e commit 8529310
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 277 deletions.
3 changes: 1 addition & 2 deletions lua/neorg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ function neorg.org_file_entered(manual, arguments)
end

-- Apply the config
config.modules[name] =
vim.tbl_deep_extend("force", config.modules[name] or {}, module.config or {})
config.modules[name] = vim.tbl_deep_extend("force", config.modules[name] or {}, module.config or {})
end

-- After all config are merged proceed to actually load the modules
Expand Down
9 changes: 3 additions & 6 deletions lua/neorg/core/config.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local lib = require("neorg.core.lib")


local function neovim_version()
local data = {}
local parsed_output = vim.api.nvim_exec("version", true)
Expand Down Expand Up @@ -40,7 +39,6 @@ local function neovim_version()
return data
end


-- Grab OS info on startup
local function os_info()
local os = vim.loop.os_uname().sysname:lower()
Expand All @@ -50,19 +48,18 @@ local function os_info()
elseif os == "darwin" then
return "mac"
elseif os == "linux" then
local f = io.open('/proc/version', 'r')
local f = io.open("/proc/version", "r")
if f ~= nil then
local version = f:read('*all')
local version = f:read("*all")
f:close()
if version:find('microsoft') then
if version:find("microsoft") then
return "wsl"
end
end
return "linux"
end
end


-- Configuration template
local config = {
user_config = {
Expand Down
44 changes: 7 additions & 37 deletions lua/neorg/core/lib.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
local lib = {
-- TODO: Are the mod functions used anywhere?
mod = { --- Modifiers for the `map` function
exclude = {} --- Filtering modifiers that exclude certain elements from a table
}
exclude = {}, --- Filtering modifiers that exclude certain elements from a table
},
}


--- Returns the item that matches the first item in statements
---@param value any #The value to compare against
---@param compare? function #A custom comparison function
Expand Down Expand Up @@ -75,7 +74,6 @@ function lib.match(value, compare)
end
end


--- Wrapped around `match()` that performs an action based on a condition
---@param comparison boolean #The comparison to perform
---@param when_true function|any #The value to return when `comparison` is true
Expand All @@ -92,7 +90,6 @@ function lib.when(comparison, when_true, when_false)
})
end


--- Maps a function to every element of a table
-- The function can return a value, in which case that specific element will be assigned
-- the return value of that function.
Expand All @@ -113,7 +110,6 @@ function lib.map(tbl, callback)
return copy
end


--- Iterates over all elements of a table and returns the first value returned by the callback.
---@param tbl table #The table to iterate over
---@param callback function #The callback function that should be invoked on each iteration.
Expand All @@ -129,7 +125,6 @@ function lib.filter(tbl, callback)
end
end


--- Finds any key in an array
---@param tbl array #An array of values to iterate over
---@param element any #The item to find
Expand All @@ -142,21 +137,18 @@ function lib.find(tbl, element)
end)
end


--- Inserts a value into a table if it doesn't exist, else returns the existing value.
---@param tbl table #The table to insert into
---@param value number|string #The value to insert
---@return any #The item to return
function lib.insert_or(tbl, value)
local item = lib.find(tbl, value)

return item and tbl[item]
or (function()
table.insert(tbl, value)
return value
end)()
end

return item and tbl[item] or (function()
table.insert(tbl, value)
return value
end)()
end

--- Picks a set of values from a table and returns them in an array
---@param tbl table #The table to extract the keys from
Expand All @@ -174,7 +166,6 @@ function lib.pick(tbl, values)
return result
end


--- Tries to extract a variable in all nesting levels of a table.
---@param tbl table #The table to traverse
---@param value any #The value to look for - note that comparison is done through the `==` operator
Expand All @@ -195,7 +186,6 @@ function lib.extract(tbl, value)
return results
end


--- Wraps a conditional "not" function in a vim.tbl callback
---@param cb function #The function to wrap
---@vararg ... #The arguments to pass to the wrapped function
Expand All @@ -207,7 +197,6 @@ function lib.wrap_cond_not(cb, ...)
end
end


--- Wraps a conditional function in a vim.tbl callback
---@param cb function #The function to wrap
---@vararg ... #The arguments to pass to the wrapped function
Expand All @@ -219,7 +208,6 @@ function lib.wrap_cond(cb, ...)
end
end


--- Wraps a function in a callback
---@param function_pointer function #The function to wrap
---@vararg ... #The arguments to pass to the wrapped function
Expand All @@ -242,7 +230,6 @@ function lib.wrap(function_pointer, ...)
end
end


--- Repeats an arguments `index` amount of times
---@param value any #The value to repeat
---@param index number #The amount of times to repeat the argument
Expand All @@ -255,7 +242,6 @@ function lib.reparg(value, index)
return value, lib.reparg(value, index - 1)
end


--- Lazily concatenates a string to prevent runtime errors where an object may not exist
-- Consider the following example:
--
Expand All @@ -273,7 +259,6 @@ function lib.lazy_string_concat(...)
return table.concat({ ... })
end


--- Converts an array of values to a table of keys
---@param values string[]|number[] #An array of values to store as keys
---@param default any #The default value to assign to all key pairs
Expand All @@ -288,7 +273,6 @@ function lib.to_keys(values, default)
return ret
end


--- Constructs a new key-pair table by running a callback on all elements of an array.
---@param keys string[] #A string array with the keys to iterate over
---@param cb function #A function that gets invoked with each key and returns a value to be placed in the output table
Expand All @@ -303,7 +287,6 @@ function lib.construct(keys, cb)
return result
end


--- If `val` is a function, executes it with the desired arguments, else just returns `val`
---@param val any|function #Either a function or any other value
---@vararg any #Potential arguments to give `val` if it is a function
Expand All @@ -316,14 +299,12 @@ function lib.eval(val, ...)
return val
end


--- Extends a list by constructing a new one vs mutating an existing
-- list in the case of `vim.list_extend`
function lib.list_extend(list, ...)
return list and { unpack(list), unpack(lib.list_extend(...)) } or {}
end


--- Converts a table with `key = value` pairs to a `{ key, value }` array.
---@param tbl_with_keys table #A table with key-value pairs
---@return array #An array of `{ key, value }` pairs.
Expand All @@ -337,7 +318,6 @@ function lib.unroll(tbl_with_keys)
return res
end


--- Works just like pcall, except returns only a single value or nil (useful for ternary operations
-- which are not possible with a function like `pcall` that returns two values).
---@param func function #The function to invoke in a protected environment
Expand All @@ -353,7 +333,6 @@ function lib.inline_pcall(func, ...)
-- return nil
end


--- Perform a backwards search for a character and return the index of that character
---@param str string #The string to search
---@param char string #The substring to search for
Expand All @@ -364,7 +343,6 @@ function lib.rfind(str, char)
return found_from_back and length - found_from_back
end


--- Ensure that a nested set of variables exists.
-- Useful when you want to initialise a chain of nested values before writing to them.
---@param tbl table #The table you want to modify
Expand All @@ -378,7 +356,6 @@ function lib.ensure_nested(tbl, ...)
end
end


--- Capitalizes the first letter of each word in a given string.
---@param str string #The string to capitalize
---@return string #The capitalized string.
Expand All @@ -393,7 +370,6 @@ function lib.title(str)
return table.concat(result, " ")
end


--- Wraps a number so that it fits within a given range.
---@param value number #The number to wrap
---@param min number #The lower bound
Expand All @@ -410,7 +386,6 @@ function lib.number_wrap(value, min, max)
return wrapped_value
end


--- Lazily copy a table-like object.
---@param to_copy table|any #The table to copy. If any other type is provided it will be copied immediately.
---@return table #The copied table
Expand Down Expand Up @@ -474,7 +449,6 @@ function lib.lazy_copy(to_copy)
})
end


--- Wrapper function to add two values
-- This function only takes in one argument because the second value
-- to add is provided as a parameter in the callback.
Expand All @@ -486,7 +460,6 @@ function lib.mod.add(amount)
end
end


--- Wrapper function to set a value to another value in a `map` sequence
---@param to any #A static value to set each element of the table to
---@return function #A callback that returns the static value
Expand All @@ -496,19 +469,16 @@ function lib.mod.modify(to)
end
end


function lib.mod.exclude.first(func, alt)
return function(i, val)
return i == 1 and (alt and alt(i, val) or val) or func(i, val)
end
end


function lib.mod.exclude.last(func, alt)
return function(i, val, tbl)
return next(tbl, i) and func(i, val) or (alt and alt(i, val) or val)
end
end


return lib
10 changes: 2 additions & 8 deletions lua/neorg/core/modules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ function modules.create(name, imports)
return new_module
end


--- Constructs a metamodule from a list of submodules. Metamodules are modules that can autoload batches of modules at once.
---@param name string #The name of the new metamodule. Make sure this is unique. The recommended naming convention is category.module_name or category.subcategory.module_name
-- @Param ... (varargs) - a list of module names to load.
Expand Down Expand Up @@ -197,7 +196,6 @@ function modules.create_meta(name, ...)
return module
end


-- TODO: What goes below this line until the next notice used to belong to modules
-- We need to find a way to make these functions easier to maintain

Expand Down Expand Up @@ -470,8 +468,7 @@ function modules.load_module(module_name, cfg)
module.config.custom = cfg
module.config.public = vim.tbl_deep_extend("force", module.config.public, config)
else
module.config.public =
vim.tbl_deep_extend("force", module.config.public, config.modules[module_name] or {})
module.config.public = vim.tbl_deep_extend("force", module.config.public, config.modules[module_name] or {})
end

-- Pass execution onto load_module_from_table() and let it handle the rest
Expand Down Expand Up @@ -567,7 +564,6 @@ function modules.await(module_name, callback)
end)
end


-- TODO: What goes below this line until the next notice used to belong to modules
-- We need to find a way to make these functions easier to maintain

Expand All @@ -577,7 +573,6 @@ end
-- All modules that subscribe to an event will receive it once it is triggered.
--]]


--- The working of this function is best illustrated with an example:
-- If type == 'core.some_plugin.events.my_event', this function will return { 'core.some_plugin', 'my_event' }
---@param type string #The full path of a module event
Expand Down Expand Up @@ -659,8 +654,7 @@ function modules.create_event(module, type, content)
local module_name = modules.split_event_type(type)[1]

-- Retrieve the template from module.events.defined
local event_template =
modules.get_event_template(modules.loaded_modules[module_name] or { name = "" }, type)
local event_template = modules.get_event_template(modules.loaded_modules[module_name] or { name = "" }, type)

if not event_template then
log.warn("Unable to create event of type", type, ". Returning nil...")
Expand Down
Loading

0 comments on commit 8529310

Please sign in to comment.