Skip to content

Commit

Permalink
updating bin
Browse files Browse the repository at this point in the history
  • Loading branch information
clpi committed Dec 15, 2024
1 parent 90b678a commit bef3a1d
Show file tree
Hide file tree
Showing 8 changed files with 1,697 additions and 387 deletions.
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@
#
# nvimf="--headless -u ./test/config/minit.lua --noplugin -c ''"

wf:
./scripts/bin/wordf
export PATH=$PATH:$HOME/word/scripts/bin

w:
./scripts/bin/word
wls:
wl:
./scripts/bin/wordls

iw:
cp -r ./scripts/bin/word ${HOME}/.local/bin/
iwl:
cp -r ./scripts/bin/word-lsp ${HOME}/.local/bin/

i: iw iwl

clean:
fd --no-ignore --glob "*-E" -x "rm" ./

v:
nvim -u ./test/config/minit.lua
nvim -u ./test/config/minit.lua # -c 'Lazy install'


# books:
# cd book && mdbook serve

# default: clean
i:

86 changes: 50 additions & 36 deletions lua/word/mod/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ local log = require("word.util.log")
local utils = require("word.util")

-- TODO: remove global
_G.Mod = {}

Mod.__index = Mod
---@class word.Mod
Mod = setmetatable({}, {
__index = Mod,
---@param self word.Mod
---@param other word.Mod
__eq = function(self, other)
return self.name == other.name
end,
---@param self word.Mod
__tostring = function(self)
return self.name
end,
})

