md: use of ft-local functions instead of script-local functions
This commit is contained in:
@@ -25,7 +25,7 @@ let b:loaded_denote_ftplugin_notes = 1
|
|||||||
|
|
||||||
" Find the column where the completion starts. This must be between 1 and
|
" Find the column where the completion starts. This must be between 1 and
|
||||||
" col('.'). Denote links are of this form: `denote:<identifier>`.
|
" 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('.')
|
" Get the substring from the start of the line until col('.')
|
||||||
let l:x = max([1, col('.')-2])
|
let l:x = max([1, col('.')-2])
|
||||||
let l:l = getline('.')[:l:x]
|
let l:l = getline('.')[:l:x]
|
||||||
@@ -48,7 +48,7 @@ function s:column()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Return completion items given by the base
|
" Return completion items given by the base
|
||||||
function s:suggestions(base)
|
function DenoteNoteCompleteLinkSuggestions(base)
|
||||||
let l:prefix = a:base->matchstr('^denote:\zs.*$')
|
let l:prefix = a:base->matchstr('^denote:\zs.*$')
|
||||||
let l:flist = glob(g:denote_directory .. '/' .. (l:prefix ? '*' .. l:prefix .. '*' : '*'), 0, v:true)
|
let l:flist = glob(g:denote_directory .. '/' .. (l:prefix ? '*' .. l:prefix .. '*' : '*'), 0, v:true)
|
||||||
let l:res = []
|
let l:res = []
|
||||||
@@ -68,19 +68,19 @@ function s:suggestions(base)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Completion function for denote links
|
" Completion function for denote links
|
||||||
function s:complete_link(findstart, base)
|
function DenoteNoteCompleteLink(findstart, base)
|
||||||
return a:findstart == 1 ? s:column() : s:suggestions(a:base)
|
return a:findstart == 1 ? DenoteNoteCompleteLinkColumn() : DenoteNoteCompleteLinkSuggestions(a:base)
|
||||||
endfunction
|
endfunction
|
||||||
setlocal omnifunc=s:complete_link()
|
setlocal omnifunc=DenoteNoteCompleteLink
|
||||||
" Denote links are of the form 'denote:<note id>'; we require the column.
|
" Denote links are of the form 'denote:<note id>'; we require the column.
|
||||||
setlocal isfname+=:
|
setlocal isfname+=:
|
||||||
" Set the function to resolve the filename under the cursor (see |gf|).
|
" Set the function to resolve the filename under the cursor (see |gf|).
|
||||||
function s:gotofile()
|
function DenoteNoteGotoFile()
|
||||||
return v:fname !~ '^denote:'
|
return v:fname !~ '^denote:'
|
||||||
\ ? v:fname
|
\ ? v:fname
|
||||||
\ : libdenote#scheme_find(g:denote_directory, v:fname[7:]) ?? v:fname
|
\ : libdenote#scheme_find(g:denote_directory, v:fname[7:]) ?? v:fname
|
||||||
endfunction
|
endfunction
|
||||||
setlocal includeexpr=s:gotofile()
|
setlocal includeexpr=DenoteNoteGotoFile()
|
||||||
|
|
||||||
" Back references command
|
" Back references command
|
||||||
let b:meta = libdenote#scheme_metadata(expand('%:t'))
|
let b:meta = libdenote#scheme_metadata(expand('%:t'))
|
||||||
|
|||||||
Reference in New Issue
Block a user