mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
added new_templated_note()
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
# Backlog
|
# Backlog
|
||||||
|
|
||||||
- maybe choose template in create note
|
|
||||||
|
|
||||||
## Dones
|
## 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] highlights oneline
|
||||||
- [x] highlight for highlighted text : ==asdfasdfasasdf==
|
- [x] highlight for highlighted text : ==asdfasdfasasdf==
|
||||||
- [x] yank notelink
|
- [x] yank notelink
|
||||||
|
|||||||
17
README.md
17
README.md
@@ -50,6 +50,7 @@ require('telekasten').setup({
|
|||||||
home = home
|
home = home
|
||||||
dailies = home .. '/' .. 'daily',
|
dailies = home .. '/' .. 'daily',
|
||||||
weeklies = home .. '/' .. 'weekly',
|
weeklies = home .. '/' .. 'weekly',
|
||||||
|
templates = home .. '/' .. 'templates',
|
||||||
extension = ".md",
|
extension = ".md",
|
||||||
|
|
||||||
-- following a link to a non-existing note will create it
|
-- following a link to a non-existing note will create it
|
||||||
@@ -68,6 +69,20 @@ require('telekasten').setup({
|
|||||||
})
|
})
|
||||||
END
|
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
|
### 3. Configure your own colors
|
||||||
Telekasten.nvim allows you to color your `[[links]]` by providing two syntax groups:
|
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.
|
The plugin defines the following functions.
|
||||||
|
|
||||||
- `new_note()` : prompts for title and creates new note by template, then shows it in Telescope
|
- `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_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
|
- `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
|
- `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>zt :lua require('telekasten').goto_today()<CR>
|
||||||
nnoremap <leader>zw :lua require('telekasten').find_weekly_notes()<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_note()<CR>
|
||||||
|
nnoremap <leader>zN :lua require('telekasten').new_templated_note()<CR>
|
||||||
nnoremap <leader>zy :lua require('telekasten').yank_notelink()<CR>
|
nnoremap <leader>zy :lua require('telekasten').yank_notelink()<CR>
|
||||||
|
|
||||||
" we could define [[ in **insert mode** to call insert link
|
" we could define [[ in **insert mode** to call insert link
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ ZkCfg = {
|
|||||||
home = home,
|
home = home,
|
||||||
dailies = home .. '/' .. 'daily',
|
dailies = home .. '/' .. 'daily',
|
||||||
weeklies = home .. '/' .. 'weekly',
|
weeklies = home .. '/' .. 'weekly',
|
||||||
|
templates = home .. '/' .. 'templates',
|
||||||
extension = ".md",
|
extension = ".md",
|
||||||
|
|
||||||
|
|
||||||
@@ -270,7 +271,7 @@ end
|
|||||||
-- CreateNote:
|
-- 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)
|
local function on_create(title)
|
||||||
if (title == nil) then return end
|
if (title == nil) then return end
|
||||||
@@ -295,6 +296,48 @@ CreateNote = function(opts)
|
|||||||
end
|
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:
|
-- GotoThisWeek:
|
||||||
-- ----------
|
-- ----------
|
||||||
@@ -349,6 +392,7 @@ local M = {
|
|||||||
goto_thisweek = GotoThisWeek,
|
goto_thisweek = GotoThisWeek,
|
||||||
find_weekly_notes = FindWeeklyNotes,
|
find_weekly_notes = FindWeeklyNotes,
|
||||||
yank_notelink = YankLink,
|
yank_notelink = YankLink,
|
||||||
|
create_note_sel_template = CreateNoteSelectTemplate,
|
||||||
}
|
}
|
||||||
return M
|
return M
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user