[vim/vim] Prevent osc52 plugin "paste" callback being called twice when TextPutPost autocmd is present (PR #20216)

8 views
Skip to first unread message

Foxe Chen

unread,
May 13, 2026, 7:01:32 PM (2 days ago) May 13
to vim/vim, Subscribed

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

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

Commit Summary

  • 9f38c81 prevent osc52 plugin "paste" callback being called twice when TextPutPost is preset

File Changes

(3 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/20216@github.com>

Christian Brabandt

unread,
May 14, 2026, 4:42:50 AM (yesterday) May 14
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#20216)

thanks


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

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

Christian Brabandt

unread,
May 14, 2026, 5:08:15 AM (yesterday) May 14
to vim/vim, Subscribed

@chrisbra commented on this pull request.


In runtime/pack/dist/opt/osc52/autoload/osc52.vim:

>    # Check if user has indicated that the terminal does not support OSC 52 paste
   # (or has disabled it)
   if get(g:, 'osc52_disable_paste', 0)
     return ("c", [])
   endif
 
+  if loop_timerid != -1
+    timer_stop(loop_timerid)
+    loop_timerid = -1
+  endif
+  if !returned_to_loop
+    returned_to_loop = true
+    # This will result in the register being unchanged
+    return null
+  endif

Do we need those 2 ifs? Wouldn't this work as well? (which I think means we do not need the returned_to_loop variable)?

  if loop_timerid != -1
    timer_stop(loop_timerid)
    loop_timerid = -1
    # This will result in the register being unchanged
    return null
  endif

In runtime/pack/dist/opt/osc52/autoload/osc52.vim:

> @@ -61,6 +75,14 @@ export def Paste(reg: string): tuple<string, list<string>>
     endif
   endtry
 
+  # A TextPutPost autocmd may cause this function to be called twice, which is
+  # technically intended behaviour, however it is not necessary for this plugin.
+  # To prevent this, return immediately if we have not returned back to the main
+  # loop since the last "paste" call.
+  loop_timerid = timer_start(0, (_) => {
+    returned_to_loop = true
+  })

This is a bit tricky, because the behaviour relies on the fact that the timer only triggers once Vim is in the main event loop. It confused me a bit, because I was looking for a loop inside the osc52 plugin.
So together with the above change, wouldn't this work?

  loop_timerid = timer_start(0, (_) => {
    loop_timerid = -1
  })

In runtime/pack/dist/opt/osc52/autoload/osc52.vim:

> @@ -61,6 +75,14 @@ export def Paste(reg: string): tuple<string, list<string>>
     endif
   endtry
 
+  # A TextPutPost autocmd may cause this function to be called twice, which is
+  # technically intended behaviour, however it is not necessary for this plugin.
+  # To prevent this, return immediately if we have not returned back to the main
+  # loop since the last "paste" call.
+  loop_timerid = timer_start(0, (_) => {
+    returned_to_loop = true
+  })

Or perhaps of using a timer, we can use the SafeState autocommand? Something like this?

  # Re-entry detected: bail without re-querying the terminal.
  if loop_pending
    loop_pending = false
    return null
  endif
autocmd SafeState * ++once loop_pending = false


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

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

Foxe Chen

unread,
May 14, 2026, 11:10:04 PM (14 hours ago) May 14
to vim/vim, Push

@64-bitman pushed 1 commit.

  • 5f9682c prevent osc52 plugin "paste" callback being called twice when TextPutPost is preset


View it on GitHub or unsubscribe.


Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/20216/before/9f38c81dd9dd7ac9141fdfac22502644d83ee575/after/5f9682cf47149f7ef07d05dbc08fbf4fb74e02d4@github.com>

Christian Brabandt

unread,
5:15 AM (7 hours ago) 5:15 AM
to vim/vim, Subscribed

Closed #20216 via 29fa934.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

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

Reply all
Reply to author
Forward
0 new messages