md: use of ft-local functions instead of script-local functions

This commit is contained in:
2026-03-04 09:08:13 +01:00
parent 5b7825d358
commit 320bc0b6c0

View File

@@ -25,7 +25,7 @@ let b:loaded_denote_ftplugin_notes = 1
" 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()
function DenoteNoteCompleteLinkColumn()
" Get the substring from the start of the line until col('.')
let l:x = max([1, col('.')-2])
let l:l = getline('.')[:l:x]
@@ -48,7 +48,7 @@ function s:column()
endfunction
" Return completion items given by the base
function s:suggestions(base)
function DenoteNoteCompleteLinkSuggestions(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 = []
@@ -68,19 +68,19 @@ function s:suggestions(base)
endfunction
" Completion function for denote links
function s:complete_link(findstart, base)
return a:findstart == 1 ? s:column() : s:suggestions(a:base)
function DenoteNoteCompleteLink(findstart, base)
return a:findstart == 1 ? DenoteNoteCompleteLinkColumn() : DenoteNoteCompleteLinkSuggestions(a:base)
endfunction
setlocal omnifunc=s:complete_link()
setlocal omnifunc=DenoteNoteCompleteLink
" Denote links are of the form 'denote:<note id>'; we require the column.
setlocal isfname+=:
" Set the function to resolve the filename under the cursor (see |gf|).
function s:gotofile()
function DenoteNoteGotoFile()
return v:fname !~ '^denote:'
\ ? v:fname
\ : libdenote#scheme_find(g:denote_directory, v:fname[7:]) ?? v:fname
endfunction
setlocal includeexpr=s:gotofile()
setlocal includeexpr=DenoteNoteGotoFile()
" Back references command
let b:meta = libdenote#scheme_metadata(expand('%:t'))