X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/b2532fa3cad2f790b1e72df330c15723047c79a3..refs/heads/master:/weechat/python/go.py?ds=sidebyside diff --git a/weechat/python/go.py b/weechat/python/go.py index 2ab47ed..c4f7f8e 100644 --- a/weechat/python/go.py +++ b/weechat/python/go.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2009-2014 Sébastien Helleu +# Copyright (C) 2009-2023 Sébastien Helleu # Copyright (C) 2010 m4v # Copyright (C) 2011 stfn # @@ -21,6 +21,17 @@ # # History: # +# 2024-05-30, Sébastien Helleu : +# version 3.0.1: refresh buffer input at the end of search +# 2024-05-30, Sébastien Helleu : +# version 3.0: refresh immediately buffer input when /go command is executed +# (needed for WeeChat >= 4.3.0) +# 2023-06-21, Sébastien Helleu : +# version 2.9: add option "min_chars" +# 2023-01-08, Sébastien Helleu : +# version 2.8: send buffer pointer with signal "input_text_changed" +# 2021-05-25, Tomáš Janoušek : +# version 2.7: add new option to prefix short names with server names # 2019-07-11, Simmo Saan # version 2.6: fix detection of "/input search_text_here" # 2017-04-01, Sébastien Helleu : @@ -94,7 +105,7 @@ from __future__ import print_function SCRIPT_NAME = 'go' SCRIPT_AUTHOR = 'Sébastien Helleu ' -SCRIPT_VERSION = '2.6' +SCRIPT_VERSION = '3.0.1' SCRIPT_LICENSE = 'GPL3' SCRIPT_DESC = 'Quick jump to buffers' @@ -106,13 +117,19 @@ try: import weechat except ImportError: print('This script must be run under WeeChat.') - print('Get WeeChat now at: http://www.weechat.org/') + print('Get WeeChat now at: https://weechat.org/') IMPORT_OK = False import re # script options SETTINGS = { + 'auto_jump': ( + 'off', + 'automatically jump to buffer when it is uniquely selected'), + 'buffer_number': ( + 'on', + 'display buffer number'), 'color_number': ( 'yellow,magenta', 'color for buffer number (not selected)'), @@ -131,12 +148,21 @@ SETTINGS = { 'color_name_highlight_selected': ( 'red,brown', 'color for highlight in a selected buffer name'), + 'fuzzy_search': ( + 'off', + 'search buffer matches using approximation'), 'message': ( 'Go to: ', 'message to display before list of buffers'), + 'min_chars': ( + '0', + 'Minimum chars to search and display list of matching buffers'), 'short_name': ( 'off', 'display and search in short names instead of buffer name'), + 'short_name_server': ( + 'off', + 'prefix short names with server names for search and display'), 'sort': ( 'number,beginning', 'comma-separated list of keys to sort buffers ' @@ -149,15 +175,6 @@ SETTINGS = { 'use_core_instead_weechat': ( 'off', 'use name "core" instead of "weechat" for core buffer'), - 'auto_jump': ( - 'off', - 'automatically jump to buffer when it is uniquely selected'), - 'fuzzy_search': ( - 'off', - 'search buffer matches using approximation'), - 'buffer_number': ( - 'on', - 'display buffer number'), } # hooks management @@ -203,6 +220,7 @@ def go_unhook_all(): go_unhook_one('modifier') for hook in HOOK_COMMAND_RUN: go_unhook_one(hook) + weechat.bar_item_update('input_text') def go_hook_all(): @@ -222,6 +240,7 @@ def go_hook_all(): if 'modifier' not in hooks: hooks['modifier'] = weechat.hook_modifier( 'input_text_display_with_cursor', 'go_input_modifier', '') + weechat.bar_item_update('input_text') def go_start(buf): @@ -317,9 +336,14 @@ def go_matching_buffers(strinput): strinput = strinput.lower() infolist = weechat.infolist_get('buffer', '', '') while weechat.infolist_next(infolist): + pointer = weechat.infolist_pointer(infolist, 'pointer') short_name = weechat.infolist_string(infolist, 'short_name') + server = weechat.buffer_get_string(pointer, 'localvar_server') if go_option_enabled('short_name'): - name = weechat.infolist_string(infolist, 'short_name') + if go_option_enabled('short_name_server') and server: + name = server + '.' + short_name + else: + name = short_name else: name = weechat.infolist_string(infolist, 'name') if name == 'weechat' \ @@ -332,7 +356,6 @@ def go_matching_buffers(strinput): full_name = '%s.%s' % ( weechat.infolist_string(infolist, 'plugin_name'), weechat.infolist_string(infolist, 'name')) - pointer = weechat.infolist_pointer(infolist, 'pointer') matching = name.lower().find(strinput) >= 0 if not matching and strinput[-1] == ' ': matching = name.lower().endswith(strinput.strip()) @@ -401,6 +424,11 @@ def go_matching_buffers(strinput): def go_buffers_to_string(listbuf, pos, strinput): """Return string built with list of buffers found (matching user input).""" + try: + if len(strinput) < int(weechat.config_get_plugin('min_chars')): + return '' + except: + pass string = '' strinput = strinput.lower() for i in range(len(listbuf)): @@ -491,7 +519,7 @@ def go_command_run_input(data, buf, command): if buffers_pos >= len(buffers): buffers_pos = 0 weechat.hook_signal_send('input_text_changed', - weechat.WEECHAT_HOOK_SIGNAL_STRING, '') + weechat.WEECHAT_HOOK_SIGNAL_POINTER, buf) return weechat.WEECHAT_RC_OK_EAT elif command == '/input complete_previous': # choose previous buffer in list @@ -499,7 +527,7 @@ def go_command_run_input(data, buf, command): if buffers_pos < 0: buffers_pos = len(buffers) - 1 weechat.hook_signal_send('input_text_changed', - weechat.WEECHAT_HOOK_SIGNAL_STRING, '') + weechat.WEECHAT_HOOK_SIGNAL_POINTER, buf) return weechat.WEECHAT_RC_OK_EAT elif command == '/input return': # switch to selected buffer (if any)