feat: allow auto-open of journal entries (#125)

This commit is contained in:
lambtho
2022-05-07 09:01:05 +00:00
committed by GitHub
parent c0925f0d30
commit c3da9a528a
2 changed files with 57 additions and 40 deletions

View File

@@ -254,6 +254,9 @@ require('telekasten').setup({
dailies_create_nonexisting = true, dailies_create_nonexisting = true,
weeklies_create_nonexisting = true, weeklies_create_nonexisting = true,
-- skip telescope prompt for goto_today and goto_thisweek
journal_auto_open = false,
-- template for new notes (new_note, follow_link) -- template for new notes (new_note, follow_link)
-- set to `nil` or do not specify if you do not want a template -- set to `nil` or do not specify if you do not want a template
template_new_note = home .. '/' .. 'templates/new_note.md', template_new_note = home .. '/' .. 'templates/new_note.md',
@@ -362,6 +365,7 @@ END
| `follow_creates_nonexisting` | following a link to a non-existing note will create it | true | | `follow_creates_nonexisting` | following a link to a non-existing note will create it | true |
| `dailies_create_nonexisting` | following a link to a non-existing daily note will create it | true | | `dailies_create_nonexisting` | following a link to a non-existing daily note will create it | true |
| `weekly_create_nonexisting` | following a link to a non-existing weekly note will create it | true | | `weekly_create_nonexisting` | following a link to a non-existing weekly note will create it | true |
| `journal_auto_open` | skip telekscope picker and automatically open the note with goto_today and goto_thisweek | false |
| `template_new_note` | markdown template for new notes | ~/zettelkasten/templates/new_note.md | | `template_new_note` | markdown template for new notes | ~/zettelkasten/templates/new_note.md |
| | set to `nil` if you want none | | | | set to `nil` if you want none | |
| `template_new_daily` | markdown template for new daily notes | ~/zettelkasten/templates/daily.md | | `template_new_daily` | markdown template for new daily notes | ~/zettelkasten/templates/daily.md |

View File

@@ -89,6 +89,9 @@ M.Cfg = {
dailies_create_nonexisting = true, dailies_create_nonexisting = true,
weeklies_create_nonexisting = true, weeklies_create_nonexisting = true,
-- skip telescope prompt for goto_today and goto_thisweek
journal_auto_open = false,
-- templates for new notes -- templates for new notes
-- template_new_note = home .. "/" .. "templates/new_note.md", -- template_new_note = home .. "/" .. "templates/new_note.md",
-- template_new_daily = home .. "/" .. "templates/daily_tk.md", -- template_new_daily = home .. "/" .. "templates/daily_tk.md",
@@ -1712,6 +1715,7 @@ local function GotoDate(opts)
or M.Cfg.insert_after_inserting or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking or M.Cfg.close_after_yanking
opts.journal_auto_open = opts.journal_auto_open or M.Cfg.journal_auto_open
local word = opts.date or os.date(dateformats.date) local word = opts.date or os.date(dateformats.date)
@@ -1735,31 +1739,35 @@ local function GotoDate(opts)
opts.erase_file = fname opts.erase_file = fname
end end
find_files_sorted({ if opts.journal_auto_open then
prompt_title = "Goto day", vim.cmd("e " .. fname)
cwd = M.Cfg.dailies, else
default_text = word, find_files_sorted({
find_command = M.Cfg.find_command, prompt_title = "Goto day",
attach_mappings = function(prompt_bufnr, map) cwd = M.Cfg.dailies,
actions.select_default:replace(function() default_text = word,
actions.close(prompt_bufnr) find_command = M.Cfg.find_command,
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
-- open the new note -- open the new note
if opts.calendar == true then if opts.calendar == true then
vim.cmd("wincmd w") vim.cmd("wincmd w")
end end
vim.cmd("e " .. fname) vim.cmd("e " .. fname)
picker_actions.post_open() picker_actions.post_open()
end) end)
map("i", "<c-y>", picker_actions.yank_link(opts)) map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts)) map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts)) map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts)) map("n", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-c>", picker_actions.close(opts)) map("n", "<c-c>", picker_actions.close(opts))
map("n", "<esc>", picker_actions.close(opts)) map("n", "<esc>", picker_actions.close(opts))
return true return true
end, end,
}) })
end
end end
-- --
@@ -2551,6 +2559,7 @@ local function GotoThisWeek(opts)
or M.Cfg.insert_after_inserting or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking or M.Cfg.close_after_yanking
opts.journal_auto_open = opts.journal_auto_open or M.Cfg.journal_auto_open
if not global_dir_check() then if not global_dir_check() then
return return
@@ -2572,22 +2581,26 @@ local function GotoThisWeek(opts)
opts.erase_file = fname opts.erase_file = fname
end end
find_files_sorted({ if opts.journal_auto_open then
prompt_title = "Goto this week:", vim.cmd("e " .. fname)
cwd = M.Cfg.weeklies, else
default_text = title, find_files_sorted({
find_command = M.Cfg.find_command, prompt_title = "Goto this week:",
attach_mappings = function(_, map) cwd = M.Cfg.weeklies,
actions.select_default:replace(picker_actions.select_default) default_text = title,
map("i", "<c-y>", picker_actions.yank_link(opts)) find_command = M.Cfg.find_command,
map("i", "<c-i>", picker_actions.paste_link(opts)) attach_mappings = function(_, map)
map("n", "<c-y>", picker_actions.yank_link(opts)) actions.select_default:replace(picker_actions.select_default)
map("n", "<c-i>", picker_actions.paste_link(opts)) map("i", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-c>", picker_actions.close(opts)) map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<esc>", picker_actions.close(opts)) map("n", "<c-y>", picker_actions.yank_link(opts))
return true map("n", "<c-i>", picker_actions.paste_link(opts))
end, map("n", "<c-c>", picker_actions.close(opts))
}) map("n", "<esc>", picker_actions.close(opts))
return true
end,
})
end
end end
-- --