fixed denote directory support
This commit is contained in:
@@ -24,10 +24,11 @@ endfunction
|
|||||||
" Return completion items given by the base
|
" Return completion items given by the base
|
||||||
function s:suggestions(base)
|
function s:suggestions(base)
|
||||||
let prefix = a:base->matchstr('^denote:\zs.*$')
|
let prefix = a:base->matchstr('^denote:\zs.*$')
|
||||||
let flist = glob(t:denote_directory .. prefix ? "*" .. prefix .. "*" : "*", 0, v:true)
|
let flist = glob(t:denote_directory .. (prefix ? "*" .. prefix .. "*" : "*"), 0, v:true)
|
||||||
let res = []
|
let res = []
|
||||||
for filename in flist
|
for filename in flist
|
||||||
let noteId = denote#meta#noteIdFromFile(filename)
|
let noteId = denote#meta#noteIdFromFile(filename)
|
||||||
|
echom "Gote noteId: " .. noteId
|
||||||
let noteTitle = denote#meta#noteTitleFromFile(filename)
|
let noteTitle = denote#meta#noteTitleFromFile(filename)
|
||||||
if noteId == v:false || (noteId !~ '^' .. prefix && noteTitle !~ prefix)
|
if noteId == v:false || (noteId !~ '^' .. prefix && noteTitle !~ prefix)
|
||||||
continue
|
continue
|
||||||
@@ -43,16 +44,6 @@ function s:suggestions(base)
|
|||||||
return res
|
return res
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! Myomni(findstart, base)
|
|
||||||
if a:findstart == 1
|
|
||||||
let tmp = s:column()
|
|
||||||
return tmp
|
|
||||||
else
|
|
||||||
let tmp = s:suggestions(a:base)
|
|
||||||
return tmp
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Completion function for denote links
|
" Completion function for denote links
|
||||||
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)
|
||||||
|
|||||||
@@ -10,27 +10,28 @@ function denote#meta#fileFromNoteId(noteId)
|
|||||||
" (A) First, we get all files that contain the note id as substring.
|
" (A) First, we get all files that contain the note id as substring.
|
||||||
" (B) Then we ensure that the note id is followed by another field or by the
|
" (B) Then we ensure that the note id is followed by another field or by the
|
||||||
" file extension.
|
" file extension.
|
||||||
|
" TODO: Fix the following (now, we have full paths!)
|
||||||
let files = glob(t:denote_directory .. "*" .. a:noteId .. "*", 0, v:true)
|
let files = glob(t:denote_directory .. "*" .. a:noteId .. "*", 0, v:true)
|
||||||
\ ->filter('v:val =~ "' .. a:noteId .. '\\(==\\|--\\|__\\|\\.\\)"')
|
\ ->filter('v:val->split("/")[-1] =~ "' .. a:noteId .. '\\(==\\|--\\|__\\|\\.\\)"')
|
||||||
\ ->filter('v:val =~ "^' .. a:noteId .. '\\|@@' .. a:noteId .. '"')
|
\ ->filter('v:val->split("/")[-1] =~ "^' .. a:noteId .. '\\|@@' .. a:noteId .. '"')
|
||||||
return empty(files) ? v:false : files[0]
|
return empty(files) ? v:false : files[0]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Return the note id from the filename. On failure, v:false is returned.
|
" Return the note id from the filename. On failure, v:false is returned.
|
||||||
function denote#meta#noteIdFromFile(filename)
|
function denote#meta#noteIdFromFile(file)
|
||||||
return a:filename->matchstr("@@\\zs.\\{-\\}\\ze\\(==\\|--\\|__\\|\\..\\)")
|
return a:file->fnamemodify(':t')->matchstr("@@\\zs.\\{-\\}\\ze\\(==\\|--\\|__\\|\\..\\)")
|
||||||
\ ?? a:filename->matchstr("^.\\{-\\}\\ze\\(==\\|--\\|__\\|\\..\\)")
|
\ ?? a:file->fnamemodify(':t')->matchstr("^.\\{-\\}\\ze\\(==\\|--\\|__\\|\\..\\)")
|
||||||
\ ?? v:false
|
\ ?? v:false
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Return the note title from the filename.
|
" Return the note title from the filename.
|
||||||
function denote#meta#noteTitleFromFile(filename)
|
function denote#meta#noteTitleFromFile(file)
|
||||||
return a:filename->matchstr("--\\zs.\\{-\\}\\ze\\(==\\|@@\\|__\\|\\..\\)")->substitute("-", " ", "g")
|
return a:file->fnamemodify(':t')->matchstr("--\\zs.\\{-\\}\\ze\\(==\\|@@\\|__\\|\\..\\)")->substitute("-", " ", "g")
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Return the note tags from the filename as a list.
|
" Return the note tags from the filename as a list.
|
||||||
function denote#meta#noteTagsFromFile(filename)
|
function denote#meta#noteTagsFromFile(file)
|
||||||
return a:filename->matchstr("__\\zs.\\{-\\}\\ze\\(==\\|@@\\|--\\|\\..\\)")->split("_")
|
return a:file->fnamemodify(':t')->matchstr("__\\zs.\\{-\\}\\ze\\(==\\|@@\\|--\\|\\..\\)")->split("_")
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Identifier creation
|
" Identifier creation
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ function s:DenoteNotesByTag(tag)
|
|||||||
" Clear location list
|
" Clear location list
|
||||||
call denote#loclist#clear()
|
call denote#loclist#clear()
|
||||||
" Find files
|
" Find files
|
||||||
let files = glob(t:denote_directory .. "*_" .. a:tag .. "*", 0, v:true)->filter('v:val =~ "_' .. a:tag .. '\\(==\\|@@\\|__\\|_\\|\\.\\)"')
|
let files = glob(t:denote_directory .. "*_" .. a:tag .. "*", 0, v:true)->filter('v:val->split("/")[-1] =~ "_' .. a:tag .. '\\(==\\|@@\\|__\\|_\\|\\.\\)"')
|
||||||
" Populate location list
|
" Populate location list
|
||||||
let locTitle="Denote notes: " .. a:tag
|
let locTitle="Denote notes: " .. a:tag
|
||||||
call setloclist(0, [], 'r',
|
call setloclist(0, [], 'r',
|
||||||
@@ -72,10 +72,10 @@ function s:DenoteNotes(search)
|
|||||||
echom "Denote directory not specified, see |vim-denote|."
|
echom "Denote directory not specified, see |vim-denote|."
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let s = substitute(" " .. a:search .. " ", " ", "*", "g")
|
|
||||||
" Clear location list
|
" Clear location list
|
||||||
call denote#loclist#clear()
|
call denote#loclist#clear()
|
||||||
" Find files
|
" Find files
|
||||||
|
let s = substitute(" " .. a:search .. " ", " ", "*", "g")
|
||||||
let files = glob(t:denote_directory .. s, 0, v:true)
|
let files = glob(t:denote_directory .. s, 0, v:true)
|
||||||
" Populate location list
|
" Populate location list
|
||||||
let locTitle="Denote notes search:" .. a:search
|
let locTitle="Denote notes search:" .. a:search
|
||||||
|
|||||||
Reference in New Issue
Block a user