fixed denote directory support

This commit is contained in:
2026-02-23 13:07:33 +01:00
parent d2d01e83e0
commit ac75a8c679
3 changed files with 14 additions and 22 deletions

View File

@@ -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)

View File

@@ -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