Mod.default_mod = function(name)
return {
Expand Down Expand Up @@ -61,7 +72,7 @@ Mod.default_mod = function(name)
events = {
subscribed = { -- The events that the init is subscribed to
},
defined = { -- The events that the init itself has defined
defined = { -- The events that the init itself has defined
},
},
required = {},
Expand All @@ -82,8 +93,8 @@ function Mod.create(name, imports)
if not Mod.load_mod(fullpath) then
log.error(
"Unable to load import '"
.. fullpath
.. "'! An error (see traceback below):"
.. fullpath
.. "'! An error (see traceback below):"
)
assert(false)
end
Expand Down Expand Up @@ -175,20 +186,20 @@ function Mod.load_mod_from_table(m)
-- Invoke the setup function. This function returns whether or not the loading of the init was successful and some metadata.
---@type word.mod.Setup
local mod_load = m.setup and m.setup()
or {
loaded = true,
replaces = {},
merge = false,
requires = {},
wants = {},
}
or {
loaded = true,
replaces = {},
merge = false,
requires = {},
wants = {},
}

-- We do not expect init.setup() to ever return nil, that's why this check is in place
if not mod_load then
log.error(
"init"
.. m.name
.. "does not handle init loading correctly; init.setup() returned nil. Omitting..."
.. m.name
.. "does not handle init loading correctly; init.setup() returned nil. Omitting..."
)
return false
end
Expand Down Expand Up @@ -220,15 +231,15 @@ function Mod.load_mod_from_table(m)
if config.user.mod[req_mod] then
log.trace(
"Wanted init"
.. req_mod
.. "isn't loaded but can be as it's defined in the user's config. Loading..."
.. req_mod
.. "isn't loaded but can be as it's defined in the user's config. Loading..."
)

if not Mod.load_mod(req_mod) then
require("word.util.log").error(
"Unable to load wanted init for"
.. m.name
.. "- the init didn't load successfully"
.. m.name
.. "- the init didn't load successfully"
)

-- Modake sure to clean up after ourselves if the init failed to load
Expand All @@ -237,7 +248,8 @@ function Mod.load_mod_from_table(m)
end
else
log.error(
("Unable to load init %s, wanted dependency %s was not satisfied. Be sure to load the init and its appropriate config too!"):format(
("Unable to load init %s, wanted dependency %s was not satisfied. Be sure to load the init and its appropriate config too!")
:format(
m.name,
req_mod
)
Expand Down Expand Up @@ -296,7 +308,8 @@ function Mod.load_mod_from_table(m)
-- If this flag has already been set before, then throw an error - there is no way for us to know which hotswapped init should take priority.
if mod_to_replace.replaced then
log.error(
("Unable to replace init %s - init replacement clashing detected. This error triggers when a init tries to be replaced more than two times - word doesn't know which replacement to prioritize."):format(
("Unable to replace init %s - init replacement clashing detected. This error triggers when a init tries to be replaced more than two times - word doesn't know which replacement to prioritize.")
:format(
mod_to_replace.name
)
)
Expand Down Expand Up @@ -375,17 +388,18 @@ function Mod.load_mod(modn, cfg)
if not modl then
log.error(
"Unable to load init"
.. modn
.. "- loaded file returned nil. Be sure to return the table created by mod.create() at the end of your init.lua file!"
.. modn
.. "- loaded file returned nil. Be sure to return the table created by mod.create() at the end of your init.lua file!"
)
return false
end

if modl == true then
log.error(
"An error has occurred when loading"
.. modn
.. "- loaded file didn't return anything meaningful. Be sure to return the table created by mod.create() at the end of your init.lua file!"
.. modn
..
"- loaded file didn't return anything meaningful. Be sure to return the table created by mod.create() at the end of your init.lua file!"
)
return false
end
Expand All @@ -398,8 +412,8 @@ function Mod.load_mod(modn, cfg)
-- print(modl.config.custom, modl.config.public, config.mod[modn])
modl.config.custom = config.mod[modn]
modl.config.public =
-- vim.tbl_extend("force", modl.config.public, modl.config.custom or {})
utils.extend(modl.config.public, modl.config.custom or {})
-- vim.tbl_extend("force", modl.config.public, modl.config.custom or {})
utils.extend(modl.config.public, modl.config.custom or {})
end

-- Pass execution onto load_mod_from_table() and let it handle the rest
Expand Down Expand Up @@ -451,8 +465,8 @@ function Mod.get_mod_config(modn)
if not Mod.is_mod_loaded(modn) then
log.trace(
"Attempt to get init config with name"
.. modn
.. "failed - init is not loaded."
.. modn
.. "failed - init is not loaded."
)
return
end
Expand All @@ -475,8 +489,8 @@ function Mod.get_mod_version(modn)
if not Mod.is_mod_loaded(modn) then
log.trace(
"Attempt to get init version with name"
.. modn
.. "failed - init is not loaded."
.. modn
.. "failed - init is not loaded."
)
return
end
Expand All @@ -488,8 +502,8 @@ function Mod.get_mod_version(modn)
if not version then
log.trace(
"Attempt to get init version with name"
.. modn
.. "failed - version variable not present."
.. modn
.. "failed - version variable not present."
)
return
end
Expand Down Expand Up @@ -598,7 +612,7 @@ function Mod.create_event(m, type, content, ev)

-- Retrieve the template from init.events.defined
local event_template =
Mod.get_event_template(Mod.loaded_mod[modn] or { name = "" }, type)
Mod.get_event_template(Mod.loaded_mod[modn] or { name = "" }, type)

if not event_template then
log.warn("Unable to create event of type" .. type .. ". Returning nil...")
Expand All @@ -624,7 +638,7 @@ function Mod.create_event(m, type, content, ev)
new_event.cursor_position = vim.api.nvim_win_get_cursor(winid)
local row_1b = new_event.cursor_position[1]
new_event.line_content =
vim.api.nvim_buf_get_lines(bufid, row_1b - 1, row_1b, true)[1]
vim.api.nvim_buf_get_lines(bufid, row_1b - 1, row_1b, true)[1]
new_event.referrer = m.name
new_event.broadcast = true
new_event.buffer = bufid
Expand All @@ -642,8 +656,8 @@ function Mod.broadcast_event(event, callback)
if not event.split_type then
log.error(
"Unable to broadcast event of type"
.. event.type
.. "- invalid event name"
.. event.type
.. "- invalid event name"
)
return
end
Expand Down
Loading

0 comments on commit bef3a1d

Please sign in to comment.