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

Support #elifdef and #elifndef in c.vim #13679

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

Conversation

jwakely
Copy link

@jwakely jwakely commented Dec 13, 2023

C2x and C++23 add these new preprocessor conditionals, as shorter forms of #elif defined and #elif !defined.

Fixes #13667

C2x and C++23 add these new preprocessor conditionals, as shorter forms
of #elif defined and #elif !defined.

Fixes vim#13667
@jwakely
Copy link
Author

jwakely commented Dec 13, 2023

This is the minimal change to make vim recognize them, so that syntax highlighting works, and you can jump between them using %. I have no idea if I should have also changed cCppOutIf2, cCppInElse, etc. because I don't know what they're used for.

@jwakely
Copy link
Author

jwakely commented Dec 13, 2023

Another way to define that regex would be:

start="^\s*\zs\%(%:\|#\)\s*\%(\(el\)\?\(if\|ifdef\|ifndef\)\)\>"

Since each of if, ifdef, and ifndef now has an "elif" form, we can just give them all an optional el prefix.

@dkearns
Copy link
Contributor

dkearns commented Dec 13, 2023

We were waiting for C23 to be released before including those changes. As these directives are already supported by GCC I think they should be conditionally included if the "c_gnu" flag is set.

cCpp{In,Out}* syntax groups are used to highlight 'disabled' code as comments. So these changes should, ideally, be applied there as well. See :help c_no_if0

@jwakely
Copy link
Author

jwakely commented Dec 13, 2023

I don't think waiting makes sense. Both C2x and C++23 have been approved and are just awaiting publication now. The content is final, and these new preprocessor tokens have 0% chance of being removed.

And it's not a GCC extension. GCC, Clang and Intel icx all support it in their latest production releases:
https://godbolt.org/z/Y4zoaE1Ed
Only MSVC doesn't yet:
https://en.cppreference.com/w/cpp/compiler_support#cpp23

@jwakely
Copy link
Author

jwakely commented Dec 13, 2023

cCpp{In,Out}* syntax groups are used to highlight 'disabled' code as comments. So these changes should, ideally, be applied there as well. See :help c_no_if0

OK, I'll try to do that too ...

@dkearns
Copy link
Contributor

dkearns commented Dec 14, 2023

I don't think waiting makes sense. Both C2x and C++23 have been approved and are just awaiting publication now. The content is final, and these new preprocessor tokens have 0% chance of being removed.

OK, if it's locked down I guess there's no reason not to add it now. There's a few other C23 related changes queued as PRs and similar that I'll try and round up soon.

I gather you noticed there's a series of version flags and we'll need a new one, c_no_c23?

@chrisbra
Copy link
Member

please ping me, once this is ready.

@chrisbra chrisbra added the needs more work used for a pull request that isn't ready to include (other than needing a test) label Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs feedback needs more work used for a pull request that isn't ready to include (other than needing a test) runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for #elifdef and #elifndef to c.vim
4 participants