added new_templated_note()

This commit is contained in:
Rene Schallner
2021-11-22 23:54:09 +01:00
parent 4a34835818
commit cd040c165d
3 changed files with 64 additions and 2 deletions

View File

@@ -1,8 +1,9 @@
# Backlog
- maybe choose template in create note
## Dones
- [x] maybe choose template in create note:
- `new_templated_note()` first asks for title, then brings up a telescope picker of all template files in new `ZkCfg.template_dir`.
- [x] highlights oneline
- [x] highlight for highlighted text : ==asdfasdfasasdf==
- [x] yank notelink

View File

@@ -50,6 +50,7 @@ require('telekasten').setup({
home = home
dailies = home .. '/' .. 'daily',
weeklies = home .. '/' .. 'weekly',
templates = home .. '/' .. 'templates',
extension = ".md",
-- following a link to a non-existing note will create it
@@ -68,6 +69,20 @@ require('telekasten').setup({
})
END
```
| setting | description | example |
| --- | --- | --- |
| `home` | path to your zettelkasten folder (folder with markdown files) | ~/zettelkasten |
| `dailies` | path where your daily notes go | ~/zettelkasten/daily |
| `weeklies` | path where your weekly notes go | ~/zettelkasten/weekly |
| `templates` | path where your note templates go | ~/zettelkasten/templates |
| `extension` | filename extension of your note files | .md |
| `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 |
| `weekly_create_nonexisting` | following a link to a non-existing weekly note will create it | true |
| `template_new_note` | markdown template for new notes | `home .. '/' .. 'templates/new_note.md'` |
| `template_new_daily` | markdown template for new daily notes | `home .. '/' .. 'templates/daily.md'` |
| `template_new_weekly` | markdown template for new weekly notes | `home .. '/' .. 'templates/weekly.md'` |
### 3. Configure your own colors
Telekasten.nvim allows you to color your `[[links]]` by providing two syntax groups:
@@ -99,6 +114,7 @@ hi tkHighlight ctermbg=yellow ctermfg=darkred cterm=bold
The plugin defines the following functions.
- `new_note()` : prompts for title and creates new note by template, then shows it in Telescope
- `new_templated_note()` : prompts for title and then uses telescope for choosing a template. When a template is selected, a new note is created with it and opened. Should the note exist, it is opened immediately
- `find_notes()` : find notes by file name (title), via Telescope
- `find_daily_notes()` : find daily notes by date (file names, sorted, most recent first), via Telescope. If today's daily note is not present, it can be created optionally, honoring the configured template
- `goto_today()` : pops up a Telescope window with today's daily note pre-selected. Today's note can optionally be created if not present, using the configured template
@@ -200,6 +216,7 @@ nnoremap <leader>zz :lua require('telekasten').follow_link()<CR>
nnoremap <leader>zt :lua require('telekasten').goto_today()<CR>
nnoremap <leader>zw :lua require('telekasten').find_weekly_notes()<CR>
nnoremap <leader>zn :lua require('telekasten').new_note()<CR>
nnoremap <leader>zN :lua require('telekasten').new_templated_note()<CR>
nnoremap <leader>zy :lua require('telekasten').yank_notelink()<CR>
" we could define [[ in **insert mode** to call insert link

View File

@@ -14,6 +14,7 @@ ZkCfg = {
home = home,
dailies = home .. '/' .. 'daily',
weeklies = home .. '/' .. 'weekly',
templates = home .. '/' .. 'templates',
extension = ".md",
@@ -270,7 +271,7 @@ end
-- CreateNote:
-- ------------
--
-- find the file linked to by the word under the cursor
-- Prompts for title and creates note with default template
--
local function on_create(title)
if (title == nil) then return end
@@ -295,6 +296,48 @@ CreateNote = function(opts)
end
--
-- CreateNoteSelectTemplate()
-- --------------------------
--
-- Prompts for title, then pops up telescope for template selection,
-- creates the new note by template and opens it
local function on_create_with_template(title)
if (title == nil) then return end
local fname = ZkCfg.home .. '/' .. title .. ZkCfg.extension
local fexists = file_exists(fname)
if (fexists == true) then
-- open the new note
vim.cmd('e ' .. fname)
return
end
builtin.find_files({
prompt_title = "Select template...",
cwd = ZkCfg.templates,
find_command = ZkCfg.find_command,
attach_mappings = function(prompt_bufnr, map)
map = map -- get rid of lsp error
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local template = ZkCfg.templates .. '/' .. action_state.get_selected_entry().value
create_note_from_template(title, fname, template)
-- open the new note
vim.cmd('e ' .. fname)
end)
return true
end,
})
end
CreateNoteSelectTemplate = function(opts)
opts = {} or opts
vim.ui.input({prompt = 'Title: '}, on_create_with_template)
end
--
-- GotoThisWeek:
-- ----------
@@ -349,6 +392,7 @@ local M = {
goto_thisweek = GotoThisWeek,
find_weekly_notes = FindWeeklyNotes,
yank_notelink = YankLink,
create_note_sel_template = CreateNoteSelectTemplate,
}
return M