itchyny/lightline.vim

[Feature request] Formal arguments in component_function

tkapias opened this issue · 5 comments

I use vimcaps and I included its vimcaps#statusline(N) function in lightline's component_function.

But vimcaps#statusline(N) take a formal argument to determine how many locks statuses to display.

  • Currently Lightline does not accept any formal argument for component_function.

autoload/lightline.vim:

 182for f in values(s:lightline.component_function)
 183silent! call call(f, [])
 184endfor
  • So I used a wrapper function for now:
function! LocksStatusLine()
    return vimcaps#statusline(-3)
endfunction

Could you add the ability to pass arguments to call() in component_function?

What value should lightline give for the arguments?

To stay compatible with the actual design the {args} will have to be optional, so f could be {func} or {func}, [{args}].

My VimL skill is basic so I'm not sure of the most elegant solution. I will continue to look at it to learn.

I don't see the point of the feature request. You configure with your wrapper function, or if you don't like to write the three lines, you can register it as non-function component. Minimal API of the plugin already allows you to configure and I think it's not worth implementing this kind of feature to grow the way how you do to archive the same thing.

I see 2 reasons:

  1. A new user has no indication of whether or not arguments can be used here, and does not know at first sight that an empty argument is forced on call(). A note to this effect in the readme might also suffice.

  2. It's a pity to lengthen the vimrc with an extra function when you want to include a function from another plugin that should take an argument. But yeah, it's quite rare because most of the time these arguments are in independent options and not in the function arguments.

Is it worth attempting to make you a PR? If not, a little update in the Readme would be nice.

I think the existing examples in README.md suggests about the limitation of the function component. But if you send me a PR, I'll review that. Also note that the call() there exists just for loading the autoload functions, not directly used for the status line.