Be less pedantic about note filenames to support subdirectories
This commit is contained in:
parent
8f1f3cda87
commit
86856bf960
4 changed files with 11 additions and 14 deletions
|
@ -45,7 +45,7 @@ endsnippet
|
|||
|
||||
# Code
|
||||
|
||||
snippet `r "R Code Block" b
|
||||
snippet rcode "R Code Block" b
|
||||
\`\`\`{r}
|
||||
${1:#| output: ${2:false}}
|
||||
${3:#| echo: ${4:false}}
|
||||
|
@ -53,7 +53,7 @@ ${0:${VISUAL:# code...}}
|
|||
\`\`\`
|
||||
endsnippet
|
||||
|
||||
snippet `py "Python Code Block" b
|
||||
snippet pycode "Python Code Block" b
|
||||
\`\`\`{python}
|
||||
${1:#| output: ${2:false}}
|
||||
${3:#| echo: ${4:false}}
|
||||
|
|
|
@ -68,10 +68,11 @@ enddef
|
|||
|
||||
export def BeforeNoteSave()
|
||||
var full_path = expand('%:p')
|
||||
var directory = expand('%:p:h')
|
||||
var daily_path = g:mbnotes_dir .. "/daily"
|
||||
|
||||
# Don't touch daily notes
|
||||
if g:mbnotes_rename_on_save && daily_path != full_path[0 : len(daily_path) - 1]
|
||||
# Only rename bona fide notes
|
||||
if directory != expand(g:mbnotes_dir)
|
||||
var base = expand('%:t')
|
||||
var date = base[0 : 9]
|
||||
|
||||
|
@ -83,7 +84,7 @@ export def BeforeNoteSave()
|
|||
var title_line = search('^#\s\+')
|
||||
|
||||
if title_line == 0
|
||||
throw "Unable to save note: No title found."
|
||||
return
|
||||
endif
|
||||
|
||||
var title = substitute(getline(title_line), '^#\s\+', '', '')
|
||||
|
@ -97,13 +98,14 @@ export def BeforeNoteSave()
|
|||
normal! `s
|
||||
setpos("'s", original_mark)
|
||||
|
||||
b:new_name = date .. "_" .. sanitised .. ".qmd"
|
||||
b:new_name = fnameescape(expand('%:p:h')) .. "/" .. date .. "_" .. sanitised .. ".qmd"
|
||||
endif
|
||||
enddef
|
||||
|
||||
export def AfterNoteSave()
|
||||
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
|
||||
enddef
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ if !exists("g:mbnotes_dir")
|
|||
echoerr "MBNotes: Error: g:mbnotes_dir not set."
|
||||
finish
|
||||
else
|
||||
silent mkdir(fnameescape(g:mbnotes_dir .. "/daily"), "p")
|
||||
silent mkdir(g:mbnotes_dir .. "/daily", "p")
|
||||
endif
|
||||
|
||||
if !exists("g:mbnotes_out_dir")
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
import vim
|
||||
from string import Template
|
||||
from datetime import datetime, timedelta
|
||||
daily_template = Template("""---
|
||||
title: "Daily Note"
|
||||
date: "$date"
|
||||
---
|
||||
|
||||
# $date
|
||||
daily_template = Template("""# $date
|
||||
|
||||
## Daily Note
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue