mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
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:
@@ -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.
|
||||
|
||||
|
||||
@@ -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*
|
||||
|
||||
|
||||
@@ -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,125 +27,136 @@ 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 = {
|
||||
home = home,
|
||||
local cfg = {
|
||||
home = home,
|
||||
|
||||
-- if true, telekasten will be enabled when opening a note within the configured home
|
||||
take_over_my_home = true,
|
||||
-- if true, telekasten will be enabled when opening a note within the configured home
|
||||
take_over_my_home = true,
|
||||
|
||||
-- auto-set telekasten filetype: if false, the telekasten filetype will not be used
|
||||
-- and thus the telekasten syntax will not be loaded either
|
||||
auto_set_filetype = true,
|
||||
-- auto-set telekasten filetype: if false, the telekasten filetype will not be used
|
||||
-- and thus the telekasten syntax will not be loaded either
|
||||
auto_set_filetype = true,
|
||||
|
||||
-- dir names for special notes (absolute path or subdir name)
|
||||
dailies = home .. "/" .. "daily",
|
||||
weeklies = home .. "/" .. "weekly",
|
||||
templates = home .. "/" .. "templates",
|
||||
-- dir names for special notes (absolute path or subdir name)
|
||||
dailies = home .. "/" .. "daily",
|
||||
weeklies = home .. "/" .. "weekly",
|
||||
templates = home .. "/" .. "templates",
|
||||
|
||||
-- image (sub)dir for pasting
|
||||
-- dir name (absolute path or subdir name)
|
||||
-- or nil if pasted images shouldn't go into a special subdir
|
||||
image_subdir = nil,
|
||||
-- image (sub)dir for pasting
|
||||
-- dir name (absolute path or subdir name)
|
||||
-- or nil if pasted images shouldn't go into a special subdir
|
||||
image_subdir = nil,
|
||||
|
||||
-- markdown file extension
|
||||
extension = ".md",
|
||||
-- markdown file extension
|
||||
extension = ".md",
|
||||
|
||||
-- Generate note filenames. One of:
|
||||
-- "title" (default) - Use title if supplied, uuid otherwise
|
||||
-- "uuid" - Use uuid
|
||||
-- "uuid-title" - Prefix title by uuid
|
||||
-- "title-uuid" - Suffix title with uuid
|
||||
new_note_filename = "title",
|
||||
-- file uuid type ("rand" or input for os.date()")
|
||||
uuid_type = "%Y%m%d%H%M",
|
||||
-- UUID separator
|
||||
uuid_sep = "-",
|
||||
-- Generate note filenames. One of:
|
||||
-- "title" (default) - Use title if supplied, uuid otherwise
|
||||
-- "uuid" - Use uuid
|
||||
-- "uuid-title" - Prefix title by uuid
|
||||
-- "title-uuid" - Suffix title with uuid
|
||||
new_note_filename = "title",
|
||||
-- file uuid type ("rand" or input for os.date()")
|
||||
uuid_type = "%Y%m%d%H%M",
|
||||
-- UUID separator
|
||||
uuid_sep = "-",
|
||||
|
||||
-- following a link to a non-existing note will create it
|
||||
follow_creates_nonexisting = true,
|
||||
dailies_create_nonexisting = true,
|
||||
weeklies_create_nonexisting = true,
|
||||
-- following a link to a non-existing note will create it
|
||||
follow_creates_nonexisting = true,
|
||||
dailies_create_nonexisting = true,
|
||||
weeklies_create_nonexisting = true,
|
||||
|
||||
-- skip telescope prompt for goto_today and goto_thisweek
|
||||
journal_auto_open = false,
|
||||
-- skip telescope prompt for goto_today and goto_thisweek
|
||||
journal_auto_open = false,
|
||||
|
||||
-- templates for new notes
|
||||
-- template_new_note = home .. "/" .. "templates/new_note.md",
|
||||
-- template_new_daily = home .. "/" .. "templates/daily_tk.md",
|
||||
-- template_new_weekly = home .. "/" .. "templates/weekly_tk.md",
|
||||
-- templates for new notes
|
||||
-- template_new_note = home .. "/" .. "templates/new_note.md",
|
||||
-- template_new_daily = home .. "/" .. "templates/daily_tk.md",
|
||||
-- template_new_weekly = home .. "/" .. "templates/weekly_tk.md",
|
||||
|
||||
-- image link style
|
||||
-- wiki: ![[image name]]
|
||||
-- markdown: 
|
||||
image_link_style = "markdown",
|
||||
-- image link style
|
||||
-- wiki: ![[image name]]
|
||||
-- markdown: 
|
||||
image_link_style = "markdown",
|
||||
|
||||
-- default sort option: 'filename', 'modified'
|
||||
sort = "filename",
|
||||
-- default sort option: 'filename', 'modified'
|
||||
sort = "filename",
|
||||
|
||||
-- when linking to a note in subdir/, create a [[subdir/title]] link
|
||||
-- instead of a [[title only]] link
|
||||
subdirs_in_links = true,
|
||||
-- when linking to a note in subdir/, create a [[subdir/title]] link
|
||||
-- instead of a [[title only]] link
|
||||
subdirs_in_links = true,
|
||||
|
||||
-- integrate with calendar-vim
|
||||
plug_into_calendar = true,
|
||||
calendar_opts = {
|
||||
-- calendar week display mode: 1 .. 'WK01', 2 .. 'WK 1', 3 .. 'KW01', 4 .. 'KW 1', 5 .. '1'
|
||||
weeknm = 4,
|
||||
-- use monday as first day of week: 1 .. true, 0 .. false
|
||||
calendar_monday = 1,
|
||||
-- calendar mark: where to put mark for marked days: 'left', 'right', 'left-fit'
|
||||
calendar_mark = "left-fit",
|
||||
},
|
||||
close_after_yanking = false,
|
||||
insert_after_inserting = true,
|
||||
-- integrate with calendar-vim
|
||||
plug_into_calendar = true,
|
||||
calendar_opts = {
|
||||
-- calendar week display mode: 1 .. 'WK01', 2 .. 'WK 1', 3 .. 'KW01', 4 .. 'KW 1', 5 .. '1'
|
||||
weeknm = 4,
|
||||
-- use monday as first day of week: 1 .. true, 0 .. false
|
||||
calendar_monday = 1,
|
||||
-- calendar mark: where to put mark for marked days: 'left', 'right', 'left-fit'
|
||||
calendar_mark = "left-fit",
|
||||
},
|
||||
close_after_yanking = false,
|
||||
insert_after_inserting = true,
|
||||
|
||||
-- tag notation: '#tag', ':tag:', 'yaml-bare'
|
||||
tag_notation = "#tag",
|
||||
-- tag notation: '#tag', ':tag:', 'yaml-bare'
|
||||
tag_notation = "#tag",
|
||||
|
||||
-- command palette theme: dropdown (window) or ivy (bottom panel)
|
||||
command_palette_theme = "ivy",
|
||||
-- command palette theme: dropdown (window) or ivy (bottom panel)
|
||||
command_palette_theme = "ivy",
|
||||
|
||||
-- tag list theme:
|
||||
-- get_cursor: small tag list at cursor; ivy and dropdown like above
|
||||
show_tags_theme = "ivy",
|
||||
-- tag list theme:
|
||||
-- get_cursor: small tag list at cursor; ivy and dropdown like above
|
||||
show_tags_theme = "ivy",
|
||||
|
||||
-- template_handling
|
||||
-- What to do when creating a new note via `new_note()` or `follow_link()`
|
||||
-- to a non-existing note
|
||||
-- - prefer_new_note: use `new_note` template
|
||||
-- - smart: if day or week is detected in title, use daily / weekly templates (default)
|
||||
-- - always_ask: always ask before creating a note
|
||||
template_handling = "smart",
|
||||
-- template_handling
|
||||
-- What to do when creating a new note via `new_note()` or `follow_link()`
|
||||
-- to a non-existing note
|
||||
-- - prefer_new_note: use `new_note` template
|
||||
-- - smart: if day or week is detected in title, use daily / weekly templates (default)
|
||||
-- - always_ask: always ask before creating a note
|
||||
template_handling = "smart",
|
||||
|
||||
-- path handling:
|
||||
-- this applies to:
|
||||
-- - new_note()
|
||||
-- - new_templated_note()
|
||||
-- - follow_link() to non-existing note
|
||||
--
|
||||
-- it does NOT apply to:
|
||||
-- - goto_today()
|
||||
-- - goto_thisweek()
|
||||
--
|
||||
-- Valid options:
|
||||
-- - smart: put daily-looking notes in daily, weekly-looking ones in weekly,
|
||||
-- all other ones in home, except for notes/with/subdirs/in/title.
|
||||
-- (default)
|
||||
--
|
||||
-- - prefer_home: put all notes in home except for goto_today(), goto_thisweek()
|
||||
-- except for notes/with/subdirs/in/title.
|
||||
--
|
||||
-- - same_as_current: put all new notes in the dir of the current note if
|
||||
-- present or else in home
|
||||
-- except for notes/with/subdirs/in/title.
|
||||
new_note_location = "smart",
|
||||
-- path handling:
|
||||
-- this applies to:
|
||||
-- - new_note()
|
||||
-- - new_templated_note()
|
||||
-- - follow_link() to non-existing note
|
||||
--
|
||||
-- it does NOT apply to:
|
||||
-- - goto_today()
|
||||
-- - goto_thisweek()
|
||||
--
|
||||
-- Valid options:
|
||||
-- - smart: put daily-looking notes in daily, weekly-looking ones in weekly,
|
||||
-- all other ones in home, except for notes/with/subdirs/in/title.
|
||||
-- (default)
|
||||
--
|
||||
-- - prefer_home: put all notes in home except for goto_today(), goto_thisweek()
|
||||
-- except for notes/with/subdirs/in/title.
|
||||
--
|
||||
-- - same_as_current: put all new notes in the dir of the current note if
|
||||
-- present or else in home
|
||||
-- except for notes/with/subdirs/in/title.
|
||||
new_note_location = "smart",
|
||||
|
||||
-- should all links be updated when a file is renamed
|
||||
rename_update_links = true,
|
||||
}
|
||||
-- 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)
|
||||
@@ -927,7 +934,7 @@ function Pinfo:resolve_link(title, opts)
|
||||
end
|
||||
|
||||
-- local function endswith(s, ending)
|
||||
-- return ending == "" or s:sub(-#ending) == ending
|
||||
-- return ending == "" or s:sub(-#ending) == ending
|
||||
-- end
|
||||
|
||||
local function file_extension(fname)
|
||||
@@ -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
42
lua/vaultpicker.lua
Normal 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
|
||||
Reference in New Issue
Block a user