add and remove tags
This commit is contained in:
@@ -76,3 +76,12 @@ function denote#frontmatter#setTitle(filename, title)
|
|||||||
call map(l:frontmatter, { _, v -> substitute(v, '^#\?+\?title:\?\s*"\?\zs.\{-\}\ze\"\?$', a:title, '')})
|
call map(l:frontmatter, { _, v -> substitute(v, '^#\?+\?title:\?\s*"\?\zs.\{-\}\ze\"\?$', a:title, '')})
|
||||||
call setbufline(a:filename, 1, l:frontmatter)
|
call setbufline(a:filename, 1, l:frontmatter)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Set tags in front matter
|
||||||
|
function denote#frontmatter#setTags(filename, tags)
|
||||||
|
let l:frontmatter = s:getFrontmatter(a:filename)
|
||||||
|
let l:tagline = denote#frontmatter#new(fnamemodify(a:filename, ':t'), '', '', a:tags)
|
||||||
|
\ ->filter('v:val =~ "^\\(#+file\\)\\?tags"')[0]
|
||||||
|
call map(l:frontmatter, { _, v -> v =~ '^\(#+file\)\?tags' ? l:tagline : v})
|
||||||
|
call setbufline(a:filename, 1, l:frontmatter)
|
||||||
|
endfunction
|
||||||
|
|||||||
@@ -43,5 +43,7 @@ function denote#ft#qf()
|
|||||||
" Denote-list specific configuration
|
" Denote-list specific configuration
|
||||||
if l:context['denote'] == 'list'
|
if l:context['denote'] == 'list'
|
||||||
command! -nargs=1 -range -buffer DenoteSetTitle :call denote#notes#settitle(<line1>, <q-args>)
|
command! -nargs=1 -range -buffer DenoteSetTitle :call denote#notes#settitle(<line1>, <q-args>)
|
||||||
|
command! -nargs=1 -range -buffer DenoteTagAdd :call denote#notes#tagmod(<line1>, <line2>, <q-args>, v:true)
|
||||||
|
command! -nargs=1 -range -buffer DenoteTagRm :call denote#notes#tagmod(<line1>, <line2>, <q-args>, v:false)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ endfunction
|
|||||||
function denote#loclist#reload()
|
function denote#loclist#reload()
|
||||||
let l:context = getloclist(0, {'context': 1})['context']
|
let l:context = getloclist(0, {'context': 1})['context']
|
||||||
if has_key(l:context, 'denote') && has_key(l:context, 'gfun')
|
if has_key(l:context, 'denote') && has_key(l:context, 'gfun')
|
||||||
execute ':lclose'
|
exe 'lclose'
|
||||||
call l:context['gfun']()
|
call l:context['gfun']()
|
||||||
execute ':lwindow'
|
exe 'lwindow'
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ endfunction
|
|||||||
function denote#notes#grep(re)
|
function denote#notes#grep(re)
|
||||||
let l:title = 'Grep results for: ' .. a:re
|
let l:title = 'Grep results for: ' .. a:re
|
||||||
let l:fpat=map(copy(g:denote_note_file_extensions), {_, e -> g:denote_directory .. '/*.' .. e})->join()
|
let l:fpat=map(copy(g:denote_note_file_extensions), {_, e -> g:denote_directory .. '/*.' .. e})->join()
|
||||||
execute 'silent! lvimgrep ' .. a:re .. ' ' .. l:fpat
|
exe 'silent! lvimgrep ' .. a:re .. ' ' .. l:fpat
|
||||||
let l:Gfun = function('denote#notes#grep', [a:re])
|
let l:Gfun = function('denote#notes#grep', [a:re])
|
||||||
call denote#loclist#setgrep(l:title, l:Gfun)
|
call denote#loclist#setgrep(l:title, l:Gfun)
|
||||||
endfunction
|
endfunction
|
||||||
@@ -34,7 +34,7 @@ function denote#notes#new(title, ft=g:denote_new_ft)
|
|||||||
" Jump to window this location list belongs to
|
" Jump to window this location list belongs to
|
||||||
call denote#loclist#jumptowindow()
|
call denote#loclist#jumptowindow()
|
||||||
" Open file and write front matter
|
" Open file and write front matter
|
||||||
execute 'edit ' l:fn
|
exe 'edit ' l:fn
|
||||||
call setline(1, denote#frontmatter#new(a:ft, l:identifier, a:title))
|
call setline(1, denote#frontmatter#new(a:ft, l:identifier, a:title))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -64,7 +64,9 @@ function denote#notes#settitle(linenr, title)
|
|||||||
exe 'silent file ' .. l:newfilename
|
exe 'silent file ' .. l:newfilename
|
||||||
exe 'silent w'
|
exe 'silent w'
|
||||||
exe 'lopen'
|
exe 'lopen'
|
||||||
|
if fnamemodify(l:filename, ':t') != fnamemodify(l:newfilename, ':t')
|
||||||
call delete(l:filename)
|
call delete(l:filename)
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
if fnamemodify(l:filename, ':t') == fnamemodify(l:newfilename, ':t')
|
if fnamemodify(l:filename, ':t') == fnamemodify(l:newfilename, ':t')
|
||||||
return
|
return
|
||||||
@@ -72,3 +74,51 @@ function denote#notes#settitle(linenr, title)
|
|||||||
call rename(l:filename, l:newfilename)
|
call rename(l:filename, l:newfilename)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Function to add or remove a tag to the selected entries. The last argument
|
||||||
|
" a:add, is set to v:true to add, and v:false to remove.
|
||||||
|
function denote#notes#tagmod(line1, line2, tag, add)
|
||||||
|
" Get file first!
|
||||||
|
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:noteid = denote#meta#noteIdFromFile(l:filename)
|
||||||
|
let l:notetags = denote#meta#noteTagsFromFile(l:filename)
|
||||||
|
let l:idx = index(l:notetags, a:tag)
|
||||||
|
if a:add
|
||||||
|
if l:idx >= 0
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
call add(l:notetags, a:tag)
|
||||||
|
else
|
||||||
|
if l:idx == -1
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
call remove(l:notetags, a:tag)
|
||||||
|
endif
|
||||||
|
let l:notesignature = denote#meta#noteSignatureFromFile(l:filename)
|
||||||
|
let l:title = denote#meta#noteTitleFromFile(l:filename)
|
||||||
|
let l:ext = fnamemodify(l:filename, ':e')
|
||||||
|
let l:newfilename = denote#meta#filename(l:ext, l:noteid, l:title, l:notetags, l:notesignature)
|
||||||
|
if index(g:denote_note_file_extensions, l:ext) >= 0
|
||||||
|
" Handle front matter
|
||||||
|
call denote#frontmatter#setTags(l:filename, l:notetags)
|
||||||
|
call denote#loclist#jumptowindow()
|
||||||
|
exe l:bufnr .. 'buf'
|
||||||
|
exe 'silent file ' .. l:newfilename
|
||||||
|
exe 'silent w'
|
||||||
|
exe 'lopen'
|
||||||
|
call delete(l:filename)
|
||||||
|
else
|
||||||
|
if fnamemodify(l:filename, ':t') == fnamemodify(l:newfilename, ':t')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call rename(l:filename, l:newfilename)
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user