Skip to content

Commit

Permalink
Removing unfinished commands, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
clpi committed Dec 15, 2024
1 parent bef3a1d commit 5ee5bb6
Show file tree
Hide file tree
Showing 35 changed files with 305 additions and 418 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,3 @@ v:
# cd book && mdbook serve

# default: clean
i:

2 changes: 1 addition & 1 deletion lua/telescope/_extensions/word/picker/linkable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ return function(opts)
search = "^\\s*(\\*+|\\|{1,2}|\\${1,2})\\s+",
use_regex = true,
search_dirs = { tostring(current_workspace) },
prompt_title = "Find in Norg files",
prompt_title = "Find in Word files",
})
end
50 changes: 23 additions & 27 deletions lua/word.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
---@file word.lua 0.1.0
---@license MIT
---@package word.lua
---@module "word"
---
---@brief neovim note-taking plugin with the
---@brief comfort of mmarkdown and the power of org
---
--- @todo TODO: make variety of commands on autocmd load markdown only
---
---@diagnostic enable
---@mle "word"
---@version JIT
---@brief neovim note-taking plugin with the
---@brief comfort of mmarkdown and the power of org

---TODO: make variety of commands on autocmd load markdown only

---@class word.word
---@field cfg word.Config
local W = {
cfg = require("word.config").config,
mod = require("word.mod"),
Expand All @@ -32,16 +30,13 @@ local W = {
}

-- local e = require("word")
local con, log, modu, utils =
require("word.config").config, W.log, W.mod, W.utils
local con, log, m, utils = require("word.config").config, W.log, W.mod, W.utils
local a, f, ext = vim.api, vim.fn, vim.tbl_deep_extend

--- @init "word.config"

--- Initializes word. Parses the supplied user config, initializes all selected mod and adds filetype checking for `.word`.
--- @param conf word.config.user? A table that reflects the structure of `config.user`.
--- @see config.user
--- @see word.config.user
--- @param conf word.config.UserMod? A table that reflects the structure of `config.user`.
function W.setup(conf)
conf = conf or { mod = {} }
if conf.mod == nil then
Expand All @@ -53,25 +48,27 @@ function W.setup(conf)
require("word.config").setup_opts()

if W.util.buf.check_md() or not con.user.lazy then
W.enter_md(false)
W.enter(false)
else
-- a.nvim_create_user_command("wordInit", function()
-- vim.cmd.delcommand("wordInit")
-- W.enter_md(true)
-- W.enter(true)
-- end, {})

a.nvim_create_autocmd("BufAdd", {
pattern = "markdown",
callback = function()
W.enter_md(false)
W.enter(false)
end,
})
end
end

function W.enter_md(manual, args)
local mod_list = con.user and con.user.mod or {}
if con.started or not mod_list or vim.tbl_isempty(mod_list) then
---@param manual table
---@param args table
function W.enter(manual, args)
local mods = con.user and con.user.mod or {}
if con.started or not mods or vim.tbl_isempty(mods) then ---@diagnostic disable-line
return
end
if con.hook then
Expand All @@ -84,22 +81,21 @@ function W.enter_md(manual, args)
end
end

for name, lm in pairs(mod_list) do
for name, lm in pairs(mods) do
con.mod[name] = utils.extend(con.mod[name] or {}, lm.config or {})
end
local load_mod = modu.load_mod
for name, _ in pairs(mod_list) do
if not load_mod(name) then
for name, _ in pairs(mods) do
if not m.load_mod(name) then
log.warn("Error recovery")
modu.loaded_mod[name] = nil
m.loaded_mod[name] = nil
end
end
for _, lm in pairs(modu.loaded_mod) do
for _, lm in pairs(m.loaded_mod) do
lm.post_load()
end
con.started = true

modu.broadcast_event({
m.broadcast({
type = "started",
split_type = {
"started",
Expand Down
2 changes: 1 addition & 1 deletion lua/word/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local f = vim.fn

--- @type word.Config
C.config = {
---@type word.config.User
---@type word.config.UserMod
user = {
mod = {
config = {},
Expand Down
2 changes: 1 addition & 1 deletion lua/word/mod/cmd/back/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ init.data = {
},
}

init.on_event = function(event)
init.on = function(event)
if event.type == "cmd.events.back" then
-- Get all the buffers
local buffers = vim.api.nvim_list_bufs()
Expand Down
Empty file added lua/word/mod/cmd/find/README.md
Empty file.
15 changes: 15 additions & 0 deletions lua/word/mod/cmd/find/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local M = require("word.mod").create("cmd.find")

---@class word.find.Config
M.config.public = {}

---@class word.find.Data
M.data = {}

M.setup = function()
return {
loaded = true,
}
end

return M
4 changes: 2 additions & 2 deletions lua/word/mod/cmd/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ M.data = {
M.events.defined[ref.name] = mod.define_event(M, ref.name)
end

mod.broadcast_event(
mod.broadcast(
assert(
mod.create_event(
M,
Expand Down Expand Up @@ -381,7 +381,7 @@ M.config.public = {

M.post_load = M.data.sync

M.on_event = function(event)
M.on = function(event)
if event.type == "cmd.events.mod.setup" then
local ok = pcall(mod.load_mod, event.content[1])

Expand Down
2 changes: 1 addition & 1 deletion lua/word/mod/cmd/mod/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ M.setup = function()
end


M.on_event = function(event)
M.on = function(event)
if event.type == "cmd.events.mod.setup" then
local ok = pcall(mod.load_mod, event.content[1])

Expand Down
2 changes: 1 addition & 1 deletion lua/word/mod/cmd/rename/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ init.data = {
},
}

init.on_event = function(event)
init.on = function(event)
if event.type == "cmd.events.rename" then
-- Get all the buffers
local buffers = vim.api.nvim_list_bufs()
Expand Down
2 changes: 1 addition & 1 deletion lua/word/mod/data/code/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ M.config.public = {
indent_errors = "notify",
}

M.on_event = function(event)
M.on = function(event)
if event.type == "cmd.events.base.code.current-file" then
local codes = M.data.code(event.buffer)

Expand Down
42 changes: 19 additions & 23 deletions lua/word/mod/data/code/snippet/init.lua
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
local M = Mod.create("data.code.snippet")
local mod = require("word.mod")
local M = mod.create("data.code.snippet")

M.setup = function()
-- mod.await("cmd", function(cmd)
-- cmd.add_commands_from_table({
-- snippet = {
-- subcommands = {
-- insert = {
-- args = 0,
-- name = "data.snippet.insert",
-- },
-- update = {
-- name = "data.snippet.update",
-- args = 0,
-- },
-- },
-- name = "snippet",
-- },
-- })
-- end)
return {
loaded = true,
requires = { "workspace", "cmd" },
}
end

M.load = function()
Mod.await("cmd", function(cmd)
cmd.add_commands_from_table({
snippet = {
subcommands = {
insert = {
args = 0,
name = "data.snippet.insert",
},
update = {
name = "data.snippet.update",
args = 0,
},
},
name = "snippet",
},
})
end)
end

M.config.public = {}

M.data.data = {}

M.data = {}

M.events.subscribed = {
Expand Down
2 changes: 1 addition & 1 deletion lua/word/mod/data/dirs/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ D.data = {
},
}

D.on_event = function(e) end
D.on = function(e) end

return D
2 changes: 1 addition & 1 deletion lua/word/mod/data/encrypt/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ E.data.data = {}

E.data = {}

E.on_event = function(e) end
E.on = function(e) end

E.events.subscribed = {
cmd = {
Expand Down
2 changes: 1 addition & 1 deletion lua/word/mod/data/export/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ E.data.data = {}

E.data = {}

E.on_event = function(e) end
E.on = function(e) end

E.events.subscribed = {
cmd = {
Expand Down
Loading

0 comments on commit 5ee5bb6

Please sign in to comment.