From 0563d59eddc80faccb032fe58331184247ef938e Mon Sep 17 00:00:00 2001 From: Max Bucknell Date: Tue, 31 Dec 2024 11:52:08 +0000 Subject: [PATCH] Daily note support --- vim/vim.xdg.symlink/Ultisnips/quarto.snippets | 4 ++ vim/vim.xdg.symlink/vimrc | 49 ++++++++++++++----- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/vim/vim.xdg.symlink/Ultisnips/quarto.snippets b/vim/vim.xdg.symlink/Ultisnips/quarto.snippets index 1f46c1e..ad20feb 100644 --- a/vim/vim.xdg.symlink/Ultisnips/quarto.snippets +++ b/vim/vim.xdg.symlink/Ultisnips/quarto.snippets @@ -28,3 +28,7 @@ ${1:#| output: ${2:false}} ${0:${VISUAL:# code...}} \`\`\` endsnippet + +snippet todo "Make a To-Do List!" b +- [ ] ${0:What would you like to do..?} +endsnippet diff --git a/vim/vim.xdg.symlink/vimrc b/vim/vim.xdg.symlink/vimrc index 2f8d55d..55e58b5 100644 --- a/vim/vim.xdg.symlink/vimrc +++ b/vim/vim.xdg.symlink/vimrc @@ -227,14 +227,14 @@ enddef augroup AutoMkdir autocmd! - autocmd BufNewFile * EnsureDirExists() + autocmd BufNewFile * EnsureDirExists() augroup END # Use tab for UltiSnips expansion, navigation, and g:ulti_expand_or_jump_res = 0 g:UltiSnipsExpandOrJumpTrigger = '' -export def Ulti_ExpandOrJump_and_getRes(default: string): string +def g:Ultisnips_expand(default: string): string UltiSnips#ExpandSnippetOrJump() if g:ulti_expand_or_jump_res == 0 @@ -244,7 +244,7 @@ export def Ulti_ExpandOrJump_and_getRes(default: string): string endif enddef -inoremap =Ulti_ExpandOrJump_and_getRes("\") +# inoremap Ulti_ExpandOrJump_and_getRes("\") # Notes config @@ -346,7 +346,7 @@ augroup CodeBlocks augroup END augroup Notes - autocmd Filetype quarto setl tw=80 fo+=croqt ts=4 sts=4 sw=4 comments=n:> + # autocmd Filetype quarto setl tw=80 fo+=croqt ts=4 sts=4 sw=4 comments=n:> # Surround mappings for Quarto callouts autocmd FileType quarto b:surround_110 = "::: {.callout-note}\n\r\n:::" @@ -354,24 +354,47 @@ augroup Notes autocmd FileType quarto b:surround_119 = "::: {.callout-warning}\n\r\n:::" autocmd FileType quarto b:surround_105 = "::: {.callout-important}\n\r\n:::" - # autocmd FileType quarto imap =Ulti_ExpandOrJump_and_getRes("\") - autocmd FileType quarto imap Ulti_ExpandOrJump_and_getRes("\") - autocmd FileType quarto imap + autocmd FileType quarto imap =g:Ultisnips_expand("\") + autocmd FileType quarto imap - autocmd FileType quarto onoremap cb :execute "normal! /^```\rk$ms?^```\rj:noh\rv`s" - autocmd FileType quarto nnoremap ec EditCodeBlock() - autocmd FileType quarto inoremap EditCodeBlock() + autocmd FileType quarto onoremap cb :execute "normal! /^```\rk$ms?^```\rj:noh\rv`s" + autocmd FileType quarto nnoremap ec EditCodeBlock() + autocmd FileType quarto inoremap EditCodeBlock() augroup END -# Daily notes -def OpenDailyNote(offset: number) +nnoremap x :silent keepp s/^- \[ \]/- [o]/e:silent keepp s/^- \[x\]/- [ ]/e:silent keepp s/^- \[o\]/- [x]/e +# Daily notes +def FormatOffset(offset: number): string + if offset == 0 + return "" + elseif offset > 0 + return "-v+" .. offset .. "d " + else + return "-v" .. offset .. "d " + endif +enddef + +def OpenDailyNote(offset = 0) + var command = "date -v-4H " .. FormatOffset(offset) .. "\"+%Y-%m-%d\"" + var date = trim(system(command)) + var filename = $DAILY_NOTES_PATH .. "/" .. date .. "-daily.qmd" + + if !filereadable(filename) + var template = $DAILY_NOTES_PATH .. "/template.py" + + system(shellescape(template) .. " " .. shellescape(date) .. " > " .. shellescape(filename)) + endif + + execute "edit " .. filename enddef +command -nargs=? Daily OpenDailyNote() + def StartUp() if @% == "" - edit ~/tmp/testing.qmd + OpenDailyNote() endif enddef