Re: [vim/vim] Allow listener_add mechanism to provide unbuffered notifications. (PR #18295)

19 views
Skip to first unread message

Paul Ollis

unread,
Sep 14, 2025, 12:42:58 PM (5 days ago) Sep 14
to vim/vim, Push

@paul-ollis pushed 1 commit.

  • 63b0a08 Implement unbuffered listener feature.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18295/before/517b3a592d63052ae8cc8c42c0d16e4ed89b0171/after/63b0a08dd7a2667322dc8d8eb164e4715d3ac9aa@github.com>

Paul Ollis

unread,
Sep 14, 2025, 3:31:38 PM (5 days ago) Sep 14
to vim/vim, Push

@paul-ollis pushed 1 commit.

  • c5143c6 Implement unbuffered listener feature.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18295/before/63b0a08dd7a2667322dc8d8eb164e4715d3ac9aa/after/c5143c62adc1575b8e3efbcd39c260297978233e@github.com>

Paul Ollis

unread,
Sep 14, 2025, 4:12:34 PM (5 days ago) Sep 14
to vim/vim, Push

@paul-ollis pushed 1 commit.

  • 6cdbb29 Implement unbuffered listener feature.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18295/before/c5143c62adc1575b8e3efbcd39c260297978233e/after/6cdbb294122a95c7ab1eafdb8902c7d59fe85deb@github.com>

Paul Ollis

unread,
Sep 15, 2025, 7:43:43 AM (4 days ago) Sep 15
to vim/vim, Push

@paul-ollis pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18295/before/6cdbb294122a95c7ab1eafdb8902c7d59fe85deb/after/71e9d01ff1f68eb0442755d5db078703fd401772@github.com>

Christian Brabandt

unread,
Sep 15, 2025, 3:28:04 PM (4 days ago) Sep 15
to vim/vim, Subscribed

@chrisbra commented on this pull request.


In runtime/doc/builtin.txt:

>  		Add a callback function that will be invoked when changes have
 		been made to buffer {buf}.
 		{buf} refers to a buffer name or number. For the accepted
 		values, see |bufname()|.  When {buf} is omitted the current
 		buffer is used.
 		Returns a unique ID that can be passed to |listener_remove()|.
 
-		The {callback} is invoked with five arguments:
+		If the {buf} already has registered callbacks then the
+		equivalent of >
+		    listener_flush({buf})
+<               is performed before the new callback is added.
+
+		When {unbuffered} is |FALSE| or omitted, the {callback} is
+		invoked with five arguments:

This is a bit strange. Wouldn't it make more sense to have the callback signature always the same? So always call it with the arguments (bufnr, start, end, added and changes), and then just detail that changes is a single change for an unbuffered callback?


In src/testdir/test_listener.vim:

> @@ -375,7 +524,7 @@ endfunc
 func Test_remove_listener_in_callback()
   new
   let s:ID = listener_add('Listener')
-  func Listener(...)
+  func! Listener(...)

I think you can remove the !


In src/change.c:

> + * will be discarded in the event that all listeners were removed.
+ *
+ */
+    static void
+clean_listener_list(buf_T *buf, listener_T **list, bool all)
+{
+    listener_T	*prev;
+    listener_T	*lnr;
+    listener_T	*next;
+
+    prev = NULL;
+    for (lnr = *list; lnr != NULL; lnr = next)
+    {
+	next = lnr->lr_next;
+	if (all || lnr->lr_id == 0)
+	{

style: you can drop braces around single statements


In src/change.c:

> @@ -250,6 +347,10 @@ f_listener_add(typval_T *argvars, typval_T *rettv)
 	    free_callback(&callback);
 	    return;
 	}
+	if (argvars[2].v_type != VAR_UNKNOWN)
+	{

style: you can drop braces around single line statements.


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

Paul Ollis

unread,
Sep 16, 2025, 5:45:05 AM (3 days ago) Sep 16
to vim/vim, Subscribed

@paul-ollis commented on this pull request.


In runtime/doc/builtin.txt:

>  		Add a callback function that will be invoked when changes have
 		been made to buffer {buf}.
 		{buf} refers to a buffer name or number. For the accepted
 		values, see |bufname()|.  When {buf} is omitted the current
 		buffer is used.
 		Returns a unique ID that can be passed to |listener_remove()|.
 
-		The {callback} is invoked with five arguments:
+		If the {buf} already has registered callbacks then the
+		equivalent of >
+		    listener_flush({buf})
+<               is performed before the new callback is added.
+
+		When {unbuffered} is |FALSE| or omitted, the {callback} is
+		invoked with five arguments:

Thanks for reviewing this PR. I will be away from my development PC for a few days, so fixes will be a bit delayed.

I though of doing it that way at first, but changed my mind. There were 2
reasons for my decision:

  1. Providing a single entry list, which added a single extra value not
    already present in the other arguments seemed strange to me.

  2. Performance. I try to avoid premature optimisation, but specifically
    creating a list that would likely be ignored seemed like unnecessary
    CPU load.

I am just providing my reasoning. I am happy to go with your preferred option.


Reply to this email directly, view it on GitHub, or unsubscribe.

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

Paul Ollis

unread,
Sep 16, 2025, 5:48:20 AM (3 days ago) Sep 16
to vim/vim, Subscribed

@paul-ollis commented on this pull request.


In src/testdir/test_listener.vim:

> @@ -375,7 +524,7 @@ endfunc
 func Test_remove_listener_in_callback()
   new
   let s:ID = listener_add('Listener')
-  func Listener(...)
+  func! Listener(...)

I added this because I got an error about the function already existing.

Thinking about it, I should have investigated a bit more as to why. I will do so.


Reply to this email directly, view it on GitHub, or unsubscribe.

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

Paul Ollis

unread,
Sep 16, 2025, 5:49:22 AM (3 days ago) Sep 16
to vim/vim, Subscribed

@paul-ollis commented on this pull request.


In src/change.c:

> + * will be discarded in the event that all listeners were removed.
+ *
+ */
+    static void
+clean_listener_list(buf_T *buf, listener_T **list, bool all)
+{
+    listener_T	*prev;
+    listener_T	*lnr;
+    listener_T	*next;
+
+    prev = NULL;
+    for (lnr = *list; lnr != NULL; lnr = next)
+    {
+	next = lnr->lr_next;
+	if (all || lnr->lr_id == 0)
+	{

Agreed.


Reply to this email directly, view it on GitHub, or unsubscribe.

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

Paul Ollis

unread,
Sep 16, 2025, 5:49:50 AM (3 days ago) Sep 16
to vim/vim, Subscribed

@paul-ollis commented on this pull request.


In src/change.c:

> @@ -250,6 +347,10 @@ f_listener_add(typval_T *argvars, typval_T *rettv)
 	    free_callback(&callback);
 	    return;
 	}
+	if (argvars[2].v_type != VAR_UNKNOWN)
+	{

Agreed.


Reply to this email directly, view it on GitHub, or unsubscribe.

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

Christian Brabandt

unread,
Sep 16, 2025, 3:07:44 PM (3 days ago) Sep 16
to vim/vim, Subscribed

@chrisbra commented on this pull request.


In runtime/doc/builtin.txt:

>  		Add a callback function that will be invoked when changes have
 		been made to buffer {buf}.
 		{buf} refers to a buffer name or number. For the accepted
 		values, see |bufname()|.  When {buf} is omitted the current
 		buffer is used.
 		Returns a unique ID that can be passed to |listener_remove()|.
 
-		The {callback} is invoked with five arguments:
+		If the {buf} already has registered callbacks then the
+		equivalent of >
+		    listener_flush({buf})
+<               is performed before the new callback is added.
+
+		When {unbuffered} is |FALSE| or omitted, the {callback} is
+		invoked with five arguments:

I understand, but I am more concerned with a consistent function interface.
Others opinions? @yegappan @zeertzjq @dkearns ?


Reply to this email directly, view it on GitHub, or unsubscribe.

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

Yegappan Lakshmanan

unread,
Sep 17, 2025, 11:14:39 AM (2 days ago) Sep 17
to vim/vim, Subscribed

@yegappan commented on this pull request.


In runtime/doc/builtin.txt:

>  		Add a callback function that will be invoked when changes have
 		been made to buffer {buf}.
 		{buf} refers to a buffer name or number. For the accepted
 		values, see |bufname()|.  When {buf} is omitted the current
 		buffer is used.
 		Returns a unique ID that can be passed to |listener_remove()|.
 
-		The {callback} is invoked with five arguments:
+		If the {buf} already has registered callbacks then the
+		equivalent of >
+		    listener_flush({buf})
+<               is performed before the new callback is added.
+
+		When {unbuffered} is |FALSE| or omitted, the {callback} is
+		invoked with five arguments:

I agree. The callback function signature should remain consistent between the two cases.


Reply to this email directly, view it on GitHub, or unsubscribe.

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

Reply all
Reply to author
Forward
0 new messages