[vim/vim] feat: support winid as argument for foldclosed*() (PR #21133)

9 views
Skip to first unread message

Mao-Yining

unread,
Aug 23, 2026, 2:33:46 AM (6 days ago) Aug 23
to vim/vim, Subscribed

fixes: #21130


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

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

Commit Summary

  • 863fbdf feat: support winid as argument for foldclosed*()

File Changes

(4 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21133@github.com>

Christian Brabandt

unread,
Aug 23, 2026, 1:57:40 PM (5 days ago) Aug 23
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#21133)

Thanks. I think this is reasonable. But please note, that using tv_get_lnum resolves '.' and '$' in the context of the current buffer which may return unexpected results. Have a look at how f_line() handles this.

There are a few other functions, that could be handled that way, e.g. foldlevel(), foldtextresult().

Please also add tests for v9 type checking, similar to what Test_line() does in test_vim9_builtin.vim.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

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

Mao-Yining

unread,
Aug 23, 2026, 11:21:12 PM (5 days ago) Aug 23
to vim/vim, Subscribed
mao-yining left a comment (vim/vim#21133)

x

Thanks. All Done.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

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

h_east

unread,
Aug 24, 2026, 6:20:05 AM (4 days ago) Aug 24
to vim/vim, Subscribed
h-east left a comment (vim/vim#21133)

Two things go wrong here regardless of the interface question.

In foldclosed_both(), restore_win() runs even when switch_win() was
never reached: with an unknown window id wp is NULL, the && chain stops
before switch_win(), and switchwin is uninitialized. restore_win() also
calls unblock_autocmds() with nothing to match it, and --autocmd_blocked
has no lower bound (autocmd.c:2640), so after one foldclosed(1, 99999) the
next block_autocmds() stops blocking anything.

In f_foldtextresult(), the if (wp == NULL || tp == NULL) return; comes
after entered = TRUE and nothing puts it back, so one call with an unknown
window id leaves foldtextresult() returning an empty string for the rest of
the session.

Both point at the same open question: what should an unknown window id do?
foldclosed() returning -1 and foldlevel() returning 0 are answers a valid
window gives too, so a script cannot tell them apart. An error would be
better, and the documentation should say which it is.

foldclosed_both() hands the window to hasFoldingWin(), while foldlevel()
and foldtextresult() switch to it, which is heavier and blocks autocommands
while it lasts. Is there a reason not to pass the window down in all three?

Moving foldLevel() elsewhere in the file, reindenting the parameter list of
foldclosed_both(), and the blank line in the new else block are unrelated
to the feature and make the diff harder to read.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

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

Mao-Yining

unread,
Aug 24, 2026, 7:06:27 AM (4 days ago) Aug 24
to vim/vim, Subscribed
mao-yining left a comment (vim/vim#21133)

Two things go wrong here regardless of the interface question.

In foldclosed_both(), restore_win() runs even when switch_win() was never reached: with an unknown window id wp is NULL, the && chain stops before switch_win(), and switchwin is uninitialized. restore_win() also calls unblock_autocmds() with nothing to match it, and --autocmd_blocked has no lower bound (autocmd.c:2640), so after one foldclosed(1, 99999) the next block_autocmds() stops blocking anything.

In f_foldtextresult(), the if (wp == NULL || tp == NULL) return; comes after entered = TRUE and nothing puts it back, so one call with an unknown window id leaves foldtextresult() returning an empty string for the rest of the session.

Both point at the same open question: what should an unknown window id do? foldclosed() returning -1 and foldlevel() returning 0 are answers a valid window gives too, so a script cannot tell them apart. An error would be better, and the documentation should say which it is.

foldclosed_both() hands the window to hasFoldingWin(), while foldlevel() and foldtextresult() switch to it, which is heavier and blocks autocommands while it lasts. Is there a reason not to pass the window down in all three?

Moving foldLevel() elsewhere in the file, reindenting the parameter list of foldclosed_both(), and the blank line in the new else block are unrelated to the feature and make the diff harder to read.

Thank you for your reply. The motivation for this issue came from developing redraw_listener — if there is an inadvertent error, it throws an error on every redraw, which is very difficult to deal with. What are your thoughts on this situation?


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

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

Christian Brabandt

unread,
Aug 25, 2026, 4:02:56 PM (3 days ago) Aug 25
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#21133)

thanks


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

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

Reply all
Reply to author
Forward
0 new messages