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

Add support for #elifdef and #elifndef to c.vim #13667

Closed
jwakely opened this issue Dec 11, 2023 · 5 comments · Fixed by chrisbra/matchit#41 · May be fixed by #13679
Closed

Add support for #elifdef and #elifndef to c.vim #13667

jwakely opened this issue Dec 11, 2023 · 5 comments · Fixed by chrisbra/matchit#41 · May be fixed by #13679

Comments

@jwakely
Copy link

jwakely commented Dec 11, 2023

The new C2x and C++23 standards add new preprocessing conditionals, #elifdef and #elifndef

For C the proposal was:
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2645.pdf

For C++ the proposal was:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2334r1.pdf

They've been supported by GCC for a couple of years:
https://gcc.gnu.org/gcc-12/changes.html#c

Vim does not recognize these and so doesn't syntax highlight them.

#ifdef foo
#elifdef bar
#elifndef baz
#endif
@chrisbra
Copy link
Member

can you create a PR to runtime/syntax/c.vim ?

jwakely added a commit to jwakely/vim that referenced this issue Dec 13, 2023
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

Done, but see my comment on #13679 about whether the PR is complete or not.

@cpplearner
Copy link

The matchit plugin also needs to recognize #elifdef and #elifndef.

let default = escape(&mps, '[$^.*~\\/?]') .. (strlen(&mps) ? "," : "") ..
\ '\/\*:\*\/,#\s*if\%(n\=def\)\=:#\s*else\>:#\s*elif\>:#\s*endif\>'

The built-in [#, ]# and % do not need any change, even though they deal with #if/#else/#endif, because they only look for el and do not care about subsequent characters.

@dkearns
Copy link
Contributor

dkearns commented Jan 12, 2024

I'll add it to #12984, thanks.

dkearns added a commit to dkearns/vim that referenced this issue Jan 12, 2024
Conditionally highlight C23 features:

- #embed, #elifdef and #elifndef preprocessor directives
- predefined macros
- UTF-8 character constants
- binary integer constants, _BitInt literals, and digit separators
- nullptr_t type and associated constant
- decimal real floating-point, bit precise and char types
- typeof operators

Matchit:
- update for new preprocessor directives

Fixes vim#13667.
@jwakely
Copy link
Author

jwakely commented Jan 13, 2024

Marvellous, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants