Skip to content

Commit 736674f

Browse files
committed
types dir -> types file, log module out of util
1 parent 603fe5c commit 736674f

File tree

43 files changed

+849
-830
lines changed

Some content is hidden

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

43 files changed

+849
-830
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,27 @@ the _familiar_, organized future for neovim and beyond!
5252
-- Place in lazy.nvim spec
5353
{
5454
"clpi/down.nvim",
55-
opts = {
55+
command = { "Down" },
56+
keys = {
57+
58+
}
59+
lazy = false,
60+
opts = {
5661
workspace = {
5762
default = "notes",
5863
workspaces = {
5964
notes = "~/notes",
60-
personal = "~/home"
65+
wiki = "~/wiki",
6166
}
6267
}
6368
},
6469
dependencies = {
6570
"nvim-treesitter/nvim-treesitter",
6671
"nvim-lua/plenary.nvim",
67-
"MunifTanjim/nui.nvim",
68-
"pysan3/pathlib.nvim",
69-
"nvim-neotest/nvim-nio",
72+
73+
-- And an optional picker, if you want that functionality
7074
"nvim-telescope/telescope.nvim", -- optional
75+
"folke/snacks.nvim", -- optional
7176
},
7277
}
7378
```

index.md

Whitespace-only changes.

lua/down.lua

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---@package down.nvim
21
---@brief v0.1.2-alpha
32
---@author Chris Pecunies <clp@clp.is>
43
---@repository https://github.com/clpi/down.nvim.git
@@ -11,7 +10,7 @@
1110

1211
--- The main entry point for the down plugin
1312
---@class down.Down
14-
Down = {
13+
local Down = {
1514
--- The configuration for the plugin
1615
config = require("down.config"),
1716
--- The module logic for the plugin
@@ -21,73 +20,70 @@ Down = {
2120
--- The utility logic for the plugin
2221
util = require("down.util"),
2322
--- The log logic for the plugin
24-
log = require("down.util.log"),
23+
log = require("down.log"),
2524
}
2625

2726
--- Load the user configuration, and load into config
2827
--- defined modules specifieed and workspaces
29-
--- @param user down.config.User user config to load
28+
--- @param user_config down.config.User user config to load
3029
--- @param ... string The arguments to pass into an optional user hook
31-
Down.setup = function(user, ...)
32-
Down.util.log.trace("Setting up down")
33-
Down.config:setup(user, ...)
30+
function Down:setup(user_config, ...)
31+
Down.log.trace("Setting up down")
32+
Down.config:setup(user_config, ...)
3433
Down:start()
3534
end
3635

3736
--- *Start* the ^down.nvim^ plugin
3837
--- Load the workspace and user modules
3938
function Down:start()
40-
self.util.log.trace("Setting up down")
41-
self.mod.load_mod(
39+
Down.log.trace("Setting up down")
40+
Down.mod.load_mod(
4241
"workspace",
43-
self.config.user.workspace or self.config.user.workspaces
42+
Down.config.user.workspace or Down.config.user.workspaces
4443
)
45-
for name, usermod in pairs(self.config.user) do
46-
if self.mod.check_id(name) then
47-
self.mod.load_mod(name, usermod)
44+
for name, usermod in pairs(Down.config.user) do
45+
if Down.mod.check_id(name) then
46+
Down.mod.load_mod(name, usermod)
4847
end
4948
end
50-
self:after()
49+
Down:after()
5150
end
5251

5352
--- After the plugin has started
5453
function Down:after()
55-
self.config:after()
56-
for _, l in pairs(self.mod.mods) do
57-
self.event.load_callback(l)
54+
Down.config:after()
55+
for _, l in pairs(Down.mod.mods) do
56+
Down.event.load_callback(l)
5857
l.after()
5958
end
60-
self:broadcast("started")
59+
Down:broadcast("started")
6160
end
6261

6362
--- Broadcast the message `e` or the 'started' event to all modules
6463
---@param e string
6564
---@param ... any
6665
function Down:broadcast(e, ...)
67-
local ev = self.event.define("down", e or "started") ---@type down.Event
68-
self.event.broadcast_to(ev, Down.mod.mods)
66+
local ev = Down.event.define("down", e or "started") ---@type down.Event
67+
Down.event.broadcast_to(ev, Down.mod.mods)
6968
end
7069

7170
--- Test all modules loaded
72-
function Down.test()
71+
function Down:test()
7372
Down.config:test()
7473
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())
74+
Down.log.trace("Testing mod: " .. m)
75+
Down.log.trace("Result: " .. d.test())
7776
end
7877
end
7978

8079
return setmetatable(Down, {
8180
__call = function(down, user, ...)
8281
Down.setup(user, ...)
8382
end,
84-
-- __call = function(down, user, ...)
85-
-- down.setup(user, ...)
86-
-- end,
87-
-- __index = function(self, key)
83+
-- __index = function(Down, key)
8884
-- return down.mod.mods[key]
8985
-- end,
90-
-- __newindex = function(self, key, val)
86+
-- __newindex = function(Down, key, val)
9187
-- down.mod.mods[key] = val
9288
-- end,
9389
})

lua/down/config.lua

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local log = require("down.util.log")
1+
local log = require("down.log")
22
local mod = require("down.mod")
33
local modconf = require("down.mod.util")
44

@@ -27,6 +27,30 @@ Config.toggles = {
2727
"bench",
2828
}
2929

30+
--- Default keymaps for down.nvim, specified in user's config
31+
--- or to be loaded via a toggle
32+
Config.keys = {
33+
{ "<space>di", "<CMD>Down index<CR>", desc = "Down index" },
34+
{ "<space>dy", "<CMD>Down yesterday<CR>", desc = "Down yesterday" },
35+
{ "<space>dt", "<CMD>Down today<CR>", desc = "Down today" },
36+
{ "<space>dm", "<CMD>Down tomorrow<CR>", desc = "Down tomorrow" },
37+
{ "<space>dw", "<CMD>Down workspace<CR>", desc = "Down workspace" },
38+
{ "<space>dc", "<CMD>Down calendar<CR>", desc = "Down calendar" },
39+
{ "<space>df", "<CMD>Down find<CR>", desc = "Down find" },
40+
{ "<space>dn", "<CMD>Down note<CR>", desc = "Down note" },
41+
{ "<space>dp", "<CMD>Down note template<CR>", desc = "Down note template" },
42+
{ "<space>dd", "<CMD>Down<CR>", desc = "Down" },
43+
}
44+
45+
--- Default dependencies for down.nvim, specified in user's config
46+
Config.dependencies = {
47+
"nvim-lua/plenary.nvim",
48+
"nvim-treesitter/nvim-treesitter",
49+
}
50+
51+
--- Default command for down.nvim, specified in user's config
52+
Config.command = { "Down" }
53+
3054
function Config:check_hook(...)
3155
if self.user.hook and type(self.user.hook) == "function" then
3256
return self.user.hook(...)
@@ -37,11 +61,11 @@ end
3761
---@param v? boolean
3862
function Config:check_toggle(k, v)
3963
if
40-
k
41-
and type(k) == "string"
42-
and v
43-
and type(v) == "boolean"
44-
and vim.tbl_contains(self.toggles, k)
64+
k
65+
and type(k) == "string"
66+
and v
67+
and type(v) == "boolean"
68+
and vim.tbl_contains(self.toggles, k)
4569
then
4670
self[k] = v
4771
end
@@ -52,9 +76,11 @@ end
5276
---@param ... any
5377
---@return down.Config
5478
function Config:load(user, ...)
55-
if self.started and self.started == false then
56-
return self
57-
elseif not type(user) == "table" then
79+
if
80+
(self.started and self.started == false)
81+
or (not type(user) == "table")
82+
or (type(user) == "nil")
83+
then
5884
return self
5985
elseif user.defaults and user.defaults == false then
6086
self.user = user
@@ -139,12 +165,12 @@ end
139165
---@return boolean
140166
function Config.check_mod_test(mod)
141167
return mod ~= nil
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)
168+
and mod.id ~= nil
169+
and modconf.check_id(mod.id)
170+
and type(mod) == "table"
171+
and mod.tests ~= nil
172+
and type(mod.tests) == "table"
173+
and not vim.tbl_isempty(mod.tests)
148174
end
149175

150176
---@param mods? down.Mod.Mod[]
@@ -161,20 +187,20 @@ end
161187
function Config.test(mod)
162188
vim.print("Testing " .. tostring(vim.inspect(mod.id)))
163189
return vim
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)
190+
.iter(pairs(mod.tests))
191+
:filter(function(tn, t)
192+
return tn and type(t) == "function"
193+
end)
194+
:all(function(tn, tt)
195+
if not type(tt) == "function" then
196+
return false
197+
end
198+
local res = tt(mod) or false ---@type boolean
199+
vim.print(
200+
"Testing mod " .. mod.id .. " test: " .. tn .. ": " .. tostring(res)
201+
)
202+
return res
203+
end)
178204
end
179205

180206
return Config

lua/down/event/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local log = require("down.util.log")
1+
local log = require("down.log")
22

33
---@class down.Event
44
local Event = {

lua/down/mod.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local Event = require("down.event")
22
local modutil = require("down.mod.util")
33
local util = require("down.util")
4-
local log = util.log
4+
local log = log
55

66
--- The Mod class is the core of the down plugin system. It is responsible for loading, unloading, and managing the lifecycle of all modules.
77
---@class down.mod.Root: down.Mod

lua/down/mod/cmd/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local down = require("down")
2-
local log = require("down.util.log")
2+
local log = require("down.log")
33
local mod = require("down.mod")
44
local util = require("down.util")
55
local api, bo, fn = vim.api, vim.bo, vim.fn

lua/down/mod/data/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local config = require("down.config")
2-
local log = require("down.util.log")
2+
local log = require("down.log")
33
local mod = require("down.mod")
44
local api, fn, fs, uv = vim.api, vim.fn, vim.fs, (vim.uv or vim.loop)
55
local stdp, join = fn.stdpath, fs.joinpath

lua/down/mod/edit/cursor/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local mod = require("down.mod")
22
local tbl = require("down.util.table")
33
local util = require("down.util")
4-
local log = util.log
4+
local log = log
55
local ts = vim.treesitter
66
local tuok, tu = pcall(require, "nvim-treesitter.ts_utils")
77

0 commit comments

Comments
 (0)