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

refactor: implement augroups as namespaces #28441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

altermo
Copy link
Contributor

@altermo altermo commented Apr 21, 2024

From #28436 (comment):

The proposed change is to remove the separation, i.e. augroups are now implemented as namespaces instead of their own special, separate address space.

Implementation details:

Deleting augroups:
Background:
Deleting named namespaces is not allowed, while there are 2 ways of deleting augroups (normal and legacy). Legacy deleted augroups change their id to augroup_deleted but do not change their name, which also is not allowed for named namespaces. augroups with the id augroup_deleted or which don't have a name are considered deleted, have the name "--Deleted--" and error when trying to access them (most of the time). There are some other important differences which will be noted later.
Implementation:
When an augroup gets deleted, its id is appended to the set deleted_augroup_map. Any augroup in the deleted_augroup_map or doesn't have an associated name (e.g. an anonymous namespace) is considered deleted. When legacy deleting augroups the same steps happen as with normal deletion but all the autocmds associated with the augroup change their group to the id returned by get_deleted_augroup_id(). This is the special deleted augroup and has the name "--Deleted--" and there is only one of these (This is a BREAKING-CHANGE, see Example 1).

Creating augroups:
Implementation:
Creating augroups will use nvim_create_namespace() to create augroups (This is a BREAKING-CHANGE as augroups now can't have the name ""(empty string)). If the returned id is in deleted_augroup_map then it will be removed from there.

Listing augroups:
Background:
There are two (or more) ways of listing augroups: using :augroup (which I will refer to as normal listing) and using getcompletion('','augroup') (which I will refer to as completion listing). Whether a deleted augroup gets listed depends on what listing method you use (normal or completion) and whether the augroup was normal or legacy deleted. Completion listing lists all augroups, including normal deleted ones (all deleted/legacy deleted augroups have the name "--Deleted--"). Normal listing will only list legacy deleted augroups.
Implementation:
Listing augroups will also list all other named namespaces, as there is no difference between named namespaces and augroups (This might break some plugin tests). Normal deleted augroups will never be listed (not even in completion listings) and there will only be one "--Deleted--" listed after any number of augroups get legacy deleted (these are BREAKING-CHANGEs).

Other:
The first-ever namespaces created with nvim_create_namespace() after initializing the runtime files will now not be 1 as the runtime files create some augroups on initialization (This might break some plugin tests).

Examples (click to expand):
Example 1
local group=vim.api.nvim_create_augroup('test',{})
vim.api.nvim_create_autocmd('FileType',{group=group,command='',pattern='foo'})
vim.cmd'augroup! test'
assert(vim.api.nvim_get_autocmds({pattern='foo'})[1].group==group)

src/nvim/autocmd.c Outdated Show resolved Hide resolved
@github-actions github-actions bot added the refactor changes that are not features or bugfixes label Apr 21, 2024
@altermo altermo force-pushed the refactor-replace-augroup-with-namespace branch from fcae9f9 to bf397ab Compare April 21, 2024 14:57
src/nvim/autocmd.c Outdated Show resolved Hide resolved
@altermo altermo force-pushed the refactor-replace-augroup-with-namespace branch 6 times, most recently from fb3520e to 184ee78 Compare April 22, 2024 07:59
@clason clason added this to the 0.11 milestone Apr 22, 2024
@clason clason added the complexity:high High-risk, potential for delicate/cascading effects label Apr 22, 2024
@altermo altermo force-pushed the refactor-replace-augroup-with-namespace branch 5 times, most recently from d48516d to 9de9563 Compare April 22, 2024 14:40
@altermo altermo marked this pull request as ready for review April 22, 2024 15:00
@zeertzjq zeertzjq added the events events, autocommands label Apr 23, 2024
@altermo altermo force-pushed the refactor-replace-augroup-with-namespace branch 6 times, most recently from 6ce4ed8 to 54770f4 Compare April 23, 2024 11:30
@altermo altermo force-pushed the refactor-replace-augroup-with-namespace branch from 54770f4 to 9f9e7e8 Compare April 23, 2024 11:41
@justinmk
Copy link
Member

Let's revisit this soon after releasing 0.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity:high High-risk, potential for delicate/cascading effects events events, autocommands refactor changes that are not features or bugfixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants