Skip to content

Commit de5e6b2

Browse files
committed
docs: clarify custom source registration order and lazy.nvim usage
1 parent 9d7d1a7 commit de5e6b2

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,41 @@ require("focal").setup({
125125
126126
## Custom Sources
127127

128-
Register adapters for unsupported file explorers:
128+
Register adapters for unsupported file explorers. Sources can be registered before or after `setup()` — order doesn't matter:
129129

130130
```lua
131131
require("focal").register_source({
132132
filetype = "my_explorer",
133133
get_path = function()
134134
-- return the absolute path of the file under cursor, or nil
135-
return "/path/to/image.png"
135+
local node = require("my_explorer").get_current_node()
136+
if node and node.type == "file" then
137+
return node.absolute_path
138+
end
139+
return nil
136140
end,
137141
})
138142
```
139143

144+
With lazy.nvim, use `opts` as normal — focal handles queuing:
145+
146+
```lua
147+
{
148+
"hmdfrds/focal.nvim",
149+
event = "VeryLazy",
150+
dependencies = { "3rd/image.nvim" },
151+
opts = {},
152+
init = function()
153+
require("focal").register_source({
154+
filetype = "my_explorer",
155+
get_path = function()
156+
return require("my_explorer").get_file_under_cursor()
157+
end,
158+
})
159+
end,
160+
}
161+
```
162+
140163
## Custom Renderers
141164

142165
Register renderers for new file types:

0 commit comments

Comments
 (0)