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

Compare commits

...

3 Commits

Author SHA1 Message Date
Eric Wong
fb7bb88485 feat(zkbrowser): use <LeftRelease> to filter tag 2024-12-11 10:10:34 +08:00
Eric Wong
4b61259a80 feat(zettelkasten): filter zk tags 2024-12-11 00:30:08 +08:00
Eric Wong
b89c9f320a feat(zettelkasten): detach vim-zettelkasten plugin
update

zettelkasten browser statusline

update

update readme

update
2024-12-10 22:35:57 +08:00
17 changed files with 249 additions and 141 deletions

View File

@ -382,6 +382,27 @@ EOT
_checkdir doc/
_detach_bundle vim-cheat doc/vim-cheat.txt
;;
vim-zettelkasten)
git clone https://github.com/wsdjeg/vim-zettelkasten.git detach/$1
cd detach/$1
_detact LICENSE
_checkdir plugin/
_detach_bundle vim-zettelkasten plugin/zettelkasten.lua
_detach_bundle vim-zettelkasten README.md
_checkdir doc/
_detach_bundle vim-zettelkasten doc/vim-zettelkasten.txt
_checkdir ftdetect
_detach_bundle vim-zettelkasten ftdetect/zettelkasten.lua
_checkdir ftplugin
_detach_bundle vim-zettelkasten ftplugin/markdown.lua
_detach_bundle vim-zettelkasten ftplugin/zkbrowser.lua
_checkdir lua/zettelkasten
_detach_bundle vim-zettelkasten lua/zettelkasten.lua
_detach_bundle vim-zettelkasten lua/zettelkasten/browser.lua
_detach_bundle vim-zettelkasten lua/zettelkasten/config.lua
_detach_bundle vim-zettelkasten lua/zettelkasten/formatter.lua
_detach_bundle vim-zettelkasten lua/zettelkasten/log.lua
;;
xmake.vim)
git clone https://github.com/wsdjeg/xmake.vim.git detach/$1
cd detach/$1

View File

@ -7,7 +7,7 @@ jobs:
strategy:
fail-fast: false
matrix:
detachPlugin: ["FlyGrep.vim", "dein-ui.vim", "vim-todo", "iedit.vim", "scrollbar.vim", "vim-chat", "vim-cheat", "xmake.vim", "GitHub.vim", "JavaUnit.vim", "git.vim", "cpicker.nvim", "SourceCounter.vim"]
detachPlugin: ["FlyGrep.vim", "dein-ui.vim", "vim-todo", "iedit.vim", "scrollbar.vim", "vim-chat", "vim-cheat", "xmake.vim", "GitHub.vim", "JavaUnit.vim", "git.vim", "cpicker.nvim", "SourceCounter.vim", "vim-zettelkasten"]
runs-on: ubuntu-latest
steps:
- name: Checkout

View File

@ -10,7 +10,7 @@ function! SpaceVim#layers#zettelkasten#plugins() abort
let plugins = []
call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-zettelkasten',
\ {
\ 'merged' : 0, 'on_cmd' : ['ZkNew', 'ZkBrowse', 'ZkListTemplete'], 'loadconf' : 1,
\ 'merged' : 0, 'on_cmd' : ['ZkNew', 'ZkBrowse', 'ZkListTemplete', 'ZkListTags'], 'loadconf' : 1,
\ }])
return plugins
endfunction
@ -30,6 +30,7 @@ function! SpaceVim#layers#zettelkasten#config() abort
let g:_spacevim_mappings_space.m.z = {'name' : '+zettelkasten'}
call SpaceVim#mapping#space#def('nnoremap', ['m', 'z', 'n'], 'ZkNew', 'create-new-zettel-note', 1)
call SpaceVim#mapping#space#def('nnoremap', ['m', 'z', 't'], 'ZkListTemplete', 'zettel-template', 1)
call SpaceVim#mapping#space#def('nnoremap', ['m', 'z', 'g'], 'ZkListTags', 'zettel-tags', 1)
call SpaceVim#mapping#space#def('nnoremap', ['m', 'z', 'b'], 'ZkBrowse', 'open-zettelkasten-browse', 1)
endfunction

View File

@ -1,24 +0,0 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

View File

