skywind3000 / quickmenu.vim

A nice customizable popup menu for vim
MIT License
278 stars 12 forks source link

Use a funcref instead of a string in quickmenu#append() #6

Closed tjdevries closed 7 years ago

tjdevries commented 7 years ago

Hi, awesome plugin :smile:

I'm wondering if it would be possible to use a function reference or lambda for quickmenu#append().

For example:

function! ExampleFunc(arg) abort
  return arg + 1
endfunction

call quickmenu#append('call funcref', funcref('ExampleFunc', [10]))

Thanks

tjdevries commented 7 years ago

this is mostly so that I can pass an argument (like a dictionary) into the function. A better example might be:

for setting in keys(config_dict)
  " Give the option of a setting for each item:
  call quickmenu#append(
            \ printf('Set: %s.%s', area, setting),
            \ { -> config#set_setting(config_dict, setting, input('New value: ')},
            \ )
endfor
skywind3000 commented 7 years ago

good point, new version released

tjdevries commented 7 years ago

Works great for me. I'm using it in my plugin here: www.github.com/tjdevries/conf.vim

It makes great menus now. Autogenerated cause of your wonderful plugin.

image

Having the ability to add descriptions is great for helping people to figure out what the options are. Thanks!

tjdevries commented 7 years ago

The code changes became very easy with your change.

      call quickmenu#append(
            \ printf('Set: %s.%s', area, setting),
            \ funcref('conf#set_setting_prompt', [
                    \ a:script,
                    \ area,
                    \ setting,
                    \ ]),
            \ conf#setting#get_description(a:script, area, setting)
            \ )