From 1ad45598b5db3b639047f69d3e95ce84a59db100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 20 May 2023 16:26:20 +0200 Subject: fset: create buffer with function buffer_new_props (issue #1942) With this function, buffer properties are set when the buffer is created and can be read immediately by other plugins/scripts, for example in a callback of signal "buffer_opened". --- src/plugins/fset/fset-buffer.c | 43 ++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/fset/fset-buffer.c b/src/plugins/fset/fset-buffer.c index edeb7912d..ff8a32688 100644 --- a/src/plugins/fset/fset-buffer.c +++ b/src/plugins/fset/fset-buffer.c @@ -1546,24 +1546,39 @@ fset_buffer_set_localvar_filter () void fset_buffer_open () { - if (!fset_buffer) + struct t_hashtable *buffer_props; + + if (fset_buffer) + return; + + buffer_props = weechat_hashtable_new ( + 32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER, + NULL, + NULL); + if (buffer_props) { - fset_buffer = weechat_buffer_new ( - FSET_BUFFER_NAME, - &fset_buffer_input_cb, NULL, NULL, - &fset_buffer_close_cb, NULL, NULL); + weechat_hashtable_set (buffer_props, "type", "free"); + weechat_hashtable_set (buffer_props, "localvar_set_type", "option"); + } - /* failed to create buffer ? then exit */ - if (!fset_buffer) - return; + fset_buffer = weechat_buffer_new_props ( + FSET_BUFFER_NAME, + buffer_props, + &fset_buffer_input_cb, NULL, NULL, + &fset_buffer_close_cb, NULL, NULL); - weechat_buffer_set (fset_buffer, "type", "free"); - fset_buffer_set_keys (); - weechat_buffer_set (fset_buffer, "localvar_set_type", "option"); - fset_buffer_set_localvar_filter (); + if (buffer_props) + weechat_hashtable_free (buffer_props); - fset_buffer_selected_line = 0; - } + if (!fset_buffer) + return; + + fset_buffer_set_keys (); + fset_buffer_set_localvar_filter (); + + fset_buffer_selected_line = 0; } /* -- cgit v1.2.3