diff options
Diffstat (limited to 'weechat/python')
-rw-r--r-- | weechat/python/colorize_nicks.py | 7 | ||||
-rw-r--r-- | weechat/python/go.py | 69 |
2 files changed, 69 insertions, 7 deletions
diff --git a/weechat/python/colorize_nicks.py b/weechat/python/colorize_nicks.py index 506a3ab..1460f01 100644 --- a/weechat/python/colorize_nicks.py +++ b/weechat/python/colorize_nicks.py @@ -21,6 +21,8 @@ # # # History: +# 2017-03-01, arza <arza@arza.us> +# version 23: don't colorize nicklist group names # 2016-05-01, Simmo Saan <simmo.saan@gmail.com> # version 22: invalidate cached colors on hash algorithm change # 2015-07-28, xt @@ -77,7 +79,7 @@ w = weechat SCRIPT_NAME = "colorize_nicks" SCRIPT_AUTHOR = "xt <xt@bash.no>" -SCRIPT_VERSION = "22" +SCRIPT_VERSION = "23" SCRIPT_LICENSE = "GPL" SCRIPT_DESC = "Use the weechat nick colors in the chat area" @@ -276,6 +278,9 @@ def populate_nicks(*args): if buffer_ptr not in colored_nicks: colored_nicks[buffer_ptr] = {} + if w.infolist_string(nicklist, 'type') != 'nick': + continue + nick = w.infolist_string(nicklist, 'name') nick_color = colorize_nick_color(nick, my_nick) diff --git a/weechat/python/go.py b/weechat/python/go.py index 476b824..3d1828b 100644 --- a/weechat/python/go.py +++ b/weechat/python/go.py @@ -21,6 +21,12 @@ # # History: # +# 2017-03-02, Sébastien Helleu <flashcode@flashtux.org>: +# version 2.4: fix syntax and indentation error +# 2017-02-25, Simmo Saan <simmo.saan@gmail.com> +# version 2.3: fix fuzzy search breaking buffer number search display +# 2016-01-28, ylambda <ylambda@koalabeast.com> +# version 2.2: add option fuzzy_search # 2015-11-12, nils_2 <weechatter@arcor.de> # version 2.1: fix problem with buffer short_name "weechat", using option # "use_core_instead_weechat", see: @@ -84,7 +90,7 @@ from __future__ import print_function SCRIPT_NAME = 'go' SCRIPT_AUTHOR = 'Sébastien Helleu <flashcode@flashtux.org>' -SCRIPT_VERSION = '2.1' +SCRIPT_VERSION = '2.4' SCRIPT_LICENSE = 'GPL3' SCRIPT_DESC = 'Quick jump to buffers' @@ -142,6 +148,9 @@ SETTINGS = { 'auto_jump': ( 'off', 'automatically jump to buffer when it is uniquely selected'), + 'fuzzy_search': ( + 'off', + 'search buffer matches using approximation'), } # hooks management @@ -239,6 +248,29 @@ def go_match_beginning(buf, string): return False +def go_match_fuzzy(name, string): + """Check if string matches name using approximation.""" + if not string: + return False + + name_len = len(name) + string_len = len(string) + + if string_len > name_len: + return False + if name_len == string_len: + return name == string + + # Attempt to match all chars somewhere in name + prev_index = -1 + for i, char in enumerate(string): + index = name.find(char, prev_index+1) + if index == -1: + return False + prev_index = index + return True + + def go_now(buf, args): """Go to buffer specified by args.""" listbuf = go_matching_buffers(args) @@ -297,6 +329,8 @@ def go_matching_buffers(strinput): matching = name.lower().find(strinput) >= 0 if not matching and strinput[-1] == ' ': matching = name.lower().endswith(strinput.strip()) + if not matching and go_option_enabled('fuzzy_search'): + matching = go_match_fuzzy(name.lower(), strinput) if not matching and strinput.isdigit(): matching = str(number).startswith(strinput) if len(strinput) == 0 or matching: @@ -364,19 +398,42 @@ def go_buffers_to_string(listbuf, pos, strinput): strinput = strinput.lower() for i in range(len(listbuf)): selected = '_selected' if i == pos else '' - index = listbuf[i]['name'].lower().find(strinput) + buffer_name = listbuf[i]['name'] + index = buffer_name.lower().find(strinput) if index >= 0: index2 = index + len(strinput) name = '%s%s%s%s%s' % ( - listbuf[i]['name'][:index], + buffer_name[:index], weechat.color(weechat.config_get_plugin( 'color_name_highlight' + selected)), - listbuf[i]['name'][index:index2], + buffer_name[index:index2], weechat.color(weechat.config_get_plugin( 'color_name' + selected)), - listbuf[i]['name'][index2:]) + buffer_name[index2:]) + elif go_option_enabled("fuzzy_search") and \ + go_match_fuzzy(buffer_name.lower(), strinput): + name = "" + prev_index = -1 + for char in strinput.lower(): + index = buffer_name.lower().find(char, prev_index+1) + if prev_index < 0: + name += buffer_name[:index] + name += weechat.color(weechat.config_get_plugin( + 'color_name_highlight' + selected)) + if prev_index >= 0 and index > prev_index+1: + name += weechat.color(weechat.config_get_plugin( + 'color_name' + selected)) + name += buffer_name[prev_index+1:index] + name += weechat.color(weechat.config_get_plugin( + 'color_name_highlight' + selected)) + name += buffer_name[index] + prev_index = index + + name += weechat.color(weechat.config_get_plugin( + 'color_name' + selected)) + name += buffer_name[prev_index+1:] else: - name = listbuf[i]['name'] + name = buffer_name string += ' %s%s%s%s%s' % ( weechat.color(weechat.config_get_plugin( 'color_number' + selected)), |