diff --git a/autoload/denote/completion.vim b/autoload/denote/completion.vim index 6766c0a..54e189c 100644 --- a/autoload/denote/completion.vim +++ b/autoload/denote/completion.vim @@ -24,10 +24,11 @@ endfunction " Return completion items given by the base function s:suggestions(base) 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 = [] for filename in flist let noteId = denote#meta#noteIdFromFile(filename) + echom "Gote noteId: " .. noteId let noteTitle = denote#meta#noteTitleFromFile(filename) if noteId == v:false || (noteId !~ '^' .. prefix && noteTitle !~ prefix) continue @@ -43,16 +44,6 @@ function s:suggestions(base) return res 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 function denote#completion#get(findstart, base) return a:findstart == 1 ? s:column() : s:suggestions(a:base) diff --git a/autoload/denote/meta.vim b/autoload/denote/meta.vim index 6150528..6266edc 100644 --- a/autoload/denote/meta.vim +++ b/autoload/denote/meta.vim @@ -10,27 +10,28 @@ function denote#meta#fileFromNoteId(noteId) " (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 " file extension. + " TODO: Fix the following (now, we have full paths!) let files = glob(t:denote_directory .. "*" .. a:noteId .. "*", 0, v:true) - \ ->filter('v:val =~ "' .. a:noteId .. '\\(==\\|--\\|__\\|\\.\\)"') - \ ->filter('v:val =~ "^' .. a:noteId .. '\\|@@' .. a:noteId .. '"') + \ ->filter('v:val->split("/")[-1] =~ "' .. a:noteId .. '\\(==\\|--\\|__\\|\\.\\)"') + \ ->filter('v:val->split("/")[-1] =~ "^' .. a:noteId .. '\\|@@' .. a:noteId .. '"') return empty(files) ? v:false : files[0] endfunction " Return the note id from the filename. On failure, v:false is returned. -function denote#meta#noteIdFromFile(filename) - return a:filename->matchstr("@@\\zs.\\{-\\}\\ze\\(==\\|--\\|__\\|\\..\\)") - \ ?? a:filename->matchstr("^.\\{-\\}\\ze\\(==\\|--\\|__\\|\\..\\)") +function denote#meta#noteIdFromFile(file) + return a:file->fnamemodify(':t')->matchstr("@@\\zs.\\{-\\}\\ze\\(==\\|--\\|__\\|\\..\\)") + \ ?? a:file->fnamemodify(':t')->matchstr("^.\\{-\\}\\ze\\(==\\|--\\|__\\|\\..\\)") \ ?? v:false endfunction " Return the note title from the filename. -function denote#meta#noteTitleFromFile(filename) - return a:filename->matchstr("--\\zs.\\{-\\}\\ze\\(==\\|@@\\|__\\|\\..\\)")->substitute("-", " ", "g") +function denote#meta#noteTitleFromFile(file) + return a:file->fnamemodify(':t')->matchstr("--\\zs.\\{-\\}\\ze\\(==\\|@@\\|__\\|\\..\\)")->substitute("-", " ", "g") endfunction " Return the note tags from the filename as a list. -function denote#meta#noteTagsFromFile(filename) - return a:filename->matchstr("__\\zs.\\{-\\}\\ze\\(==\\|@@\\|--\\|\\..\\)")->split("_") +function denote#meta#noteTagsFromFile(file) + return a:file->fnamemodify(':t')->matchstr("__\\zs.\\{-\\}\\ze\\(==\\|@@\\|--\\|\\..\\)")->split("_") endfunction " Identifier creation diff --git a/plugin/denote.vim b/plugin/denote.vim index cbd355c..536c0e1 100644 --- a/plugin/denote.vim +++ b/plugin/denote.vim @@ -48,7 +48,7 @@ function s:DenoteNotesByTag(tag) " Clear location list call denote#loclist#clear() " 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 let locTitle="Denote notes: " .. a:tag call setloclist(0, [], 'r', @@ -72,10 +72,10 @@ function s:DenoteNotes(search) echom "Denote directory not specified, see |vim-denote|." return endif - let s = substitute(" " .. a:search .. " ", " ", "*", "g") " Clear location list call denote#loclist#clear() " Find files + let s = substitute(" " .. a:search .. " ", " ", "*", "g") let files = glob(t:denote_directory .. s, 0, v:true) " Populate location list let locTitle="Denote notes search:" .. a:search