copy files to denote directory
This commit is contained in:
@@ -8,6 +8,7 @@ function denote#commands#load()
|
||||
command -nargs=1 -complete=custom,denote#completion#tags DenoteByTag call denote#notes#bytag(<q-args>) | lcl | lopen
|
||||
command -nargs=+ DenoteGrep call denote#notes#grep(<q-args>) | lcl | lopen
|
||||
command -nargs=1 DenoteNew call denote#notes#new(<q-args>)
|
||||
command -nargs=1 -complete=file DenoteCopy call denote#notes#copy(<q-args>)
|
||||
|
||||
" Register auto commands
|
||||
autocmd BufReadPost quickfix call denote#ft#qf()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user