Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit 561d37f

Browse files
Merge pull request #34 from tlindsay/master
Implement after_open callback
2 parents 606bb0f + 99b75cc commit 561d37f

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Here is the default configuration:
7373
picker_cmd = false, -- use cmd previewer in picker preview
7474
picker_cmd_args = {}, -- example using glow: { "-p" }
7575
ensure_installed = {}, -- get automatically installed
76+
after_open = function(bufnr) end, -- callback that runs after the Devdocs window is opened. Devdocs buffer ID will be passed in
7677
}
7778
```
7879

@@ -96,6 +97,19 @@ Available commands:
9697

9798
Commands support completion, and the Telescope picker will be used when no argument is provided.
9899

100+
## Lifecycle Hook
101+
102+
An `after_open` callback is supplied which accepts the buffer ID of the Devdocs window. It can be used for things like buffer-specific keymaps:
103+
104+
```lua
105+
require('nvim-devdocs').setup({
106+
-- ...
107+
after_open = function(bufnr)
108+
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Esc>', ':close<CR>', {})
109+
end
110+
})
111+
```
112+
99113
## TODO
100114

101115
- More search options

lua/nvim-devdocs/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local config = {
1616
picker_cmd = false,
1717
picker_cmd_args = {},
1818
ensure_installed = {},
19+
after_open = function() end
1920
}
2021

2122
M.get = function() return config end

lua/nvim-devdocs/operations.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ M.open = function(alias, bufnr, pattern, float)
237237
else
238238
vim.bo[bufnr].ft = "markdown"
239239
end
240+
241+
plugin_config.after_open(bufnr)
240242
end
241243

242244
return M

0 commit comments

Comments
 (0)