1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:40:05 +08:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Eric Wong
5f34976cd4 feat(zktagstree): support <LeftRelease> key 2024-12-11 13:55:21 +08:00
Eric Wong
81400f9c23 feat(zettelkasten): add zk tags tree 2024-12-11 13:48:49 +08:00
4 changed files with 105 additions and 14 deletions

View File

@ -65,6 +65,14 @@ if vim.fn.mapcheck('[I', 'n') == '' then
end end
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 end
local config = require('zettelkasten.config') local config = require('zettelkasten.config')

View File

@ -0,0 +1,57 @@
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,
})
vim.api.nvim_buf_set_keymap(0, 'n', '<LeftRelease>', '', {
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_file_path = {}
local s_note_cache_with_id = {} local s_note_cache_with_id = {}
-- list all zettelkasten notes in specific folder -- list all zettelkasten notes in specific folder
local function get_files(folder) local function get_files(folder)
local files = fn.split(fn.globpath(folder, '*.md'), '\\n') local files = fn.split(fn.globpath(folder, '*.md'), '\\n')
@ -225,7 +224,6 @@ function M.get_tags()
return tags return tags
end end
function M.browse(opt) function M.browse(opt)
vim.cmd('edit zk://browser') vim.cmd('edit zk://browser')
vim.opt_local.syntax = '' vim.opt_local.syntax = ''
@ -241,5 +239,30 @@ function M.browse(opt)
vim.opt_local.buflisted = false vim.opt_local.buflisted = false
vim.opt_local.modifiable = false vim.opt_local.modifiable = false
end 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 return M

View File

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