Compare commits
2 Commits
4fb6e977ff
...
1afd45b91a
| Author | SHA1 | Date | |
|---|---|---|---|
| 1afd45b91a | |||
| dfc15def2b |
@@ -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
|
||||
|
||||
@@ -45,8 +45,11 @@ function denote#ft#qf()
|
||||
command! -nargs=1 -range -buffer DenoteSetTitle :call denote#notes#settitle(<line1>, <q-args>)
|
||||
command! -nargs=1 -range -buffer -complete=custom,denote#completion#tags DenoteTagAdd :call denote#notes#tagmod(<line1>, <line2>, <q-args>, v:true)
|
||||
command! -nargs=1 -range -buffer -complete=custom,denote#completion#tags DenoteTagRm :call denote#notes#tagmod(<line1>, <line2>, <q-args>, v:false)
|
||||
command! -range -buffer DenoteDelete :call denote#notes#rm(<line1>, <line2>)
|
||||
nnoremap <buffer> C :DenoteSetTitle
|
||||
nnoremap <buffer> + :DenoteTagAdd
|
||||
nnoremap <buffer> - :DenoteTagRm
|
||||
nnoremap <buffer> dd :DenoteDelete<CR>
|
||||
" TODO: Add visual maps for line ranges +/-/delete
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -122,3 +122,49 @@ 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
|
||||
|
||||
" Delete notes from denote directory
|
||||
function denote#notes#rm(line1, line2)
|
||||
let l:items = getloclist(0, {'items': 1})['items']
|
||||
if empty(l:items)
|
||||
return
|
||||
endif
|
||||
for i in range(a:line1, a:line2)
|
||||
let l:item = l:items[i-1]
|
||||
let l:bufnr = l:item['bufnr']
|
||||
let l:filename = bufname(l:bufnr)
|
||||
let l:title = denote#meta#noteTitleFromFile(l:filename)
|
||||
let l:answer = confirm('Are you sure you want to delete the note "' .. l:title .. '"?', "&Yes\n&No\n", 2, 'Question')
|
||||
if l:answer != 1
|
||||
continue
|
||||
endif
|
||||
" Wipe buffer, if it exists
|
||||
if bufexists(l:filename)
|
||||
exe 'silent bwipe ' .. fnameescape(l:filename)
|
||||
endif
|
||||
" Delete file
|
||||
call delete(l:filename)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user