From 75b2b85626a94bed3d5b1db928c52ee4c83ea26a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 7 Mar 2019 10:01:20 +0100 Subject: [PATCH] completion: Add a room name completion. This is meant to be used as another default_template for the global weechat completion. --- main.py | 3 ++- matrix/completion.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 61e5c84..93a04df 100644 --- a/main.py +++ b/main.py @@ -63,7 +63,8 @@ from matrix.completion import (init_completion, matrix_command_completion_cb, matrix_server_command_completion_cb, matrix_server_completion_cb, matrix_user_completion_cb, - matrix_own_devices_completion_cb) + matrix_own_devices_completion_cb, + matrix_room_completion_cb) from matrix.config import (MatrixConfig, config_log_category_cb, config_log_level_cb, config_server_buffer_cb, matrix_config_reload_cb, config_pgup_cb) diff --git a/matrix/completion.py b/matrix/completion.py index 2c05b42..1a08b05 100644 --- a/matrix/completion.py +++ b/matrix/completion.py @@ -280,6 +280,20 @@ def matrix_user_completion_cb(data, completion_item, buffer, completion): return W.WEECHAT_RC_OK +@utf8_decode +def matrix_room_completion_cb(data, completion_item, buffer, completion): + """Completion callback for matrix room names.""" + for server in SERVERS.values(): + for room_buffer in server.room_buffers.values(): + name = room_buffer.weechat_buffer.short_name + + W.hook_completion_list_add( + completion, name, 0, W.WEECHAT_LIST_POS_SORT + ) + + return W.WEECHAT_RC_OK + + def init_completion(): W.hook_completion( "matrix_server_commands", @@ -343,3 +357,10 @@ def init_completion(): "matrix_own_devices_completion_cb", "", ) + + W.hook_completion( + "matrix_rooms", + "Matrix room name completion", + "matrix_room_completion_cb", + "", + )