Compare commits
2 Commits
55bbeecb0a
...
4fb6e977ff
| Author | SHA1 | Date | |
|---|---|---|---|
| 4fb6e977ff | |||
| 5d631a5506 |
@@ -1,14 +1,3 @@
|
|||||||
" This function is used to autocomplete the tags in user commands.
|
|
||||||
function s:tagList(ArgLead, cmdLine, CursorPos)
|
|
||||||
let l:files=glob(g:denote_directory .. '/*', 0, v:true)
|
|
||||||
let l:tags=[]
|
|
||||||
for f in l:files
|
|
||||||
let l:tags=extend(l:tags, denote#meta#noteTagsFromFile(f))
|
|
||||||
endfor
|
|
||||||
return uniq(sort(l:tags))->join("\n")
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
|
|
||||||
" Public commands
|
" Public commands
|
||||||
function denote#commands#load()
|
function denote#commands#load()
|
||||||
if exists('g:denote_commands_loaded') && g:denote_commands_loaded
|
if exists('g:denote_commands_loaded') && g:denote_commands_loaded
|
||||||
@@ -16,7 +5,7 @@ function denote#commands#load()
|
|||||||
endif
|
endif
|
||||||
" Register user commands
|
" Register user commands
|
||||||
command -nargs=* Denote call denote#notes#list(<q-args>) | lcl | lopen
|
command -nargs=* Denote call denote#notes#list(<q-args>) | lcl | lopen
|
||||||
command -nargs=1 -complete=custom,s:tagList DenoteByTag call denote#notes#bytag(<q-args>) | lcl | lopen
|
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=+ DenoteGrep call denote#notes#grep(<q-args>) | lcl | lopen
|
||||||
command -nargs=1 DenoteNew call denote#notes#new(<q-args>)
|
command -nargs=1 DenoteNew call denote#notes#new(<q-args>)
|
||||||
|
|
||||||
|
|||||||
@@ -47,3 +47,13 @@ endfunction
|
|||||||
function denote#completion#get(findstart, base)
|
function denote#completion#get(findstart, base)
|
||||||
return a:findstart == 1 ? s:column() : s:suggestions(a:base)
|
return a:findstart == 1 ? s:column() : s:suggestions(a:base)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Completion function for denote tags
|
||||||
|
function denote#completion#tags(ArgLead, cmdLine, CursorPos)
|
||||||
|
let l:files=glob(g:denote_directory .. '/*', 0, v:true)
|
||||||
|
let l:tags=[]
|
||||||
|
for f in l:files
|
||||||
|
let l:tags=extend(l:tags, denote#meta#noteTagsFromFile(f))
|
||||||
|
endfor
|
||||||
|
return uniq(sort(l:tags))->join("\n")
|
||||||
|
endfunction
|
||||||
|
|||||||
@@ -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,10 @@ 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 -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)
|
||||||
|
nnoremap <buffer> C :DenoteSetTitle
|
||||||
|
nnoremap <buffer> + :DenoteTagAdd
|
||||||
|
nnoremap <buffer> - :DenoteTagRm
|
||||||
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
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ function denote#notes#settitle(linenr, title)
|
|||||||
let l:noteid = denote#meta#noteIdFromFile(l:filename)
|
let l:noteid = denote#meta#noteIdFromFile(l:filename)
|
||||||
let l:notetags = denote#meta#noteTagsFromFile(l:filename)
|
let l:notetags = denote#meta#noteTagsFromFile(l:filename)
|
||||||
let l:notesignature = denote#meta#noteSignatureFromFile(l:filename)
|
let l:notesignature = denote#meta#noteSignatureFromFile(l:filename)
|
||||||
let l:oldtitle = denote#meta#noteTitleFromFile (l:filename)
|
let l:oldtitle = denote#meta#noteTitleFromFile(l:filename)
|
||||||
let l:ext = fnamemodify(l:filename, ':e')
|
let l:ext = fnamemodify(l:filename, ':e')
|
||||||
let l:newfilename = denote#meta#filename(l:ext, l:noteid, a:title, l:notetags, l:notesignature)
|
let l:newfilename = denote#meta#filename(l:ext, l:noteid, a:title, l:notetags, l:notesignature)
|
||||||
" If this note has a front matter, we rewrite the front matter and rename the
|
" If this note has a front matter, we rewrite the front matter and rename the
|
||||||
@@ -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, l:idx)
|
||||||
|
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