Add tags picker to Telescope extension. (#54)

pull/57/head
deforde 2 years ago committed by GitHub
parent 80576e1041
commit 1e942d3f74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -473,9 +473,9 @@ end)
```
## Telescope Plugin
> Not recommended, instead just use the [:ZkNotes command](#built-in-commands).
> Not recommended, instead just use the [:ZkNotes or :ZkTags commands](#built-in-commands).
It's possible (but unnecessary) to also load the notes picker as a telescope plugin.
It's possible (but unnecessary) to also load the notes and tags pickers as a telescope plugin.
```lua
require("telescope").load_extension("zk")
@ -484,4 +484,6 @@ require("telescope").load_extension("zk")
```vim
:Telescope zk notes
:Telescope zk notes createdAfter=3\ days\ ago
:Telescope zk tags
:Telescope zk tags created=today
```

@ -391,10 +391,10 @@ Then, create a new file under `~/.config/nvim/ftplugin/markdown.lua` to setup th
if require("zk.util").notebook_root(vim.fn.expand('%:p')) ~= nil then
local function map(...) vim.api.nvim_buf_set_keymap(0, ...) end
local opts = { noremap=true, silent=false }
-- Open the link under the caret.
map("n", "<CR>", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
-- Create a new note after asking for its title.
-- This overrides the global `<leader>zn` mapping to create the note in the same directory as the current buffer.
map("n", "<leader>zn", "<Cmd>ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }<CR>", opts)
@ -408,7 +408,7 @@ Then, create a new file under `~/.config/nvim/ftplugin/markdown.lua` to setup th
--map('n', '<leader>zb', '<Cmd>lua vim.lsp.buf.references()<CR>', opts)
-- Open notes linked by the current buffer.
map("n", "<leader>zl", "<Cmd>ZkLinks<CR>", opts)
-- Preview a linked note.
map("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts)
-- Open the code actions for a visual selection.
@ -476,15 +476,17 @@ If you insist to use nvim-lsp-installer for `zk`, the following code snippet sho
--------------------------------------------------------------------------------
TELESCOPE PLUGIN *zk-telescope_plugin*
>
Not recommended, instead just use the :ZkNotes command (#built-in-commands).
Not recommended, instead just use the :ZkNotes or :ZkTags commands (#built-in-commands).
<
It's possible (but unnecessary) to also load the notes picker as a telescope plugin.
It's possible (but unnecessary) to also load the notes and tags pickers as a telescope plugin.
>
require("telescope").load_extension("zk")
<
>
:Telescope zk notes
:Telescope zk notes createdAfter=3\ days\ ago
:Telescope zk tags
:Telescope zk tags created=today
<

@ -6,8 +6,21 @@ local function show_notes(opts)
zk.edit(opts, { picker = "telescope", telescope = opts })
end
---@param opts? table additional options for zk, telescope options, all optional and in one table
---@see https://github.com/mickael-menu/zk/blob/main/docs/editors-integration.md#zktaglist
local function show_tags(opts)
zk.pick_tags(opts, { picker = "telescope", telescope = opts }, function(tags)
tags = vim.tbl_map(function(v)
return v.name
end, tags)
opts = vim.tbl_extend("force", { tags = tags }, opts or {})
zk.edit(opts, { picker = "telescope", telescope = opts })
end)
end
return require("telescope").register_extension({
exports = {
notes = show_notes,
tags = show_tags,
},
})

Loading…
Cancel
Save