Be less pedantic about note filenames to support subdirectories

This commit is contained in:
Max Bucknell 2025-01-19 11:13:24 +00:00
parent 8f1f3cda87
commit 86856bf960
No known key found for this signature in database
4 changed files with 11 additions and 14 deletions

View file

@ -45,7 +45,7 @@ endsnippet
# Code # Code
snippet `r "R Code Block" b snippet rcode "R Code Block" b
\`\`\`{r} \`\`\`{r}
${1:#| output: ${2:false}} ${1:#| output: ${2:false}}
${3:#| echo: ${4:false}} ${3:#| echo: ${4:false}}
@ -53,7 +53,7 @@ ${0:${VISUAL:# code...}}
\`\`\` \`\`\`
endsnippet endsnippet
snippet `py "Python Code Block" b snippet pycode "Python Code Block" b
\`\`\`{python} \`\`\`{python}
${1:#| output: ${2:false}} ${1:#| output: ${2:false}}
${3:#| echo: ${4:false}} ${3:#| echo: ${4:false}}

View file

@ -68,10 +68,11 @@ enddef
export def BeforeNoteSave() export def BeforeNoteSave()
var full_path = expand('%:p') var full_path = expand('%:p')
var directory = expand('%:p:h')
var daily_path = g:mbnotes_dir .. "/daily" var daily_path = g:mbnotes_dir .. "/daily"
# Don't touch daily notes # Only rename bona fide notes
if g:mbnotes_rename_on_save && daily_path != full_path[0 : len(daily_path) - 1] if directory != expand(g:mbnotes_dir)
var base = expand('%:t') var base = expand('%:t')
var date = base[0 : 9] var date = base[0 : 9]
@ -83,7 +84,7 @@ export def BeforeNoteSave()
var title_line = search('^#\s\+') var title_line = search('^#\s\+')
if title_line == 0 if title_line == 0
throw "Unable to save note: No title found." return
endif endif
var title = substitute(getline(title_line), '^#\s\+', '', '') var title = substitute(getline(title_line), '^#\s\+', '', '')
@ -97,13 +98,14 @@ export def BeforeNoteSave()
normal! `s normal! `s
setpos("'s", original_mark) setpos("'s", original_mark)
b:new_name = date .. "_" .. sanitised .. ".qmd" b:new_name = fnameescape(expand('%:p:h')) .. "/" .. date .. "_" .. sanitised .. ".qmd"
endif endif
enddef enddef
export def AfterNoteSave() export def AfterNoteSave()
if exists("b:new_name") if exists("b:new_name")
execute "silent Move " .. fnameescape(g:mbnotes_dir) .. "/" .. b:new_name execute "silent Move " .. b:new_name
unlet b:new_name
endif endif
enddef enddef

View file

@ -16,7 +16,7 @@ if !exists("g:mbnotes_dir")
echoerr "MBNotes: Error: g:mbnotes_dir not set." echoerr "MBNotes: Error: g:mbnotes_dir not set."
finish finish
else else
silent mkdir(fnameescape(g:mbnotes_dir .. "/daily"), "p") silent mkdir(g:mbnotes_dir .. "/daily", "p")
endif endif
if !exists("g:mbnotes_out_dir") if !exists("g:mbnotes_out_dir")

View file

@ -1,12 +1,7 @@
import vim import vim
from string import Template from string import Template
from datetime import datetime, timedelta from datetime import datetime, timedelta
daily_template = Template("""--- daily_template = Template("""# $date
title: "Daily Note"
date: "$date"
---
# $date
## Daily Note ## Daily Note