Reply to messages with 'r' binding in cursor mode

This commit is contained in:
Tom Smeding 2020-07-02 17:48:14 +02:00
parent de1d3d4664
commit fab8bb37bf
3 changed files with 62 additions and 2 deletions

View file

@ -241,6 +241,27 @@ settings:
1. `matrix.network.read_markers_conditions`
1. `matrix.network.typing_notice_conditions`
## Cursor bindings
While you can reply on a matrix message using the `/reply-matrix` command (see
its help in weechat), weechat-matrix also adds a binding in `/cursor` mode to
easily reply to a particular message. This mode can be triggered either by
running `/cursor`, or by middle-clicking somewhere on the screen. See weechat's
help for `/cursor`.
The default binding is:
/key bindctxt cursor @chat(python.matrix.*):r hsignal:matrix_cursor_reply
This means that you can reply to a message in a Matrix buffer using the middle
mouse button, then `r`.
This binding is automatically set when the script is loaded and there is no
such binding yet. If you want to use a different key than `r`, you can execute
the above command with a different key in place of `r`. To use modifier keys
like control and alt, use alt-k, then your wanted binding key combo, to enter
weechat's representation of that key combo in the input bar.
## Navigating room buffers using go.py
If you try to use the `go.py` script to navigate buffers created by

View file

@ -65,7 +65,7 @@ from matrix.bar_items import (
from matrix.buffer import room_buffer_close_cb, room_buffer_input_cb
# Weechat searches for the registered callbacks in the scope of the main script
# file, import the callbacks here so weechat can find them.
from matrix.commands import (hook_commands, hook_page_up,
from matrix.commands import (hook_commands, hook_key_bindings, hook_page_up,
matrix_command_buf_clear_cb, matrix_command_cb,
matrix_command_pgup_cb, matrix_invite_command_cb,
matrix_join_command_cb, matrix_kick_command_cb,
@ -74,7 +74,8 @@ from matrix.commands import (hook_commands, hook_page_up,
matrix_olm_command_cb, matrix_devices_command_cb,
matrix_room_command_cb, matrix_uploads_command_cb,
matrix_upload_command_cb, matrix_send_anyways_cb,
matrix_reply_command_cb)
matrix_reply_command_cb,
matrix_cursor_reply_signal_cb)
from matrix.completion import (init_completion, matrix_command_completion_cb,
matrix_debug_completion_cb,
matrix_message_completion_cb,
@ -695,6 +696,7 @@ if __name__ == "__main__":
G.CONFIG.read()
hook_commands()
hook_key_bindings()
init_bar_items()
init_completion()

View file

@ -544,6 +544,15 @@ def hook_commands():
hook_page_up()
def hook_key_bindings():
W.hook_hsignal("matrix_cursor_reply", "matrix_cursor_reply_signal_cb", "")
binding = "@chat(python.{}*):r".format(G.BUFFER_NAME_PREFIX)
W.key_bind("cursor", {
binding: "hsignal:matrix_cursor_reply",
})
def format_device(device_id, fp_key, display_name):
fp_key = partition_key(fp_key)
message = (" - Device ID: {device_color}{device_id}{ncolor}\n"
@ -1930,3 +1939,31 @@ def matrix_send_anyways_cb(data, buffer, args):
W.prnt("", message)
return W.WEECHAT_RC_ERROR
@utf8_decode
def matrix_cursor_reply_signal_cb(data, signal, ht):
tags = ht["_chat_line_tags"].split(",")
W.command("", "/cursor stop")
if "matrix_message" in tags:
for tag in tags:
if tag.startswith("matrix_id_"):
matrix_id = tag[10:]
break
else:
return W.WEECHAT_RC_OK
buffer_name = ht["_buffer_full_name"]
bufptr = W.buffer_search("==", buffer_name)
current_input = W.buffer_get_string(bufptr, "input")
input_pos = W.buffer_get_integer(bufptr, "input_pos")
new_prefix = "/reply-matrix {} ".format(matrix_id)
W.buffer_set(bufptr, "input", new_prefix + current_input)
W.buffer_set(bufptr, "input_pos", str(len(new_prefix) + input_pos))
return W.WEECHAT_RC_OK