Skip to content

Commit 1220f40

Browse files
committed
cleaning up unneeded files - telescope, util/ft, etc.
1 parent cbd52c9 commit 1220f40

File tree

45 files changed

+557
-1418
lines changed

Some content is hidden

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

45 files changed

+557
-1418
lines changed

doc/down.txt

Lines changed: 162 additions & 355 deletions
Large diffs are not rendered by default.

lua/down.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
---@tags markdown, org-mode, note-taking, knowledge-management, developer-tools, productivity
88
---
99
---@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.
10+
---@brief note-taking and knowledge management environment, offering the comfort familiarity, and compatibility of a traditional markdown note-taking environment with the power of org-mode.
1111

1212
--- The main entry point for the down plugin
1313
---@class down.Down
14-
local Down = {
14+
Down = {
1515
--- The configuration for the plugin
1616
config = require("down.config"),
1717
--- The module logic for the plugin
@@ -34,7 +34,7 @@ Down.setup = function(user, ...)
3434
Down:start()
3535
end
3636

37-
--- Start the plugin
37+
--- *Start* the ^down.nvim^ plugin
3838
--- Load the workspace and user modules
3939
function Down:start()
4040
self.util.log.trace("Setting up down")
@@ -54,7 +54,7 @@ end
5454
function Down:after()
5555
self.config:after()
5656
for _, l in pairs(self.mod.mods) do
57-
self.event.load_cb(l)
57+
self.event.load_callback(l)
5858
l.after()
5959
end
6060
self:broadcast("started")

lua/down/event/autocmd.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--- Autocmd module.
2+
local Autocmd = {}
3+
4+
return Autocmd

lua/down/event/callback.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
local Callback = {}
2+
3+
return Callback

lua/down/event/init.lua

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ local Event = {
3333
},
3434
}
3535

36+
--- Callback
3637
--- @class down.Callback
37-
--- @field callbacks table<string, { [1]: fun(event: down.Event, content: table|any), [2]?: fun(event: down.Event): boolean }>
38-
local Cb = {
38+
--- @field cb table<string, { [1]: fun(event: down.Event, content: table|any), [2]?: fun(event: down.Event): boolean }>
39+
local Callback = {
3940
---@type table<string, { [1]: fun(event: down.Event, content: table|any), [2]?: fun(event: down.Event): boolean }>
4041
cb = {},
4142

@@ -44,9 +45,9 @@ local Cb = {
4445
}
4546

4647
--- @param ty? string
47-
--- @return { [1]: fun(event: down.Event, content: table|any)> }
48+
--- @return { [1]: fun(event: down.Event, content: table|any) }
4849
function Event:get_cb(ty)
49-
return Cb.cb[ty or self.id]
50+
return Callback.cb[ty or self.id]
5051
end
5152

5253
--- Triggers a new callback to execute whenever an event of the requested type is executed.
@@ -55,21 +56,21 @@ end
5556
--- @param filt? fun(event: down.Event): boolean # A filtering function to test if a certain event meets our expectations.
5657
function Event.callback(self, cb, filt)
5758
local ty = (self and self.id) or self
58-
Cb.cb[ty] = Cb.cb[ty] or {}
59-
table.insert(Cb.cb[ty], { cb, filt })
59+
Callback.cb[ty] = Callback.cb[ty] or {}
60+
table.insert(Callback.cb[ty], { cb, filt })
6061
end
6162

6263
--- @param cb? fun(event: down.Event, content: table|any)
6364
function Event.set_callback(self, cb)
64-
Cb.cb[self.id] = Cb.cb[self.id] or {}
65-
table.insert(Cb.cb[self.id], cb)
65+
Callback.cb[self.id] = Callback.cb[self.id] or {}
66+
table.insert(Callback.cb[self.id], cb)
6667
end
6768

6869
--- Used internally by down to call all C with an event.
6970
--- @param self down.Event
7071
function Event.handle(self)
7172
log.trace("Event.handle: Handling ", self.id)
72-
local cbentry = Cb.cb[self.id]
73+
local cbentry = Callback.cb[self.id]
7374
if cbentry then
7475
for _, cb in ipairs(cbentry) do
7576
if not cb[2] or cb[2](self) then
@@ -79,7 +80,9 @@ function Event.handle(self)
7980
end
8081
end
8182

82-
function Event.load_cb(m)
83+
--- Load callback
84+
--- @param m down.Mod.Mod
85+
function Event.load_callback(m)
8386
for hk, ht in pairs(m.handle) do
8487
for ck, ct in pairs(ht) do
8588
if type(ct) == "function" then
@@ -89,8 +92,11 @@ function Event.load_cb(m)
8992
end
9093
end
9194

92-
---@type fun(module: down.Mod.Mod, name: string, body?: any): down.Event
93-
---@return down.Event
95+
--- Define a new event
96+
---@param module down.Mod.Mod The module
97+
---@param name string The name of the event
98+
---@param body any? The body payload
99+
---@return down.Event event The result event
94100
Event.define = function(module, name, body)
95101
local mn = ""
96102
if type(module) == "table" then
@@ -116,8 +122,9 @@ Event.define = function(module, name, body)
116122
}
117123
end
118124

125+
--- Split id
119126
--- @param id string The full path of a init event
120-
--- @return string[]?
127+
--- @return string[]? splitid id
121128
function Event.split_id(id)
122129
local sa, sb = id:find("%.events%.")
123130
local sp_id = { id:sub(0, sa - 1), id:sub(sb + 1) }
@@ -202,6 +209,7 @@ function Event.broadcast_to(self, mods)
202209
end
203210
end
204211

212+
--- Send an event
205213
--- @param recv down.Mod.Mod The name of a loaded init that will be the recipient of the event.
206214
--- @return nil
207215
--- @param self down.Event

lua/down/mod.lua

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ Mod.new = function(nm, im)
149149
if not Mod.load_mod(fp) then
150150
log.error(
151151
"Unable to load import '"
152-
.. fp
153-
.. "'! An error (see traceback below):"
152+
.. fp
153+
.. "'! An error (see traceback below):"
154154
)
155155
assert(false)
156156
end
@@ -167,8 +167,8 @@ Mod.delete = function(mod)
167167
end
168168

169169
--- @param m down.Mod.Mod The actual mod to load.
170-
--- @return down.Mod|nil # Whether the mod successfully loaded.
171-
Mod.load_mod_from_table = function(m, cfg)
170+
--- @return down.Mod.Mod|nil # Whether the mod successfully loaded.
171+
Mod.from_table = function(m, cfg)
172172
if Mod.mods[m.id] ~= nil then
173173
return Mod.mods[m.id]
174174
end
@@ -205,22 +205,22 @@ Mod.load_mod_from_table = function(m, cfg)
205205
end
206206

207207
--- @param n string
208-
--- @return down.config.Mod?
208+
--- @return down.Mod.Mod
209209
function Mod.check_mod(n)
210210
local modl = require("down.mod." .. n)
211211
if not modl then
212212
log.error("Mod.load_mod: could not load mod " .. n)
213213
return nil
214214
elseif modl == true then
215-
log.error("did not return valid mod: " .. n)
215+
log.error("Mod.load_mod: could not load mod " .. n)
216216
return nil
217217
end
218218
return modl
219219
end
220220

221221
--- @param modn string A path to a mod on disk. A path in down is '.', not '/'.
222222
--- @param cfg table? A config that reflects the structure of `down.config.user.setup["mod.id"].config`.
223-
--- @return down.Mod|nil # Whether the mod was successfully loaded.
223+
--- @return down.Mod.Mod|nil # Whether the mod was successfully loaded.
224224
function Mod.load_mod(modn, cfg)
225225
if Mod.mods[modn] then
226226
if cfg ~= nil then
@@ -235,30 +235,7 @@ function Mod.load_mod(modn, cfg)
235235
if cfg and not vim.tbl_isempty(cfg) then
236236
modl.config = util.extend(modl.config, cfg)
237237
end
238-
return Mod.load_mod_from_table(modl)
239-
end
240-
241-
--- Has the same principle of operation as load_mod_from_table(), except it then sets up the parent mod's "dep" table, allowing the parent to access the child as if it were a dependency.
242-
--- @param md down.Mod A valid table as returned by mod.new()
243-
--- @param parent_mod string|down.Mod If a string, then the parent is searched for in the loaded mod. If a table, then the mod is treated as a valid mod as returned by mod.new()
244-
function Mod.load_mod_as_dependency_from_table(md, parent_mod)
245-
if Mod.load_mod_from_table(md) then
246-
if type(parent_mod) == "string" then
247-
Mod.mods[parent_mod].dep[md.id] = md
248-
elseif type(parent_mod) == "table" then
249-
parent_mod.dep[md.id] = md
250-
end
251-
end
252-
end
253-
254-
--- Normally loads a mod, but then sets up the parent mod's "dep" table, allowing the parent mod to access the child as if it were a dependency.
255-
--- @param modn string A path to a mod on disk. A path in down is '.', not '/'
256-
--- @param parent_mod string The name of the parent mod. This is the mod which the dependency will be attached to.
257-
--- @param cfg? table A config that reflects the structure of down.config.user.setup["mod.id"].config
258-
function Mod.load_mod_as_dependency(modn, parent_mod, cfg)
259-
if Mod.load_mod(modn, cfg) and Mod.is_loaded(parent_mod) then
260-
Mod.mods[parent_mod].dep[modn] = Mod.mod_config(modn)
261-
end
238+
return Mod.from_table(modl)
262239
end
263240

264241
--- Returns the mod.config table if the mod is loaded
@@ -268,8 +245,8 @@ function Mod.mod_config(modn)
268245
if not Mod.is_loaded(modn) then
269246
log.trace(
270247
"Attempt to get mod config with name"
271-
.. modn
272-
.. "failed - mod is not loaded."
248+
.. modn
249+
.. "failed - mod is not loaded."
273250
)
274251
return
275252
end
@@ -326,14 +303,16 @@ function Mod.load_kind(mk, kt)
326303
end
327304
end
328305

329-
---@param m down.Mod
306+
--- Load the opts for the mod
307+
---@param m down.Mod.Mod
330308
function Mod.load_opts(m)
331309
Mod.load_kind(m.opts, function(k, v)
332310
vim.bo[k] = v
333311
end)
334312
end
335313

336-
---@param m down.Mod
314+
--- Load the maps for the mod
315+
---@param m down.Mod.Mod
337316
function Mod.load_maps(m)
338317
Mod.load_kind(m.maps, function(_, v)
339318
local opts = {
@@ -352,11 +331,12 @@ function Mod.load_maps(m)
352331
end)
353332
end
354333

355-
---@param m down.Mod
334+
--- Perform initialization for the mod
335+
---@param m down.Mod.Mod
356336
function Mod.mod_load(m)
357337
Mod.load_maps(m)
358338
Mod.load_opts(m)
359-
Event.load_cb(m)
339+
Event.load_callback(m)
360340
if m.load then
361341
m.load()
362342
end
@@ -372,7 +352,7 @@ Mod.get = function(m)
372352
end
373353
end
374354
--- @param ms? table<any, string> list of modules to load
375-
--- @return table<integer, down.Mod>
355+
--- @return down.Mod.Mod[]
376356
Mod.modules = function(ms)
377357
local modmap = {}
378358
for mname, module in pairs(ms or Mod.default.mods) do
@@ -381,7 +361,7 @@ Mod.modules = function(ms)
381361
return modmap
382362
end
383363

384-
---@param m down.Mod
364+
---@param m down.Mod.Mod
385365
Mod.test = function(m)
386366
log.info("Mod.test: Performing tests for ", m.id, ": ")
387367
if m.tests then
@@ -401,8 +381,10 @@ Mod.unloaded = modutil.ids
401381
--- @param m down.Mod.Id
402382
--- @return nil
403383
Mod.unload = function(m)
404-
if Mod.mods[m] ~= nil then
384+
local old = vim.deepcopy(Mod.mods[m])
385+
if old ~= nil then
405386
Mod.mods[m] = nil
387+
return old
406388
else
407389
if Mod.check_id(m) then
408390
log.warn("Mod.unload: Attempt to unload unloaded mod ", m)
@@ -421,24 +403,29 @@ Mod.reload = function(m)
421403
end
422404

423405
--- Syncs the unloaded modules with the loaded modules
424-
Mod.sync_unloaded = function()
406+
Mod.sync = function()
425407
for _, i in ipairs(Mod.util.ids) do
426408
if not vim.list_contains(vim.tbl_keys(Mod.mods), i) then
427409
Mod.unloaded[i] = Mod.get(i)
428410
end
429411
end
430412
end
431413

414+
Mod.sync_unloaded = Mod.sync
415+
432416
---@param cmds down.Command[]
417+
---@param self down.Mod.Mod
418+
---@param e down.Event
419+
---@param cmd string
433420
---@return boolean
434421
Mod.handle_cmd = function(self, e, cmd, cmds, ...)
435422
log.trace("Mod.handle_cmd: Handling cmd ", cmd, " for mod ", self.id)
436423
if not cmds or type(cmds) ~= "table" or not cmds[cmd] then
437424
return false
438425
end
439-
if cmds.enabled ~= nil and cmds.enabled == false then
440-
return false
441-
end
426+
-- if cmds.enabled ~= nil and cmds.enabled == false then
427+
-- return false
428+
-- end
442429
local cc = cmds[cmd]
443430
if cc.enabled ~= nil and cc.enabled == false then
444431
return false
@@ -461,16 +448,17 @@ Mod.handle_cmd = function(self, e, cmd, cmds, ...)
461448
return false
462449
end
463450

451+
--- Handles an event for a mod.
464452
--- @param e down.Event
465-
--- @param self down.Mod
453+
--- @param self down.Mod.Mod
466454
--- @param ... any
467455
--- @return boolean
468456
Mod.handle_event = function(self, e, ...)
469457
log.trace("Mod.handle_event: Handling event ", e.id, " for mod ", self.id)
470458
if
471-
self.handle
472-
and self.handle[e.split[1]]
473-
and self.handle[e.split[1]][e.split[2]]
459+
self.handle
460+
and self.handle[e.split[1]]
461+
and self.handle[e.split[1]][e.split[2]]
474462
then
475463
self.handle[e.split[1]][e.split[2]](e)
476464
return true
@@ -507,14 +495,14 @@ function Mod.broadcast(e)
507495
end
508496

509497
--- Returns an event template defined in `mod.events`.
510-
--- @param m down.Mod.Mod A reference to the mod invoking the function
498+
--- @param self down.Mod.Mod A reference to the mod invoking the function
511499
--- @param id string A full path to a valid event type (e.g. `mod.events.some_event`)
512500
--- @return down.Event?
513501
function Mod.get_event(self, id)
514502
local split = Event.split_id(id)
515503
if not split then
516504
log.warn(
517-
"Unable to get event template for event" .. tid .. "and mod" .. self.id
505+
"Unable to get event template for event" .. id .. "and mod" .. self.id
518506
)
519507
return
520508
end

0 commit comments

Comments
 (0)