Skip to content

Commit 91c310a

Browse files
committed
adding module exmaple
1 parent b8a877e commit 91c310a

6 files changed

Lines changed: 126 additions & 25 deletions

File tree

book/lua/module/example.lua

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
local word = require("word")
2+
3+
local mod, config, util = word.mod, word.config, word.util
4+
5+
local M = mod.create("user.example", {
6+
--- @brief submodules
7+
--- child directories containing
8+
--- modules to load in tandem, relative
9+
--- to this (parent) module.
10+
--- "subexample",
11+
--- "pre_example",
12+
--- ...
13+
})
14+
15+
M.setup = function()
16+
return {
17+
requires = {
18+
---@brief required modules
19+
--- modules from builtin or custom
20+
--- modules that can be loaded in (same as
21+
--- if calling `require 'module'`) as a dependency
22+
--- for the module.
23+
--- "ui.popup",
24+
--- "edit.link",
25+
--- "integration.treesitter",
26+
--- ...
27+
},
28+
loaded = true,
29+
}
30+
end
31+
32+
---@class (exact) example.Config
33+
M.config.public = {
34+
--- @brief module config
35+
--- the public facing config for this module that can be
36+
--- set by the user from its default values here.
37+
--- ...
38+
}
39+
40+
---@class example.Data
41+
M.data = {
42+
--- @brief module data
43+
--- the home of the module's internal data and methods
44+
--- TODO: split up concerns
45+
--- ...
46+
}
47+
48+
M.load = function()
49+
--- @brief module load
50+
--- a set of functions to run whenever the
51+
--- module is fist loaded upon startup.
52+
--- TODO: maybe just merge in with setup()
53+
--- ...
54+
end
55+
56+
return M

book/src/SUMMARY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ Welcome -- to the `word.lua` book. I hope this helps!
2626
- [Keymaps](./extend/keymaps.md)
2727
- [Autocmds](./extend/autocmd.md)
2828

29+
- [Modules](./modules.md)
30+
31+
- [Introduction](./modules/intro.md)
32+
2933
- [Customizing](./customizing.md)
3034

3135
- [Themes](./customizing/themes.md)
3236
- [Highlights](./customizing/highlights.md)
3337

3438
- [Export](./export.md)
39+
3540
- [Frameworks](./publish/frameworks.md)
3641
- [org](./export/org.md)
3742

@@ -42,6 +47,7 @@ Welcome -- to the `word.lua` book. I hope this helps!
4247
- [Digital garden](./publish/digital_garden.md)
4348

4449
- [Plans](./plans/index.md)
50+
4551
- [Near](./plans/near.md)
4652
- [Far](./plans/far.md)
4753

book/src/modules.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Modules
2+
3+
## Example custom module
4+
5+
```lua
6+
local word = require("word")
7+
8+
local mod, config, util = word.mod, word.config, word.util
9+
10+
local M = mod.create("user.example", {
11+
--- @brief submodules
12+
--- child directories containing
13+
--- modules to load in tandem, relative
14+
--- to this (parent) module.
15+
--- "subexample",
16+
--- "pre_example",
17+
--- ...
18+
})
19+
20+
M.setup = function()
21+
return {
22+
requires = {
23+
---@brief required modules
24+
--- modules from builtin or custom
25+
--- modules that can be loaded in (same as
26+
--- if calling `require 'module'`) as a dependency
27+
--- for the module.
28+
--- "ui.popup",
29+
--- "edit.link",
30+
--- "integration.treesitter",
31+
--- ...
32+
},
33+
loaded = true,
34+
}
35+
end
36+
37+
---@class (exact) example.Config
38+
M.config.public = {
39+
--- @brief module config
40+
--- the public facing config for this module that can be
41+
--- set by the user from its default values here.
42+
--- ...
43+
}
44+
45+
---@class example.Data
46+
M.data = {
47+
--- @brief module data
48+
--- the home of the module's internal data and methods
49+
--- TODO: split up concerns
50+
--- ...
51+
}
52+
53+
M.load = function()
54+
--- @brief module load
55+
--- a set of functions to run whenever the
56+
--- module is fist loaded upon startup.
57+
--- TODO: maybe just merge in with setup()
58+
--- ...
59+
end
60+
61+
return M
62+
63+
```

book/src/modules/intro.md

Whitespace-only changes.

lua/word/mod/edit/link/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ link from the word under the cursor or a visual selection (if there is one).
473473
M.load = function()
474474
mod.await("cmd", function(cmd)
475475
cmd.add_commands_from_table({
476-
preview = {
476+
link = {
477477
name = "link",
478478
subcommands = {
479479
update = {

test/config/init.lua

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)