-
Notifications
You must be signed in to change notification settings - Fork 66
Using Funcrefs/lambdas with wiki_map_link_create #104
Copy link
Copy link
Closed
Description
Description:
Currently wiki.vim doesn't support passing funcrefs/lambdas to the wiki_map_link_create option (because of strange VimL behavior).
Minimal working example
If we create a lambda: let CreateLoudLinks = {x -> toupper(x) . '!'}, then:
This works
echo exists('*CreateLoudLinks') " string
" = 1
echo call(CreateLoudLinks, ['hello world']) " symbol
" = HELLO WORLD!
But this doesn't work
echo exists(CreateLoudLinks) " symbol
" = E729: using Funcref as a String
echo call('*CreateLoudLinks', ['hello world']) " string
" = E117: Unknown function: CreateLinkLinks
The problem
The exists function always expects a string, however, the call function will fail if it receives a funcref as a string (but not as a symbol).
Suggested solution
In the source code the relevant bit seems to be:
" wiki.vim/autoload/wiki/link/word.vim
if !empty(g:wiki_map_link_create) && exists('*' . g:wiki_map_link_create)
let l:url = call(g:wiki_map_link_create, [a:url])
endif
Allowing the user to pass a funcref, and typecheck wiki_map_link_create here, before calling exists and call seems to me like a reasonable workaround for the inconsistency between the two functions.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels