feat: denote directory support

This commit is contained in:
2026-02-21 10:13:47 +01:00
parent 6d8f8c720b
commit d2d01e83e0
5 changed files with 103 additions and 16 deletions

View File

@@ -24,7 +24,7 @@ endfunction
" Return completion items given by the base
function s:suggestions(base)
let prefix = a:base->matchstr('^denote:\zs.*$')
let flist = glob(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)
@@ -34,7 +34,7 @@ function s:suggestions(base)
endif
let noteTitle = noteTitle ?? '(no title)'
let noteTags = denote#meta#noteTagsFromFile(filename)
let res = res->add({
call add(res, {
\ 'word' : 'denote:' .. noteId,
\ 'abbr' : noteTitle,
\ 'menu' : noteTags->join(', ')

View File

@@ -51,8 +51,13 @@ endfunction
" Load all references to the given note into the location list.
function denote#loclist#references(noteId)
if !exists('t:denote_directory')
echohl WarningMsg
echom "Denote directory not specified, see |vim-denote|."
return
endif
" Populate location list
execute "lvimgrep /\\<denote:" .. a:noteId .. "\\>/gj *"
silent! execute "lvimgrep /\\<denote:" .. a:noteId .. "\\>/gj " .. t:denote_directory .. "*"
" Adjust location list: set title and specify display function
let file=denote#meta#fileFromNoteId(a:noteId)
let noteTitle=denote#meta#noteTitleFromFile(file)

View File

@@ -10,7 +10,7 @@ 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.
let files = glob("*" .. a:noteId .. "*", 0, v:true)
let files = glob(t:denote_directory .. "*" .. a:noteId .. "*", 0, v:true)
\ ->filter('v:val =~ "' .. a:noteId .. '\\(==\\|--\\|__\\|\\.\\)"')
\ ->filter('v:val =~ "^' .. a:noteId .. '\\|@@' .. a:noteId .. '"')
return empty(files) ? v:false : files[0]