1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 07:20:04 +08:00

feat(zettelkasten): add zk tags tree

This commit is contained in:
Eric Wong 2024-12-11 13:13:58 +08:00
parent fb7bb88485
commit 81400f9c23
4 changed files with 86 additions and 14 deletions

View File

@ -65,6 +65,14 @@ if vim.fn.mapcheck('[I', 'n') == '' then
end
end,
})
vim.api.nvim_buf_set_keymap(0, 'n', '<F2>', '', {
noremap = true,
silent = true,
nowait = true,
callback = function()
require('zettelkasten.browser').open_tag_tree()
end,
})
end
local config = require('zettelkasten.config')

View File

@ -0,0 +1,38 @@
if vim.b.did_ftp == true then
return
end
vim.opt_local.cursorline = true
vim.opt_local.modifiable = false
vim.opt_local.buflisted = false
vim.opt_local.number = false
vim.opt_local.relativenumber = false
vim.opt_local.bufhidden = 'wipe'
vim.opt_local.syntax = 'zktagstree'
vim.opt_local.buftype = 'nofile'
vim.opt_local.swapfile = false
vim.api.nvim_buf_set_keymap(0, 'n', '<F2>', '', {
noremap = true,
silent = true,
nowait = true,
callback = function() end,
})
vim.api.nvim_buf_set_keymap(0, 'n', '<Enter>', '', {
noremap = true,
silent = true,
nowait = true,
callback = function()
local bufnr = vim.fn.bufnr('zk://browser')
if vim.api.nvim_buf_is_valid(bufnr) then
vim.api.nvim_set_option_value('modifiable', true, { buf = bufnr })
vim.api.nvim_buf_set_lines(
bufnr,
0,
-1,
false,
require('zettelkasten').get_note_browser_content({ tags = { vim.fn.getline('.') } })
)
end
vim.api.nvim_set_option_value('modifiable', false, { buf = bufnr })
end,
})

View File

@ -17,7 +17,6 @@ local ZK_FILE_NAME_PATTERN = '%d+-%d+-%d+-%d+-%d+-%d+.md'
local s_note_cache_with_file_path = {}
local s_note_cache_with_id = {}
-- list all zettelkasten notes in specific folder
local function get_files(folder)
local files = fn.split(fn.globpath(folder, '*.md'), '\\n')
@ -225,21 +224,45 @@ function M.get_tags()
return tags
end
function M.browse(opt)
vim.cmd('edit zk://browser')
vim.opt_local.syntax = ''
vim.opt_local.modifiable = true
vim.api.nvim_buf_set_lines(
0,
0,
-1,
false,
require('zettelkasten').get_note_browser_content({ tags = opt })
)
vim.opt_local.syntax = 'zkbrowser'
vim.opt_local.buflisted = false
vim.opt_local.modifiable = false
vim.opt_local.syntax = ''
vim.opt_local.modifiable = true
vim.api.nvim_buf_set_lines(
0,
0,
-1,
false,
require('zettelkasten').get_note_browser_content({ tags = opt })
)
vim.opt_local.syntax = 'zkbrowser'
vim.opt_local.buflisted = false
vim.opt_local.modifiable = false
end
local function unique_string_table(t)
local temp = {}
for _, k in ipairs(t) do
temp[k] = true
end
local rst = {}
for m, _ in pairs(temp) do
table.insert(rst, m)
end
return rst
end
function M.open_tag_tree()
vim.cmd('30vsplit zk://tags_tree')
vim.opt_local.filetype = 'zktagstree'
vim.opt_local.modifiable = true
local lines = {}
local result = M.get_tags()
for _, tag in ipairs(result) do
table.insert(lines, tag.name)
end
vim.api.nvim_buf_set_lines(0, 0, -1, false, unique_string_table(lines))
vim.opt_local.buflisted = false
vim.opt_local.modifiable = false
end
return M

View File

@ -585,6 +585,9 @@ local special_statusline = {
zkbrowser = function()
return simple_name('Zettelkasten Browser')
end,
zktagstree = function()
return simple_name('ZkTags Tree')
end,
['vader-result'] = function()
return simple_name('Vader result')
end,