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

feat(zettelkasten): improve zettelkasten plugin

This commit is contained in:
Eric Wong 2024-12-07 21:23:02 +08:00
parent 2e6031b927
commit 3683a06c8c
3 changed files with 38 additions and 15 deletions

View File

@ -8,6 +8,7 @@ vim.opt_local.buflisted = false
vim.opt_local.syntax = 'zkbrowser'
vim.opt_local.buftype = 'nofile'
vim.opt_local.swapfile = false
vim.opt_local.buflisted = false
vim.opt_local.iskeyword:append(':')
vim.opt_local.iskeyword:append('-')
vim.opt_local.suffixesadd:append('.md')
@ -21,6 +22,8 @@ if vim.opt_local.tagfunc:get() == '' then
vim.opt_local.tagfunc = 'v:lua.zettelkasten.tagfunc'
end
local win = require('spacevim.api.vim.window')
require('zettelkasten').add_hover_command()
if vim.fn.mapcheck('[I', 'n') == '' then
@ -31,13 +34,24 @@ if vim.fn.mapcheck('[I', 'n') == '' then
'<CMD>lua require("zettelkasten").show_back_references(vim.fn.expand("<cword>"))<CR>',
{ noremap = true, silent = true, nowait = true }
)
vim.api.nvim_buf_set_keymap(
0,
'n',
'q',
':bd!<cr>',
{ noremap = true, silent = true, nowait = true }
)
vim.api.nvim_buf_set_keymap(0, 'n', 'q', '', {
noremap = true,
silent = true,
nowait = true,
callback = function()
if vim.fn.tabpagenr('$') > 1 and win.is_last_win() then
vim.cmd('quit')
return
end
local ok = pcall(function()
vim.cmd('b#')
end)
if not ok then
vim.cmd('bd')
end
end,
})
end
local config = require('zettelkasten.config')
@ -53,6 +67,7 @@ vim.api.nvim_create_autocmd({ 'BufEnter' }, {
vim.opt_local.modifiable = true
vim.api.nvim_buf_set_lines(0, 0, -1, false, require('zettelkasten').get_note_browser_content())
vim.opt_local.syntax = 'zkbrowser'
vim.opt_local.buflisted = false
vim.opt_local.modifiable = false
end,
})

View File

@ -1,3 +1,10 @@
--=============================================================================
-- browser.lua --- browser zknotes
-- Copyright (c) 2019-2024 Wang Shidong & Contributors
-- Author: Wang Shidong < wsdjeg@outlook.com >
-- URL: https://spacevim.org
-- License: GPLv3
--=============================================================================
local M = {}
local fn = vim.fn
@ -10,6 +17,8 @@ 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')
files = vim.tbl_filter(function(file)

View File

@ -7,7 +7,6 @@
--=============================================================================
local M = {}
if vim.g.zettelkasten_directory and vim.g.zettelkasten_directory ~= '' then
M.zettel_dir = vim.g.zettelkasten_directory
else
@ -20,8 +19,8 @@ else
M.templete_dir = '~/.zettelkasten_template'
end
M.browseformat = "%f - %h [%r Refs] [%b B-Refs] %t"
M.preview_command = "pedit"
M.browseformat = '%f - %h [%r Refs] [%b B-Refs] %t'
M.preview_command = 'pedit'
M.get = function()
return nil