From 7a6e89131e06c124cdf1d51d7169a19bd507e858 Mon Sep 17 00:00:00 2001 From: skovati Date: Sat, 7 Jan 2023 21:05:14 +0000 Subject: [PATCH] Add `filename_space_subst` config option (#198) * add filename_space_subst configuration option * add docs for new filename_space_subst * fix template refactor bug --- README.md | 3 +++ doc/telekasten.txt | 13 +++++++++++++ lua/telekasten.lua | 13 ++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4320f3e..bc722f5 100644 --- a/README.md +++ b/README.md @@ -312,6 +312,9 @@ require('telekasten').setup({ -- UUID separator uuid_sep = "-", + -- if not nil, this string replaces spaces in the title when generating filenames + filename_space_subst = nil, + -- following a link to a non-existing note will create it follow_creates_nonexisting = true, dailies_create_nonexisting = true, diff --git a/doc/telekasten.txt b/doc/telekasten.txt index 5bb1993..8b487bd 100644 --- a/doc/telekasten.txt +++ b/doc/telekasten.txt @@ -255,6 +255,19 @@ telekasten.setup({opts}) Default: '-' + *telekasten.settings.filename_space_subst* + filename_space_subst: ~ + When the note title is used within the filename, i.e. + |new_note_filename| contains 'title', spaces in the title will be + substituted for |filename_space_subst|. + + e.g. if set to '_', '20230103-my new note title.md' would instead + become '20230103-my_new_note_title.md' + + If set to `nil`, no substitution will occur. + + Default: `nil` + *telekasten.settings.image_subdir* image_subdir: ~ Path to the directory where pasted images should go to. Accepts diff --git a/lua/telekasten.lua b/lua/telekasten.lua index 18aa08c..37d2708 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -74,6 +74,9 @@ local function defaultConfig(home) -- UUID separator uuid_sep = "-", + -- if not nil, replaces any spaces in the title when it is used in filename generation + filename_space_subst = nil, + -- following a link to a non-existing note will create it follow_creates_nonexisting = true, dailies_create_nonexisting = true, @@ -224,6 +227,10 @@ local function get_uuid(opts) end local function generate_note_filename(uuid, title) + if M.Cfg.filename_space_subst ~= nil then + title = escape(title):gsub(" ", M.Cfg.filename_space_subst) + end + local pp = Path:new(title) local p_splits = pp:_split() local filename = p_splits[#p_splits] @@ -649,9 +656,9 @@ local function linesubst(line, title, dates, uuid) end local substs = vim.tbl_extend("error", dates, { - shorttitle, - uuid, - title, + shorttitle = shorttitle, + uuid = uuid, + title = title, }) for k, v in pairs(substs) do