Skip to content

Commit cbd52c9

Browse files
committed
updating doc, updating mod names, moving mods
1 parent 7b84ef0 commit cbd52c9

File tree

65 files changed

+1950
-2333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1950
-2333
lines changed

doc/down.txt

Lines changed: 648 additions & 470 deletions
Large diffs are not rendered by default.

lua/down.lua

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
1-
---@author clpi
2-
---@file down.nvim 0.1.0
3-
---@license MIT
41
---@package down.nvim
5-
---@brief neovim note-taking plugin with the
6-
---@brief comfort of mmarkdown and the power of org
2+
---@brief v0.1.2-alpha
3+
---@author Chris Pecunies <clp@clp.is>
4+
---@repository https://github.com/clpi/down.nvim.git
5+
---@homepage https://down.cli.st
6+
---@license MIT
7+
---@tags markdown, org-mode, note-taking, knowledge-management, developer-tools, productivity
8+
---
9+
---@brief The Neovim plugin for the *down* _markdown_ developer-focused
10+
---@briefnote-taking and knowledge management environment, offering the comfort familiarity, and compatibility of a traditional markdown note-taking environment with the power of org-mode.
711

8-
---@class down.down
9-
local down = {
10-
---@type down.config.Config
12+
--- The main entry point for the down plugin
13+
---@class down.Down
14+
local Down = {
15+
--- The configuration for the plugin
1116
config = require("down.config"),
17+
--- The module logic for the plugin
1218
mod = require("down.mod"),
19+
--- The event logic for the plugin
1320
event = require("down.event"),
21+
--- The utility logic for the plugin
1422
util = require("down.util"),
23+
--- The log logic for the plugin
1524
log = require("down.util.log"),
1625
}
1726

1827
--- Load the user configuration, and load into config
1928
--- defined modules specifieed and workspaces
20-
--- @param user down.mod.Config user config to load
29+
--- @param user down.config.User user config to load
2130
--- @param ... string The arguments to pass into an optional user hook
22-
function down.setup(user, ...)
23-
down.util.log.trace("Setting up down")
24-
down.config:setup(user, ...)
25-
down:start()
31+
Down.setup = function(user, ...)
32+
Down.util.log.trace("Setting up down")
33+
Down.config:setup(user, ...)
34+
Down:start()
2635
end
2736

28-
function down:start()
37+
--- Start the plugin
38+
--- Load the workspace and user modules
39+
function Down:start()
2940
self.util.log.trace("Setting up down")
3041
self.mod.load_mod(
3142
"workspace",
@@ -36,35 +47,40 @@ function down:start()
3647
self.mod.load_mod(name, usermod)
3748
end
3849
end
39-
self:post_load()
50+
self:after()
4051
end
4152

42-
function down:post_load()
43-
self.config:post_load()
53+
--- After the plugin has started
54+
function Down:after()
55+
self.config:after()
4456
for _, l in pairs(self.mod.mods) do
4557
self.event.load_cb(l)
46-
l.post_load()
58+
l.after()
4759
end
4860
self:broadcast("started")
4961
end
5062

63+
--- Broadcast the message `e` or the 'started' event to all modules
5164
---@param e string
5265
---@param ... any
53-
function down:broadcast(e, ...)
66+
function Down:broadcast(e, ...)
5467
local ev = self.event.define("down", e or "started") ---@type down.Event
55-
self.event.broadcast_to(ev, down.mod.mods)
68+
self.event.broadcast_to(ev, Down.mod.mods)
5669
end
5770

5871
--- Test all modules loaded
59-
function down.test()
60-
down.config:test()
61-
for m, d in pairs(down.mod.mods) do
62-
print("Testing mod: " .. m)
63-
d.test()
72+
function Down.test()
73+
Down.config:test()
74+
for m, d in pairs(Down.mod.mods) do
75+
Down.util.log.trace("Testing mod: " .. m)
76+
Down.util.log.trace("Result: " .. d.test())
6477
end
6578
end
6679

67-
return setmetatable(down, {
80+
return setmetatable(Down, {
81+
__call = function(down, user, ...)
82+
Down.setup(user, ...)
83+
end,
6884
-- __call = function(down, user, ...)
6985
-- down.setup(user, ...)
7086
-- end,

lua/down/config.lua

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local mod = require("down.mod")
33
local modconf = require("down.mod.util")
44

55
--- The down.nvim configuration
6-
--- @class down.config.Config
6+
--- @class down.Config
77
local Config = {
88
--- Start in dev mode
99
dev = false,
@@ -37,19 +37,20 @@ end
3737
---@param v? boolean
3838
function Config:check_toggle(k, v)
3939
if
40-
k
41-
and type(k) == "string"
42-
and v
43-
and type(v) == "boolean"
44-
and vim.tbl_contains(self.toggles, k)
40+
k
41+
and type(k) == "string"
42+
and v
43+
and type(v) == "boolean"
44+
and vim.tbl_contains(self.toggles, k)
4545
then
4646
self[k] = v
4747
end
4848
end
4949

50+
--- Load the user configuration, and load into config
5051
---@param user down.mod.Config user config
5152
---@param ... any
52-
---@return down.config.Config
53+
---@return down.Config
5354
function Config:load(user, ...)
5455
if self.started and self.started == false then
5556
return self
@@ -67,7 +68,7 @@ function Config:load(user, ...)
6768
self.started = true
6869
end
6970

70-
function Config:post_load()
71+
function Config:after()
7172
return self:check_tests(require("down.mod").mods or self.user) ---@type boolean?
7273
end
7374

@@ -109,10 +110,11 @@ function Config:save(f)
109110
return vim.fn.writefile(json, self:file(f), "S")
110111
end
111112

112-
--- @param self down.config.Config
113-
---@param user down.mod.Config
114-
---@param ... any
115-
---@return down.config.Config
113+
--- Setup the down config
114+
--- @param self down.Config The down config
115+
--- @param user down.mod.Config user config to load
116+
--- @param ... any The arguments to pass into an optional user hook
117+
--- @return down.Config
116118
function Config:setup(user, ...)
117119
log.new(log.config, false)
118120
log.info("Config.setup: Log started")
@@ -137,12 +139,12 @@ end
137139
---@return boolean
138140
function Config.check_mod_test(mod)
139141
return mod ~= nil
140-
and mod.id ~= nil
141-
and modconf.check_id(mod.id)
142-
and type(mod) == "table"
143-
and mod.tests ~= nil
144-
and type(mod.tests) == "table"
145-
and not vim.tbl_isempty(mod.tests)
142+
and mod.id ~= nil
143+
and modconf.check_id(mod.id)
144+
and type(mod) == "table"
145+
and mod.tests ~= nil
146+
and type(mod.tests) == "table"
147+
and not vim.tbl_isempty(mod.tests)
146148
end
147149

148150
---@param mods? down.Mod.Mod[]
@@ -159,20 +161,20 @@ end
159161
function Config.test(mod)
160162
vim.print("Testing " .. tostring(vim.inspect(mod.id)))
161163
return vim
162-
.iter(pairs(mod.tests))
163-
:filter(function(tn, t)
164-
return tn and type(t) == "function"
165-
end)
166-
:all(function(tn, tt)
167-
if not type(tt) == "function" then
168-
return false
169-
end
170-
local res = tt(mod) or false ---@type boolean
171-
vim.print(
172-
"Testing mod " .. mod.id .. " test: " .. tn .. ": " .. tostring(res)
173-
)
174-
return res
175-
end)
164+
.iter(pairs(mod.tests))
165+
:filter(function(tn, t)
166+
return tn and type(t) == "function"
167+
end)
168+
:all(function(tn, tt)
169+
if not type(tt) == "function" then
170+
return false
171+
end
172+
local res = tt(mod) or false ---@type boolean
173+
vim.print(
174+
"Testing mod " .. mod.id .. " test: " .. tn .. ": " .. tostring(res)
175+
)
176+
return res
177+
end)
176178
end
177179

178180
return Config

lua/down/event/init.lua

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
local log = require 'down.util.log'
1+
local log = require("down.util.log")
22

33
---@class down.Event
44
local Event = {
55
autocmd = require("down.event.autocmd"),
6-
id = '',
7-
ref = '',
6+
id = "",
7+
ref = "",
88
split = {},
99
body = nil,
1010
broadcast = true,
1111
position = vim.api.nvim_win_get_cursor(0),
12-
file = vim.fn.expand('%:p'),
12+
file = vim.fn.expand("%:p"),
1313
dir = vim.fn.getcwd(),
1414
buf = vim.api.nvim_get_current_buf(),
1515
win = vim.api.nvim_get_current_win(),
@@ -25,11 +25,11 @@ local Event = {
2525
},
2626
line = vim.api.nvim_get_current_line(),
2727
char = vim.api.nvim_win_get_cursor(0)[2],
28-
file = vim.fn.expand('%:p'),
28+
file = vim.fn.expand("%:p"),
2929
buf = vim.api.nvim_get_current_buf(),
3030
win = vim.api.nvim_get_current_win(),
3131
dir = vim.fn.getcwd(),
32-
scope = 'global',
32+
scope = "global",
3333
},
3434
}
3535

@@ -82,7 +82,7 @@ end
8282
function Event.load_cb(m)
8383
for hk, ht in pairs(m.handle) do
8484
for ck, ct in pairs(ht) do
85-
if type(ct) == 'function' then
85+
if type(ct) == "function" then
8686
Event.callback(Event.define(m, ck), ct)
8787
end
8888
end
@@ -92,21 +92,21 @@ end
9292
---@type fun(module: down.Mod.Mod, name: string, body?: any): down.Event
9393
---@return down.Event
9494
Event.define = function(module, name, body)
95-
local mn = ''
96-
if type(module) == 'table' then
95+
local mn = ""
96+
if type(module) == "table" then
9797
mn = module.id
98-
elseif type(module) == 'string' then
98+
elseif type(module) == "string" then
9999
mn = module
100100
end
101-
local id = mn .. '.events.' .. name
101+
local id = mn .. ".events." .. name
102102
return { ---@type down.Event
103103
id = id,
104104
ref = mn,
105105
split = Event.split_id(id) or {},
106106
body = body or module,
107107
broadcast = true,
108108
position = vim.api.nvim_win_get_cursor(0),
109-
file = vim.fn.expand('%:p'),
109+
file = vim.fn.expand("%:p"),
110110
dir = vim.fn.getcwd(),
111111
line = vim.api.nvim_get_current_line(),
112112
buf = vim.api.nvim_get_current_buf(),
@@ -119,10 +119,10 @@ end
119119
--- @param id string The full path of a init event
120120
--- @return string[]?
121121
function Event.split_id(id)
122-
local sa, sb = id:find('%.events%.')
122+
local sa, sb = id:find("%.events%.")
123123
local sp_id = { id:sub(0, sa - 1), id:sub(sb + 1) }
124124
if #sp_id ~= 2 then
125-
log.warn('Invalid type name:' .. id)
125+
log.warn("Invalid type name:" .. id)
126126
return
127127
end
128128
return sp_id
@@ -135,10 +135,12 @@ end
135135
function Event.get_event(m, id)
136136
local split = Event.split_id(id)
137137
if not split then
138-
log.warn('Unable to get event template for event' .. id .. 'and init' .. m.id)
138+
log.warn(
139+
"Unable to get event template for event" .. id .. "and init" .. m.id
140+
)
139141
return
140142
end
141-
log.trace('Returning' .. split[2] .. 'for init' .. split[1])
143+
log.trace("Returning" .. split[2] .. "for init" .. split[1])
142144
return m.events[split[2]]
143145
end
144146

@@ -151,40 +153,48 @@ end
151153
function Event.new(m, id, body, ev)
152154
local event_template = Event.get_event(m or { id = m.id }, id)
153155
if not event_template then
154-
log.warn('Unable to create event of type' .. id .. '. Returning nil...')
156+
log.warn("Unable to create event of type" .. id .. ". Returning nil...")
155157
return
156158
end
157159
local mn = vim.deepcopy(event_template)
158160
mn.id = id
159161
mn.body = body
160162
mn.ref = m.id
161163
mn.split = assert(Event.split_id(id))
162-
mn.file = vim.fn.expand('%:t') --[[@as string]]
163-
mn.dir = vim.fn.expand('%:p:h') --[[@as string]]
164+
mn.file = vim.fn.expand("%:t") --[[@as string]]
165+
mn.dir = vim.fn.expand("%:p:h") --[[@as string]]
164166
mn.buf = ev and ev.buf or vim.api.nvim_get_current_buf()
165167
mn.win = vim.api.nvim_get_current_win()
166168
mn.position = vim.api.nvim_win_get_cursor(mn.win)
167169
mn.mode = vim.api.nvim_get_mode()
168-
mn.line = vim.api.nvim_buf_get_lines(mn.buf, mn.position[1] - 1, mn.position[1], true)[1]
170+
mn.line = vim.api.nvim_buf_get_lines(
171+
mn.buf,
172+
mn.position[1] - 1,
173+
mn.position[1],
174+
true
175+
)[1]
169176
mn.broadcast = true
170177
return mn
171178
end
172179

173180
--- Sends an event to all subscribed mod. The event contains the filename, filehead, cursor position and line body as a bonus.
174181
--- @param mods down.Mod.Mod[]
175182
--- @param self down.Event
183+
--- @return nil
176184
function Event.broadcast_to(self, mods)
177185
if not self.split then
178-
log.error('Unable to broadcast event of type' .. self.id .. '- invalid event name')
186+
log.error(
187+
"Unable to broadcast event of type" .. self.id .. "- invalid event name"
188+
)
179189
return
180190
end
181191
Event.handle(self)
182192
for mid, cm in pairs(mods or {}) do
183193
if cm.handle and cm.handle[self.split[1]] then
184194
local evt = cm.handle[self.split[1]][self.split[2]]
185-
if evt == nil or type(evt) == 'nil' then
195+
if evt == nil or type(evt) == "nil" then
186196
goto broadcastcontinue
187-
elseif type(evt) == 'function' then
197+
elseif type(evt) == "function" then
188198
evt(self)
189199
end
190200
end
@@ -200,7 +210,7 @@ function Event.send(self, recv)
200210
Event.handle(self)
201211
if recv.handle and recv.handle[self.split[1]] then
202212
local evt = recv.handle[self.split[1]][self.split[2]]
203-
if evt ~= nil and type(evt) == 'function' then
213+
if evt ~= nil and type(evt) == "function" then
204214
evt(self)
205215
end
206216
end

0 commit comments

Comments
 (0)