Conversation
|
I'm painfully stuck on this one. It's such a great feature idea, and something I've been wanting myself. But we really should do the config parsing with native E.g, zk-org/zk#484 lists the aliases, filters and extras from the config file. It would then be a case of extending this (not in the same pr though) to list also the groups, and then implementing it as an api function in zk-nvim |
|
Thanks, and I agree with you! I’ll take a look at the PR first. (Oh, it hasn't been merged for long time.) So, the step is:
right ? (I wish I could help, but I'm not familiar with Go lang at all for now.) |
|
Yep, that's correct. It would ultimately result in a new |
| ---Load and decode 'config.toml' | ||
| ---@param cwd? string Notebook root directory (optional) | ||
| ---@return table? config Decoded TOML config if successful | ||
| function M.get_config_toml(cwd) | ||
| local ltoml = require("toml") | ||
| cwd = cwd or require("zk.util").notebook_root(vim.fn.getcwd()) | ||
| if not cwd then | ||
| return | ||
| end | ||
| toml_path = vim.fs.joinpath(cwd, ".zk/config.toml") | ||
| local result, config = pcall(ltoml.decodeFromFile, toml_path) | ||
| if not result then |
There was a problem hiding this comment.
Also, just as a general comment for future work. Rembmer that a zk config can either be global (in $XDG_CONFIG_HOME/zk/config.toml), local (in the notebook) or a combination of both.
This implementation only considers local configs.
This (and many other reasons) are why it's best to develop the zk-nvim plugin, to use as much as possible, the functionality built into zk already.
There was a problem hiding this comment.
Thank you for your review.
That's right, I completely forgot about $XDG_CONFIG_HOME/zk/config.toml.
I understand that we should use zk as much as possible before implementing in zk-nvim.
|
Temporarily I've migrated this functionality to a new repository: I needed this functionality immediately, so I decided to create a separate plugin. If the repository name is confusing, it can be changed anytime. Though the issue with retrieving Once zk-org/zk#484 is merged, Thanks @tjex ! |
I'm not sure whether this feature is important for other users.
But this is essential for my daily use.
It’s convenient for users who include a
groupsection inconfig.tomlor include several templates or directories, but less so for those who don’t.Purpose
Add prompt for choosing group, path and template interactively for creating new note based on
config.tomlScreenshots
1. Group selection:
2. Path or directory selection:
3. Template selection:
Summary
:ZkNewcan create a new note in a directory using a template.But normally it consumes some keybinds.
(e.g.)
<leader>znn-> ZkNew note<leader>znd-> ZkNew dialy<leader>zni-> ZkNew inbox { template = 'inbox.md' }zk.new_prompt()function enables to select interactively from:based on
config.tomlor filesystem, withvim.ui.select()at once.This fills the gap between
config.toml, templates, directories,zkandzk-nvimefficiently.And it's highly customizable with callback.
Details
When groups are defined, the user selects a group, then a path if available (or chooses a directory from all directories list).
The group’s single
note.templateis applied automatically; if it’s missing, an error is shown.If no groups are defined, templates are collected from
.zk/templates, and user selects one. Then chooses a directory from all directories list.The callback function receives
optionstable contains group, dir, template, and also fetchedconfigtable.Dependencies
ltoml (Should we avoid adding new dependencies?)
Usage
or just simply create new:
Test
One-liner for easy test:
Example code
Example code for
zk.new:Example code for
zk.newwith title input:Example code for
zk.newwith title select from existing notes and modify it:(NOT WORKS: because
vim.ui.selectaccepts onlyexistingitem. But telescope can, I guess.)Show code
Keymaps
I think it can replace
:ZkNewkeymap, if user wishs.lazy.nvim:
Additional functions
These functions are added in this PR.
zk.util.get_config_toml(cwd)zk.util.get_templates(cwd)zk.util.get_dirs(cwd)Enabled to chose also
pathsThe
zk.newcommand automatically selects the group whosepathsinclude the specified directory (e.g.,zk.new notes→ group containingnotes), and determines the template from that group’snote.template = ....However, if multiple groups include the same path in
paths, the one defined first is always chosen, making the others ineffective.Therefore, although this behavior differs slightly from the original
zkcommand logic, selection frompathsis also supported.Should ignore the weird behavior of
zk new?I guess that
zk newuses first found template in another group if the specified group does not includenote.template = "...". Currently that behavior is ignored.Sample config
Since the
groupsections may not be familiar for many users, see the following example.group example in
config.toml:When it's converted into a lua table:
To add the root dir (= notebook_path) in paths selection, use an empty string:
Or, just removing
paths = []line will work fine too.