Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any plans to allow configuration from lua? #52

Open
IndianBoy42 opened this issue Aug 1, 2021 · 8 comments
Open

Any plans to allow configuration from lua? #52

IndianBoy42 opened this issue Aug 1, 2021 · 8 comments
Labels
feature New feature or request lua neovim

Comments

@IndianBoy42
Copy link

Right now all the configuration is done through vimscript calls and variables. Personally, I want to keep as much of my configuration as lua, but this plugin makes me keep around some large blocks of vim.cmd[[]]

@IndianBoy42
Copy link
Author

BTW there are some problems in the example configs when run inside a vim.cmd [[ ]] block.

  1. Using s: variables gives me a 'illegal variable names' error
  2. The below block of code gives me an error that it can't find the list ending ']'
vim.cmd [[
call wilder#set_option('pipeline', [
         wilder#branch(
           wilder#cmdline_pipeline({
             'fuzzy': 1,
           }),
           wilder#python_search_pipeline({
             'pattern': 'fuzzy',
           }),
         ),
       ])
]]

@gelguy
Copy link
Owner

gelguy commented Aug 1, 2021

There's some issues with writing the configuration fully in Lua due to neovim/neovim#13436. I'll explore if writing wrappers in Lua will help avoid this issue.

Regarding the vim.cmd block,

  1. The s: variables have to be renamed to g: variables.
  2. VimScript needs \ to delimit a line continuation, so the correct config will be
vim.cmd [[
call wilder#set_option('pipeline', [
      \   wilder#branch(
      \     wilder#cmdline_pipeline({
      \       'fuzzy': 1,
      \     }),
      \     wilder#python_search_pipeline({
      \       'pattern': 'fuzzy',
      \     }),
      \   ),
      \ ])
]]

@gelguy gelguy added the feature New feature or request label Aug 1, 2021
@IndianBoy42
Copy link
Author

IndianBoy42 commented Aug 1, 2021

    vim.cmd [[
  call wilder#set_option('pipeline', [
       \    wilder#branch(
       \      wilder#cmdline_pipeline({
       \        'fuzzy': 1,
       \      }),
       \      wilder#python_search_pipeline({
       \        'pattern': 'fuzzy',
       \      }),
       \    ),
       \  ])
    ]]

Results in:

packer.nvim: Error running config for wilder.nvim: /home/amedhi/.config/nvim/lua/lv-wilder/init.lua:21: Vim(call):E697: Missing end of List ']':
  vim.cmd [[
let g:wilder_highlighters = [ wilder#pcre2_highlighter(), wilder#basic_highlighter(), ] 
call wilder#set_option('renderer', wilder#renderer_mux({
  \  ':': wilder#popupmenu_renderer({
  \    'highlighter': wilder#basic_highlighter(),
  \  }),
  \  '/': wilder#wildmenu_renderer({
  \    'highlighter': wilder#basic_highlighter(),
  \  }),
  \})
)
    ]]

Results in:

packer.nvim: Error running config for wilder.nvim: /home/amedhi/.config/nvim/lua/lv-wilder/init.lua:34: Vim(call):E116: Invalid arguments for function wilder#renderer_mux

Should I open a new issue about the example configs?

@IndianBoy42
Copy link
Author

I just tried merging all the lines (so no line continuations are necessary) and I no longer get any error messages

@gelguy
Copy link
Owner

gelguy commented Aug 1, 2021

For the first case I can't reproduce it (although I'm not using packer, just an init.lua).

For the second case there last ) is missing the leading \.

@pinpox
Copy link

pinpox commented Oct 21, 2021

A proper way to use lua config would be great! Something like the setup {} functions that many other plugins use to allow specifying a table of options

@gelguy
Copy link
Owner

gelguy commented Oct 21, 2021

I'm working on a workaround for neovim/neovim#13436, which will allow easier configuration in Lua. Will update here when the PR is merged.

@gelguy
Copy link
Owner

gelguy commented Jan 6, 2022

I've merged #115 which includes an experimental Lua shim for wilder. There is no documentation (since it is highly experimental), but the configuration should be straightforward:

For every wilder#<foo> method, an analogous wilder.<foo> method is exposed in Lua. Take this example config:

call wilder#setup({'modes': [':', '/', '?']})
call wilder#set_option('use_python_remote_plugin', 0)

call wilder#set_option('pipeline', [
      \   wilder#branch(
      \     wilder#python_file_finder_pipeline({
      \       'file_command': ['find', '.', '-type', 'f', '-printf', '%P\n'],
      \       'dir_command': ['find', '.', '-type', 'd', '-printf', '%P\n'],
      \       'filters': ['fuzzy_filter', 'difflib_sorter'],
      \     }),
      \     wilder#cmdline_pipeline(),
      \     wilder#python_search_pipeline(),
      \   ),
      \ ])

The config in Lua would then look like:

local wilder = require('wilder')
wilder.set_option('use_python_remote_plugin', 0)
wilder.setup({modes = {'/', '?', ':'}})

wilder.set_option('pipeline', {
  wilder.branch(
    wilder.python_file_finder_pipeline({
      file_comand = {'find', '.', '-type', 'f', '-printf', '%P\n'},
      dir_comand = {'find', '.', '-type', 'd', '-printf', '%P\n'},
      filters = {'fuzzy_filter', 'difflib_sorter'},
    }),
    wilder.cmdline_pipeline(),
    wilder.python_search_pipeline()
  ),
})

Essentially, wilder#set_option() is translated to wilder.set_option() and similar for other methods. All arguments remain the same. Lambdas have to be translated accordingly e.g. {ctx, x -> x * 2} becomes function(ctx, x) return x*2 end.

Note: only the top level wilder#... methods are provided, methods in deeper namespaces e.g. wilder#cmdline#parse() are not provided.

Note: The Lua shim introduces a bit of overhead since Neovim has to do some translation of the arguments passed from VimScript to Lua and vice versa. Ultimately, most of the logic will be passed to the VimScript core so in general a Lua config will always be slower than a VimScript config. (This could be alleviated by providing pure Lua implementations of the VimScript core, but that would be a topic for another day.)

@gelguy gelguy pinned this issue Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request lua neovim
Projects
None yet
Development

No branches or pull requests

3 participants