@ -1,70 +1,36 @@
# vim-zettelkasten
`vim-zettelkasten` is a [Zettelkasten](https://zettelkasten.de) note taking plugin.
> _vim-zettelkasten_ is a [Zettelkasten](https://zettelkasten.de) note taking plugin, which is forked from [zettelkasten.nvim@fe174666](https://github.com/Furkanzmc/zettelkasten.nvim/tree/fe1746666e27c2fcc0e60dc2786cb9983b994759).
It is based on [zettelkasten.nvim@fe174666](https://github.com/Furkanzmc/zettelkasten.nvim/tree/fe1746666e27c2fcc0e60dc2786cb9983b994759)
[![](https://spacevim.org/img/build-with-SpaceVim.svg)](https://spacevim.org)
[![GPLv3 License](https://img.spacevim.org/license-GPLv3-blue.svg)](LICENSE)
Using this plugin, you can:
<!-- vim-markdown-toc GFM -->
1. Create new notes with unique IDs (`:help :ZkNew`)
- [Install](#install)
- [Feedback](#feedback)
2. List the places where a tag is used with `:tselect tag_name` or use Vim's own tag shortcuts for
navigation.
<!-- vim-markdown-toc -->
3. Use `i_CTRL-X_CTRL-]` to get a list of all the tags in your notes.
## Install
4. Get a completion list of note references.
1. Using `vim-zettelkasten` in SpaceVim:
5. Use `K` command to display context for a note ID.
```toml
[[layers]]
name = 'zettelkasten'
zettel_dir = 'D:\me\zettelkasten'
zettel_template_dir = 'D:\me\zettelkasten_template'
```
6. Use `gf` to navigate to a reference. As long as your `:help path` option is set correctly, this
will work.
2. Using `vim-zettelkasten` without SpaceVim:
There's no separate file type for zettelkasten. Markdown file type is used to extend the
functionality to make it easier to take notes.
```
Plug 'wsdjeg/vim-zettelkasten'
```
For the most up to date information, please do `:help zettelkasten.txt`. I won't be updating README
file for every single feature or update. You can also check out the
[wiki](https://github.com/Furkanzmc/zettelkasten.nvim/wiki) for tips and tricks on how to use
zettelkasten.nvim.
## Feedback
# Configuration
The development of this plugin is in [`SpaceVim/bundle/vim-zettelkasten`](https://github.com/SpaceVim/SpaceVim/tree/master/bundle/vim-zettelkasten) directory.
See `:help zettelkasten.txt` for more information.
# TODO
Potential ideas to implement in the future:
- [ ] A graph view (Possible with an external CLI program.)
- [X] A sidebar (or preview window) to display the linked notes.
- [ ] Telescope support. It's a popular plugin so it'd be useful but I don't use Telescope so
contributions for this feature is most welcome!
# Project Goals
I started the project out of a bout of excitement for having discovered the Zettelkasten note
taking system. I've been looking for better ways to take notes and this system seems to fulfill my
needs. Since I love Vim, and Zettelkasten is a text based system (Which is what I love the most
about it), I decided to create a plugin immediately.
My goal is not to turn this into a huge thing with custom pickers, and file types, and a gazillion
mapping and commands. My goal is to make use of the existing Vim options/mappings/features to
extend markdown file type so it's more convenient to navigate, discover, and write.
As you can see from its initial state, the only thing you need to really know about this plugin is
the `:ZkNew` command. Everything else can be discovered as you are flexing your usual Vim muscles
(e. `gf`, `i_CTRL-X_CTRL-]`, `CTRL-]`).
In true Vim philosophy, I also want to make it easier for people to extend this plugin to their own
needs. So, all the Lua API will be nicely designed so you can interface this plugin with others
(e.g `Telescope.nvim`) or create your own workflow easily.
Please also see `:help zettelkasten.nvim-101` and `:help zettelkasten-philosophy`.
# Related Projects
- [zk-nvim](https://github.com/mickael-menu/zk-nvim)
- [zettel.vim](https://github.com/Aarleks/zettel.vim/)
- [telekasten.nvim](https://github.com/renerocksai/telekasten.nvim)
- [marty-oehme/zettelkasten.nvim](https://github.com/marty-oehme/zettelkasten.nvim)
If you encounter any bugs or have suggestions, please file an issue in the [issue tracker](https://github.com/SpaceVim/SpaceVim/issues)

View File

@ -8,21 +8,15 @@ 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')
vim.opt_local.errorformat = '%f:%l: %m'
if vim.opt_local.keywordprg:get() == '' then
vim.opt_local.keywordprg = ':ZkHover -preview'
end
if vim.opt_local.tagfunc:get() == '' then
vim.opt_local.tagfunc = 'v:lua.zettelkasten.tagfunc'
end
vim.opt_local.keywordprg = ':ZkHover -preview'
vim.opt_local.tagfunc = 'v:lua.zettelkasten.tagfunc'
local win = require('spacevim.api.vim.window')
local hi = require('spacevim.api.vim.highlight')
require('zettelkasten').add_hover_command()
@ -52,22 +46,28 @@ if vim.fn.mapcheck('[I', 'n') == '' then
end
end,
})
vim.api.nvim_buf_set_keymap(0, 'n', '<C-l>', '', {
noremap = true,
silent = true,
nowait = true,
callback = function()
vim.cmd('ZkBrowse')
end,
})
vim.api.nvim_buf_set_keymap(0, 'n', '<LeftRelease>', '', {
noremap = true,
silent = true,
nowait = true,
callback = function()
if hi.syntax_at() == 'ZettelKastenTags' then
vim.cmd('ZkBrowse #' .. vim.fn.expand('<cword>') )
end
end,
})
end
local config = require('zettelkasten.config')
if config.zettel_dir ~= '' then
vim.cmd('lcd ' .. config.zettel_dir)
end
vim.api.nvim_create_autocmd({ 'BufEnter' }, {
group = vim.api.nvim_create_augroup('zettelkasten_browser_events', { clear = true }),
buffer = vim.api.nvim_get_current_buf(),
callback = function(opts)
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())
vim.opt_local.syntax = 'zkbrowser'
vim.opt_local.buflisted = false
vim.opt_local.modifiable = false
end,
})

View File

@ -0,0 +1,60 @@
local action_state = require("telescope.actions.state")
local actions = require("telescope.actions")
local conf = require("telescope.config").values
local finders = require("telescope.finders")
local pickers = require("telescope.pickers")
local browser = require('zettelkasten.browser')
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
local function prepare_output_table()
local lines = {}
local result = browser.get_tags()
for _, tag in ipairs(result) do
table.insert(lines, tag.name)
end
return unique_string_table(lines)
end
local function show_script_names(opts)
opts = opts or {}
pickers.new(opts, {
prompt_title = "ZettelKasten Tags",
finder = finders.new_table {
results = prepare_output_table()
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
local entry = action_state.get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd('ZkBrowse --tags ' .. entry.value)
vim.cmd('stopinsert')
end)
return true
end,
}):find()
end
local function run()
show_script_names()
end
return require("telescope").register_extension({
exports = {
-- Default when to argument is given, i.e. :Telescope scriptnames
zettelkasten_tags = run,
},
})

View File

@ -257,23 +257,40 @@ function M.get_toc(note_id, format)
return formatter.format(lines, format)
end
function M.get_note_browser_content()
function M.get_note_browser_content(opt)
if config.zettel_dir == '' then
log.notify("'notes_path' option is required for note browsing.", log_levels.WARN, {})
return {}
end
local filter_tags = {}
for _, tag in ipairs(opt.tags) do
filter_tags[tag] = true
end
local all_notes = browser.get_notes()
local lines = {}
for _, note in ipairs(all_notes) do
table.insert(lines, {
file_name = note.file_name,
id = note.id,
references = note.references,
back_references = note.back_references,
tags = note.tags,
title = note.title,
})
local has_tag
if #opt.tags == 0 then
has_tag = true
else
for _, tag in ipairs(note.tags) do
if filter_tags[tag.name] then
has_tag = true
break
end
end
end
if has_tag then
table.insert(lines, {
file_name = note.file_name,
id = note.id,
references = note.references,
back_references = note.back_references,
tags = note.tags,
title = note.title,
})
end
end
return formatter.format(lines, config.browseformat)

View File

@ -225,4 +225,21 @@ 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
end
return M

View File

@ -1,3 +1,11 @@
--=============================================================================
-- formatter.lua --- formatter for zk notes browser
-- Copyright (c) 2024 Wang Shidong & Contributors
-- Author: Wang Shidong < wsdjeg@outlook.com >
-- URL: https://spacevim.org
-- License: GPLv3
--=============================================================================
local M = {}
local s_formatters = {
['%r'] = function(line)
@ -10,6 +18,9 @@ local s_formatters = {
return vim.fn.fnamemodify(line.file_name, ':t')
end,
['%h'] = function(line)
if vim.fn.strdisplaywidth(line.title) <= 30 then
return line.title .. string.rep(' ', 30 - vim.fn.strdisplaywidth(line.title))
end
return line.title
end,
['%d'] = function(line)

View File

@ -5,23 +5,19 @@
-- URL: https://spacevim.org
-- License: GPLv3
--=============================================================================
if vim.fn.exists(":ZkNew") == 0 then
vim.cmd([[command ZkNew :lua require('zettelkasten').zknew({})]])
end
vim.cmd([[command ZkNew :lua require('zettelkasten').zknew({})]])
if vim.fn.exists(":ZkBrowse") == 0 then
vim.cmd([[command ZkBrowse :lua _G.zettelkasten.zkbrowse()]])
end
if vim.fn.exists(":ZkListTemplete") == 0 then
vim.cmd([[command ZkListTemplete :Telescope zettelkasten_template]])
end
vim.cmd([[command ZkListTemplete :Telescope zettelkasten_template]])
vim.cmd([[command ZkListTags :Telescope zettelkasten_tags]])
vim.api.nvim_create_user_command('ZkBrowse', function(opt)
require('zettelkasten.browser').browse(opt.fargs)
end, { nargs = '*' })
_G.zettelkasten = {
tagfunc = require("zettelkasten").tagfunc,
completefunc = require("zettelkasten").completefunc,
zknew = require("zettelkasten").zknew,
zkbrowse = function()
vim.cmd("edit zk://browser")
end,
tagfunc = require('zettelkasten').tagfunc,
completefunc = require('zettelkasten').completefunc,
zknew = require('zettelkasten').zknew,
zkbrowse = function()
vim.cmd('edit zk://browser')
end,
}

View File

@ -1,6 +0,0 @@
column_width = 100
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferSingle"
call_parentheses = "Always"

View File

@ -2,12 +2,14 @@ if "zkbrowser" !=# get(b:, "current_syntax", "zkbrowser")
finish
endif
syntax match ZkFileName '[0-9]\+-[0-9]\+-[0-9]\+-[0-9]\+-[0-9]\+-[0-9]\+\.md'
syntax match ZkRefCount '\[[0-9]\+ .*\]'
syntax match ZkTag '#\<\k\+\>'
syntax match ZettelKastenID '[0-9]\+-[0-9]\+-[0-9]\+-[0-9]\+-[0-9]\+-[0-9]\+\.md'
syntax match ZettelKastenDash '\s-\s'
syntax match ZettelKastenRefs '\[[0-9]\+ .*\]'
syntax match ZettelKastenTags '#\<\k\+\>'
highlight default link ZkFileName Label
highlight default link ZkRefCount Link
highlight default link ZkTag Tag
highlight default link ZettelKastenID String
highlight default link ZettelKastenDash Comment
highlight default link ZettelKastenRefs Number
highlight default link ZettelKastenTags Tag
let b:current_syntax = "zkbrowser"

View File

@ -7,6 +7,7 @@ lua require('telescope').load_extension('task')
lua require('telescope').load_extension('neomru')
if SpaceVim#layers#isLoaded('zettelkasten')
lua require('telescope').load_extension('zettelkasten_template')
lua require('telescope').load_extension('zettelkasten_tags')
endif
if SpaceVim#layers#isLoaded('tools')
lua require('telescope').load_extension('bookmarks')

View File

@ -101,4 +101,47 @@ function M.hi_separator(a, b)
M.hi(hi_b_a)
end
local function get_color(name)
local c = vim.api.nvim_get_hl(0, { name = name })
if c.link then
return get_color(c.link)
else
return c
end
end
function M.syntax_at(...)
local lnum = select(1, ...) or vim.fn.line('.')
local col = select(2, ...) or vim.fn.col('.')
local inspect = vim.inspect_pos(0, lnum - 1, col - 1)
local name, hl
if #inspect.semantic_tokens > 0 then
local token, priority = {}, 0
for _, semantic_token in ipairs(inspect.semantic_tokens) do
if semantic_token.opts.priority > priority then
priority = semantic_token.opts.priority
token = semantic_token
end
end
if token then
name = token.opts.hl_group_link
hl = vim.api.nvim_get_hl(0, { name = token.opts.hl_group_link })
end
elseif #inspect.treesitter > 0 then
for i = #inspect.treesitter, 1, -1 do
name = inspect.treesitter[i].hl_group_link
hl = vim.api.nvim_get_hl(0, { name = name })
if hl.fg then
break
end
end
else
name = vim.fn.synIDattr(vim.fn.synID(vim.fn.line('.'), vim.fn.col('.'), 1), 'name', 'gui')
hl = get_color(name)
end
return name, hl
end
return M

View File

@ -582,6 +582,9 @@ local special_statusline = {
calender = function()
return simple_name('Calendar')
end,
zkbrowser = function()
return simple_name('Zettelkasten Browser')
end,
['vader-result'] = function()
return simple_name('Vader result')
end,