cleaned
This commit is contained in:
@@ -1,59 +1,9 @@
|
||||
" Find the column where the completion starts. This must be between 1 and
|
||||
" col('.'). Denote links are of this form: `denote:<identifier>`.
|
||||
function s:column()
|
||||
" Get the substring from the start of the line until col('.')
|
||||
let l:l = getline('.')[:col('.')]
|
||||
" Take the shortest prefix of a denote link. This may be any of
|
||||
" \<d$
|
||||
" ..
|
||||
" \<denote:$
|
||||
" \<denote:\f$
|
||||
" \<denote:\f\f$
|
||||
" etc.
|
||||
let l:res = l:l->matchstrpos('\<denote:\f*$')
|
||||
if l:res[1] >= 0
|
||||
return l:res[1]
|
||||
endif
|
||||
let l:res = l:l->matchstrpos('\<d\f*$')
|
||||
if l:res[1] == -1
|
||||
return -3
|
||||
endif
|
||||
return 'denote:' =~ '^' .. l:res[0] ? l:res[1] : -3
|
||||
endfunction
|
||||
|
||||
" Return completion items given by the base
|
||||
function s:suggestions(base)
|
||||
let l:prefix = a:base->matchstr('^denote:\zs.*$')
|
||||
let l:flist = glob(g:denote_directory .. '/' .. (l:prefix ? '*' .. l:prefix .. '*' : '*'), 0, v:true)
|
||||
let l:res = []
|
||||
for filename in l:flist
|
||||
let l:noteId = denote#meta#noteIdFromFile(filename)
|
||||
let l:noteTitle = denote#meta#noteTitleFromFile(filename)
|
||||
if l:noteId == v:false || (l:noteId !~ '^' .. l:prefix && l:noteTitle !~ l:prefix)
|
||||
continue
|
||||
endif
|
||||
let l:noteTitle = l:noteTitle ?? '(no title)'
|
||||
let l:noteTags = denote#meta#noteTagsFromFile(filename)
|
||||
call add(l:res, {
|
||||
\ 'word' : 'denote:' .. l:noteId,
|
||||
\ 'abbr' : l:noteTitle,
|
||||
\ 'menu' : l:noteTags->join(', ')
|
||||
\ })
|
||||
endfor
|
||||
return l:res
|
||||
endfunction
|
||||
|
||||
" Completion function for denote links
|
||||
function denote#completion#get(findstart, base)
|
||||
return a:findstart == 1 ? s:column() : s:suggestions(a:base)
|
||||
endfunction
|
||||
|
||||
" Completion function for denote tags
|
||||
function denote#completion#tags(ArgLead, cmdLine, CursorPos)
|
||||
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))
|
||||
let l:tags=extend(l:tags, libdenote#scheme_metadata(f).tags)
|
||||
endfor
|
||||
return uniq(sort(l:tags))->join("\n")
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user