Skip to content

Commit

Permalink
feat: allow accessing documentation
Browse files Browse the repository at this point in the history
fixes #128
  • Loading branch information
max397574 committed Nov 9, 2024
1 parent 36a5ffc commit e70df3b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/configuration_recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,44 @@ for i, label in ipairs(labels) do
require("care").api.confirm()
end)
end

```

## Access Documentation

You can use these function to access documentation. This e.g. allows to copy it
to somewhere for reference or to click links in it easily.

They have to be called while the documentation window of care is actually open.

### Open in split

This function opens the documentation in a split window.

```lua
local documentation = require("care").api.get_documentation()
if #documentation == 0 then
return
end
local old_win = vim.api.nvim_get_current_win()
vim.cmd.wincmd("s")
local buf = vim.api.nvim_create_buf(false, true)
vim.bo[buf].ft = "markdown"
vim.api.nvim_buf_set_lines(buf, 0, -1, false, documentation)
vim.api.nvim_win_set_buf(0, buf)
vim.api.nvim_set_current_win(old_win)
```

### Copy to clipboard

This function copies the documentation to the clipboard (or any other register).

```lua
local documentation = require("care").api.get_documentation()
if #documentation == 0 then
return
end
vim.fn.setreg("+", table.concat(documentation, "\n"))
```

## Manual completion like builtin neovim
Expand Down
5 changes: 5 additions & 0 deletions lua/care/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ care.api = {
doc_is_open = function()
return care.core and care.core.menu and care.core.menu:docs_visible()
end,
get_documentation = function()
return care.core.menu:docs_visible()
and vim.api.nvim_buf_get_lines(care.core.menu.docs_window.buf, 0, -1, false)
or {}
end,
scroll_docs = function(delta)
care.core.menu:scroll_docs(delta)
end,
Expand Down

0 comments on commit e70df3b

Please sign in to comment.