Squashed PR #158 and fixup into 1 commit

Squashed PR#158 into 1 single commit;

        Add vaults

        Add documentation:

        Make luachack happy.

        Address review comments

    fixed tabs and formatting of PR #158
This commit is contained in:
Shivanth
2022-08-07 23:54:19 +08:00
committed by Rene Schallner
parent 74ff3a9e64
commit fa66746981
4 changed files with 208 additions and 107 deletions

View File

@@ -368,6 +368,13 @@ require('telekasten').setup({
-- should all links be updated when a file is renamed
rename_update_links = true,
vaults = {
vault2 = {
-- alternate configuration for vault2 here. Missing values are defaulted to
-- default values from telekasten.
},
},
})
END
```
@@ -632,6 +639,7 @@ The plugin defines the following functions:
- `panel()` : brings up the command palette
- `show_tags()` : brings up the tag list. From there you can select a tag to search for tagged notes - or yank or insert the tag
- `rename_note()` : rename the current note and update the links pointing to it
- `switch_vault()` : switch the vault
To use one of the functions above, just run them with the `:lua ...` command.

View File

@@ -37,6 +37,7 @@ CONTENTS
3.3 Templates ................ |telekasten.templates|
3.4 Calendar ................. |telekasten.calendar|
3.5 Picker mappings .......... |telekasten.picker_mappings|
3.6 Mutliple home directories. |telekasten.switch_vaults|
4. Suggested mappings ............ |telekasten.mappings|
5. Credits ....................... |telekasten.credits|
@@ -125,6 +126,7 @@ telekasten.setup({opts})
-- 'left'
-- 'right'
-- 'left-fit'
},
-- make syntax available to markdown buffers and telescope previewers
install_syntax = true,
@@ -142,6 +144,12 @@ telekasten.setup({opts})
-- when linking to a note in subdir/, create a [[subdir/title]] link
-- instead of a [[title only]] link
subdirs_in_links = true,
vaults = {
personal = {
--configuration for personal vault
}
},
}
<
@@ -911,6 +919,14 @@ the following mappings apply:
function. E.g. `insert_img_link()`'s action is to insert a link to the
selected image.
--------------------------------------------------------------------------------
Section 3.6 Mutliple home directories *telekasten.switch_vaults*
You can have multiple home directories setup in telekasten. The configuration
for each vault is stored as a map in telekasten. You can use `switch_vaults
to launch a picker to choose the vaults.
================================================================================
Section 4: Suggested Mappings *telekasten.mappings*

View File

@@ -19,6 +19,7 @@ local tagutils = require("taglinks.tagutils")
local linkutils = require("taglinks.linkutils")
local dateutils = require("taglinks.dateutils")
local Path = require("plenary.path")
local vaultPicker = require("vaultpicker")
-- declare locals for the nvim api stuff to avoid more lsp warnings
local vim = vim
@@ -26,10 +27,14 @@ local vim = vim
-- ----------------------------------------------------------------------------
-- DEFAULT CONFIG
-- ----------------------------------------------------------------------------
local home = vim.fn.expand("~/zettelkasten")
local _home = vim.fn.expand("~/zettelkasten")
local M = {}
local function defaultConfig(home)
if home == nil then
home = _home
end
M.Cfg = {
local cfg = {
home = home,
-- if true, telekasten will be enabled when opening a note within the configured home
@@ -144,7 +149,14 @@ M.Cfg = {
-- should all links be updated when a file is renamed
rename_update_links = true,
}
}
M.Cfg = cfg
M.note_type_templates = {
normal = M.Cfg.template_new_note,
daily = M.Cfg.template_new_daily,
weekly = M.Cfg.template_new_weekly,
}
end
local function file_exists(fname)
if fname == nil then
@@ -463,13 +475,8 @@ local function imgFromClipboard()
vim.api.nvim_err_writeln("Unable to write image " .. png)
end
end
-- end of image stuff
M.note_type_templates = {
normal = M.Cfg.template_new_note,
daily = M.Cfg.template_new_daily,
weekly = M.Cfg.template_new_weekly,
}
-- end of image stuff
local function daysuffix(day)
day = tostring(day)
@@ -2806,6 +2813,7 @@ end
--
local function Setup(cfg)
cfg = cfg or {}
defaultConfig(cfg.home)
local debug = cfg.debug
for k, v in pairs(cfg) do
-- merge everything but calendar opts
@@ -2826,7 +2834,6 @@ local function Setup(cfg)
end
end
end
-- TODO: this is obsolete:
if vim.fn.executable("rg") == 1 then
M.Cfg.find_command = { "rg", "--files", "--sortr", "created" }
@@ -2907,12 +2914,38 @@ local function Setup(cfg)
end
end
local function _setup(cfg)
if cfg.vaults ~= nil and cfg.default_vault ~= nil then
M.vaults = cfg.vaults
cfg.vaults = nil
Setup(cfg.vaults[cfg.default_vault])
elseif cfg.vaults ~= nil and cfg.vaults["default"] ~= nil then
M.vaults = cfg.vaults
cfg.vaults = nil
Setup(cfg.vaults["default"])
elseif cfg.home ~= nil then
M.vaults = cfg.vaults or {}
cfg.vaults = nil
M.vaults["default"] = cfg
Setup(cfg)
end
end
local function ChangeVault(opts)
vaultPicker.vaults(M, opts)
end
local function chdir(cfg)
Setup(cfg)
-- M.Cfg = vim.tbl_deep_extend("force", defaultConfig(new_home), cfg)
end
M.find_notes = FindNotes
M.find_daily_notes = FindDailyNotes
M.search_notes = SearchNotes
M.insert_link = InsertLink
M.follow_link = FollowLink
M.setup = Setup
M.setup = _setup
M.goto_today = GotoToday
M.new_note = CreateNote
M.goto_thisweek = GotoThisWeek
@@ -2932,6 +2965,8 @@ M.preview_img = PreviewImg
M.browse_media = BrowseImg
M.taglinks = taglinks
M.show_tags = FindAllTags
M.switch_vault = ChangeVault
M.chdir = chdir
-- Telekasten command, completion
local TelekastenCmd = {

42
lua/vaultpicker.lua Normal file
View File

@@ -0,0 +1,42 @@
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local conf = require("telescope.config").values
local M = {}
local vaults = function(telekasten, opts)
opts = opts or {}
local vaults = telekasten.vaults
local _vaults = {}
for k, v in pairs(vaults) do
table.insert(_vaults, { k, v })
end
pickers.new(opts, {
prompt_title = "Vaults",
finder = finders.new_table({
results = _vaults,
entry_maker = function(entry)
return {
value = entry,
display = entry[1],
ordinal = entry[1],
}
end,
}),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
-- print(vim.inspect(selection))
telekasten.chdir(selection.value[2])
end)
return true
end,
}):find()
end
M.vaults = vaults
return M