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

lua: autocmds take 2 #14661

Merged
merged 1 commit into from
Feb 27, 2022
Merged

Conversation

tjdevries
Copy link
Contributor

Restarting my attempt of #12378

Plan is:

  1. Add a bunch more functional tests for autocmds
  2. Add nvim_* api functions to access and test autocmds
  3. THEN we'll start the refactor again of do_cmdline and/or create a new function that can be used by autocmds.
  4. When we do this, we can change the return type of the LineGetter to something that could return a union of items (command, LuaRef, vim funcref). And then we execute it there

Once we do that, it's very easy to extend the nvim_* api functions to accept lua refs (as a new key) and use the refactoring that we did.

I'll be moving code over as I implement this from the original PR.

Status:

  • May 28, 2021: I've implemented most of step 1 & 2. Probably will add more weird edge cases as I think of them.

@RustemB
Copy link

RustemB commented Jul 11, 2021

image

@tjdevries
Copy link
Contributor Author

Haha, this is my next big core feature I will work on 😁 it is a fun one to tackle.

@RustemB

This comment has been minimized.

@hrsh7th

This comment has been minimized.

@Olyve

This comment has been minimized.

@ttys3

This comment has been minimized.

@clason

This comment has been minimized.

@shadmansaleh

This comment has been minimized.

@bfredl
Copy link
Member

bfredl commented Jul 21, 2021

I still need to find how rpc api is handled to see if adding that to exsisting api functions will be a breaking change :P

It is not a breaking change.

@tjdevries tjdevries force-pushed the tjdevries/lua_autocmd_v2 branch 2 times, most recently from 6e476af to 81045a5 Compare July 30, 2021 18:12
nanotee pushed a commit to nanotee/nvim-lua-guide that referenced this pull request Aug 7, 2021
Also mentioned the 2nd take on autocommands PR (neovim/neovim#14661) as well as the newer plugin for running Fennel (https://github.com/rktjmp/hotpot.nvim).
@sandangel

This comment has been minimized.

@tjdevries
Copy link
Contributor Author

tjdevries commented Aug 9, 2021

hi, may I ask if there is any update on this PR?

I am working on it when I have time :) In general, it is considered bad form to do these kinds of posts in a PR that has commits somewhat recently.

@sandangel

This comment has been minimized.

@clason clason added api libnvim, Nvim RPC API lua stdlib events events, autocommands labels Sep 6, 2021
@tjdevries tjdevries force-pushed the tjdevries/lua_autocmd_v2 branch 2 times, most recently from 0f28a28 to d6c16d6 Compare November 9, 2021 06:25
@bfredl
Copy link
Member

bfredl commented Dec 25, 2021

@tjdevries What you think about getting this merged for 0.7? I remember you said you "hated" some things in the present implementation, but does those affect observable behavior? I'd say as long as the behavior is reasonable (including error handling and such), we can get this merged early in the 0.7 cycle, and re-iterate on the implementation, including possible small changes of behavior if needed.

@clason
Copy link
Member

clason commented Jan 10, 2022

Just noting this down here for the sake of completeness: Does this PR cover User autocommands and doautocmd? Would be nice (in a future PR) to have an API for that, which ideally adds support for custom event structures.

@tjdevries
Copy link
Contributor Author

@bfredl let me spend some time this week and next on it, and then ask for your review. If you like it and feel OK w/ the hack that I have in there, I feel confident it could work pretty well.

@bfredl
Copy link
Member

bfredl commented Feb 9, 2022

@tjdevries I rebased to resolve some surface level conflicts.

@clason clason added this to the 0.7 milestone Feb 18, 2022
@tjdevries tjdevries force-pushed the tjdevries/lua_autocmd_v2 branch 4 times, most recently from 5049b03 to f5e3c77 Compare February 19, 2022 04:09
src/nvim/eval/typval.c Outdated Show resolved Hide resolved
@bfredl bfredl force-pushed the tjdevries/lua_autocmd_v2 branch 2 times, most recently from ce505cc to e95e862 Compare February 27, 2022 20:50
@bfredl bfredl merged commit fad33b0 into neovim:master Feb 27, 2022
Lua API automation moved this from In progress to Done Feb 27, 2022
@fsouza

This comment was marked as resolved.

@Maverun

This comment was marked as resolved.

@kevinhwang91
Copy link
Contributor

IMO, command field in nvim_create_autocmd should be deleted, callback should be the last position argument, which can easy to convert to await.

@mvllow
Copy link

mvllow commented Feb 28, 2022

Would it make sense to merge command and callback? Perhaps command could accept a string or lua function?

@clason
Copy link
Member

clason commented Feb 28, 2022

No, it would not make sense -- these have to be different for technical reasons (same as for the nvim_set_keymap() API). If people want the extra convenience, they can create a Lua API on top of it (similarly as with vim.keymap.set). At the moment, the goal is to make sure that the underlying low-level API is sound and bug-free; convenience comes after that.

Also, drive-by bikeshedding after a PR is merged is a) poor form and b) not going to lead to very much due to the lack of visibility.

@hkupty
Copy link

hkupty commented Feb 28, 2022

Not sure if this is the intended behavior, but for an autocmd where I set a description, it is duplicated in the command, which together with not having the event key in this response, makes it hard to figure to which event that autocommand is bound to:
image
image

Note that this was match only by group, which in this case does make sense not to show up in the response, but if I search only for TabLeave event, I can never figure out for which plugin/group that autocmd maps to:
image
image

@lewis6991
Copy link
Member

Please don't comment on this PR with user specific issues or questions. Either raise an issue or reach out on matrix.

Thanks

@neovim neovim locked as resolved and limited conversation to collaborators Feb 28, 2022
@tjdevries
Copy link
Contributor Author

Note, for anyone who was using this immediately after merge, there was a problem with our merge into master, which was resolved in this PR:

#17551

Note, that there are changes to the API functions here, so you will need to change how you were calling the API

@zeertzjq zeertzjq modified the milestones: 0.8, 0.7 Mar 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api libnvim, Nvim RPC API events events, autocommands lua stdlib
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet