[vim/vim] Support #elifdef and #elifndef in c.vim (PR #13679)

32 views
Skip to first unread message

Jonathan Wakely

unread,
Dec 13, 2023, 5:20:10 AM12/13/23
to vim/vim, Subscribed

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

Fixes #13667


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/13679

Commit Summary

  • 62fa9dc Support #elifdef and #elifndef in c.vim

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13679@github.com>

Jonathan Wakely

unread,
Dec 13, 2023, 5:22:23 AM12/13/23
to vim/vim, Subscribed

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.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13679/c1853641873@github.com>

Jonathan Wakely

unread,
Dec 13, 2023, 5:26:47 AM12/13/23
to vim/vim, Subscribed

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.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13679/c1853648531@github.com>

dkearns

unread,
Dec 13, 2023, 10:35:38 AM12/13/23
to vim/vim, Subscribed

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


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13679/c1854156562@github.com>

Jonathan Wakely

unread,
Dec 13, 2023, 1:40:48 PM12/13/23
to vim/vim, Subscribed

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


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13679/c1854514329@github.com>

Jonathan Wakely

unread,
Dec 13, 2023, 1:41:17 PM12/13/23
to vim/vim, Subscribed

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 ...


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13679/c1854515250@github.com>

dkearns

unread,
Dec 13, 2023, 10:35:19 PM12/13/23
to vim/vim, Subscribed

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?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13679/c1855073140@github.com>

Christian Brabandt

unread,
Dec 16, 2023, 8:20:27 AM12/16/23
to vim/vim, Subscribed

please ping me, once this is ready.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13679/c1858817189@github.com>

Christian Brabandt

unread,
Nov 11, 2024, 3:45:51 PM11/11/24
to vim/vim, Subscribed

Closed #13679.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13679/issue_event/15255304988@github.com>

Christian Brabandt

unread,
Nov 11, 2024, 3:45:51 PM11/11/24
to vim/vim, Subscribed

this seems to have stalled, so let me close it for now. Please create a new PR once you have a new version ready.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13679/c2468991796@github.com>

Jonathan Wakely

unread,
Nov 12, 2024, 4:13:55 AM11/12/24
to vim/vim, Subscribed

I didn't figure out how to make the requested changes, sorry.

N.B. both C23 and C++23 have now been published and the previous standards withdrawn. So #elifdef and #elifndef are in the current ISO standards.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13679/c2469981461@github.com>

dkearns

unread,
Nov 12, 2024, 4:30:57 AM11/12/24
to vim/vim, Subscribed

I think it's fixed in #12984. I'll finish that in the next couple of days.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13679/c2470027507@github.com>

Reply all
Reply to author
Forward
0 new messages