rename notes/and files
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
" Functions to create the front matter
|
||||
" Functions to manipulate and query the front matter
|
||||
|
||||
" Helper function to put string in double quotes, and remove inside double
|
||||
" quotes.
|
||||
function s:escapeDQ(s)
|
||||
@@ -57,3 +58,21 @@ function denote#frontmatter#new(ft, id, title, tags=[])
|
||||
\ : g:denote_fm_md_type == 'toml' ? s:md_new_toml(a:id, a:title, a:tags)
|
||||
\ : s:md_new_yaml(a:id, a:title, a:tags)
|
||||
endfunction
|
||||
|
||||
" Return the frontmatter of the specified file (as a list)
|
||||
function s:getFrontmatter(filename)
|
||||
let l:ft = fnamemodify(a:filename, ':e')
|
||||
let l:cnt = l:ft == 'org' ? 4
|
||||
\ : l:ft == 'txt' ? 5
|
||||
\ : 6
|
||||
call bufload(a:filename)
|
||||
return getbufline(a:filename, 1, 1 + l:cnt)
|
||||
endfunction
|
||||
|
||||
" Get title from front matter
|
||||
function denote#frontmatter#setTitle(filename, title)
|
||||
" Retrieve front matter (number of lines depends on ft), and replace title
|
||||
let l:frontmatter = s:getFrontmatter(a:filename)
|
||||
call map(l:frontmatter, { _, v -> substitute(v, '^#\?+\?title:\?\s*"\?\zs.\{-\}\ze\"\?$', a:title, '')})
|
||||
call setbufline(a:filename, 1, l:frontmatter)
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user