refactor: implement augroups as namespaces #28441
Open
+225
−129
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
From #28436 (comment):
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 idaugroup_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 thedeleted_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 byget_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 indeleted_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 usinggetcompletion('','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