Coder Social home page Coder Social logo

Comments (9)

itchyny avatar itchyny commented on August 11, 2024 1

I created lightline plugin before NeoVim was forked from Vim, and Lua API became so common. So the design does not look well with the Lua API (I don't use NeoVim and not tested the plugin with the Lua API). Having said that, gitbranch = 'v:lua.gitBranch' should work, but it needs some patch fixing code not working with v:lua. I can't include as it is, the question here is how can we check the function existence of v:lua.F?

diff --git a/autoload/lightline.vim b/autoload/lightline.vim
index e1f09ca..5ca6c20 100644
--- a/autoload/lightline.vim
+++ b/autoload/lightline.vim
@@ -296,7 +296,7 @@ endfunction
 function! s:subseparator(components, subseparator, expanded) abort
   let [a, c, f, v, u] = [a:components, s:lightline.component, s:lightline.component_function, s:lightline.component_visible_condition, s:lightline.component_function_visible_condition]
   let xs = map(range(len(a:components)), 'a:expanded[v:val] ? "1" :
-        \ has_key(f, a[v:val]) ? (has_key(u, a[v:val]) ? "(".u[a[v:val]].")" : (exists("*".f[a[v:val]]) ? "" : "exists(\"*".f[a[v:val]]."\")&&").f[a[v:val]]."()!=#\"\"") :
+        \ has_key(f, a[v:val]) ? (has_key(u, a[v:val]) ? "(".u[a[v:val]].")" : f[a[v:val]]."()!=#\"\"") :
         \ has_key(v, a[v:val]) ? "(".v[a[v:val]].")" : has_key(c, a[v:val]) ? "1" : "0"')
   return '%{' . (xs[0] ==# '1' || xs[0] ==# '(1)' ? '' : xs[0] . '&&(') . join(xs[1:], '||') . (xs[0] ==# '1' || xs[0] ==# '(1)' ? '' : ')') . '?"' . a:subseparator . '":""}'
 endfunction
@@ -380,7 +380,7 @@ function! s:expand(components) abort
 endfunction
 
 function! s:func(name) abort
-  return exists('*' . a:name) ? '%{' . a:name . '()}' : '%{exists("*' . a:name . '")?' . a:name . '():""}'
+  return '%{' . a:name . '()}'
 endfunction
 
 function! s:line(tabline, inactive) abort

from lightline.vim.

itchyny avatar itchyny commented on August 11, 2024 1

I don't like to use luaeval here. I believe we could check function existence in a consistent way, hope anyone asks NeoVim devs if they have thoughts on making exists("*v:lua.F") works.

from lightline.vim.

itchyny avatar itchyny commented on August 11, 2024 1

Although this issue isn't resolved, I can do nothing to fix in this plugin so closing the issue. I still think the request for NeoVim neovim/neovim#24587 (comment) is reasonable. Please help them by writing a NeoVim patch to make Vim script plugins work well on NeoVim.

from lightline.vim.

itchyny avatar itchyny commented on August 11, 2024 1

@jonhoo @pauldesmondparker @glepnir NeoVim v0.9.5 does not work with exists("*v:lua.F"). Existence check for user-defined functions should be prefixed by *.

from lightline.vim.

glepnir avatar glepnir commented on August 11, 2024 1

hmm i dont know why it through invaid expression. i don't check lightline code :P should return 0 when it start with *v:lua ..for viml user custom function it start with * for lua i just use v:lua directly...let me think about it.

from lightline.vim.

pauldesmondparker avatar pauldesmondparker commented on August 11, 2024

Thank you, worked like a charm. Not sustainable, but at least it was nice to see it work directly.

Any chance of using this, to check for the Lua function:

function! IsLuaFunction(name) abort
    return luaeval(a:name)->type() == v:t_func
endfunction

from lightline.vim.

jonhoo avatar jonhoo commented on August 11, 2024

@itchyny neovim/neovim#26485 has landed and makes exists able to check for v:lua functions 🎉 I'm hoping that means there's a path to getting v:lua.F to work? Currently it yields:

E15: Invalid expression: v:lua

from lightline.vim.

itchyny avatar itchyny commented on August 11, 2024

This check should check "*v:lua." right? The patch implements in the different way than proposed by the original issue.

from lightline.vim.

glepnir avatar glepnir commented on August 11, 2024

Yes. Opportunistic but breaks compatibility T.T working on it

from lightline.vim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.