diff --git a/autoload/denote/commands.vim b/autoload/denote/commands.vim index 9e7f790..17d1a6f 100644 --- a/autoload/denote/commands.vim +++ b/autoload/denote/commands.vim @@ -8,6 +8,7 @@ function denote#commands#load() command -nargs=1 -complete=custom,denote#completion#tags DenoteByTag call denote#notes#bytag() | lcl | lopen command -nargs=+ DenoteGrep call denote#notes#grep() | lcl | lopen command -nargs=1 DenoteNew call denote#notes#new() + command -nargs=1 -complete=file DenoteCopy call denote#notes#copy() " Register auto commands autocmd BufReadPost quickfix call denote#ft#qf() diff --git a/autoload/denote/frontmatter.vim b/autoload/denote/frontmatter.vim index 73ae334..320cd2d 100644 --- a/autoload/denote/frontmatter.vim +++ b/autoload/denote/frontmatter.vim @@ -85,3 +85,9 @@ function denote#frontmatter#setTags(filename, tags) call map(l:frontmatter, { _, v -> v =~ '^\(#+file\)\?tags' ? l:tagline : v}) call setbufline(a:filename, 1, l:frontmatter) endfunction + +" Prepend frontmatter to file +function denote#frontmatter#prepend(filename, id, title, tags=[]) + let l:frontmatter = denote#frontmatter#new(fnamemodify(a:filename, ':t'), a:id, a:title, a:tags) + call appendbufline(a:filename, 0, l:frontmatter) +endfunction diff --git a/autoload/denote/notes.vim b/autoload/denote/notes.vim index 97c7948..6fb7981 100644 --- a/autoload/denote/notes.vim +++ b/autoload/denote/notes.vim @@ -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