copy files to denote directory

This commit is contained in:
2026-02-28 15:02:09 +01:00
parent 4fb6e977ff
commit dfc15def2b
3 changed files with 29 additions and 0 deletions

View File

@@ -122,3 +122,25 @@ function denote#notes#tagmod(line1, line2, tag, add)
endif
endfor
endfunction
" Add file to denote directory
function denote#notes#copy(origfile)
if !filereadable(a:origfile)
echohl WarningMsg
echom 'Cannot copy specified file to denote directory.'
return
endif
" Derive title from origfile
let l:title = fnamemodify(a:origfile, ':t:r')
let l:ext = fnamemodify(a:origfile, ':e')
let l:identifier = g:Denote_identifier_fun()
let l:filename = denote#meta#filename(l:ext, l:identifier, l:title)
call system('cp ' .. shellescape(a:origfile) .. ' ' .. shellescape(l:filename))
" Write front matter, if this is supported
if index(g:denote_note_file_extensions, l:ext) >= 0
call denote#loclist#jumptowindow()
exe 'edit ' .. l:filename
call denote#frontmatter#prepend(l:filename, l:identifier, l:title)
exe 'w'
endif
endfunction