Skip to content

Instantly share code, notes, and snippets.

@gilbertw1
Created March 23, 2016 16:25
Show Gist options
  • Select an option

  • Save gilbertw1/d28a7f33e2a7e325d91e to your computer and use it in GitHub Desktop.

Select an option

Save gilbertw1/d28a7f33e2a7e325d91e to your computer and use it in GitHub Desktop.
enhanced go.py with muliple input matching support
def go_matching_buffers(strinput):
"""Return a list with buffers matching user input."""
global buffers_pos
listbuf = []
if len(strinput) == 0:
buffers_pos = 0
strinput = strinput.lower()
infolist = weechat.infolist_get('buffer', '', '')
while weechat.infolist_next(infolist):
short_name = weechat.infolist_string(infolist, 'short_name')
if go_option_enabled('short_name'):
name = weechat.infolist_string(infolist, 'short_name')
else:
name = weechat.infolist_string(infolist, 'name')
if name == 'weechat' \
and go_option_enabled('use_core_instead_weechat') \
and weechat.infolist_string(infolist, 'plugin_name') == 'core':
name = 'core'
number = weechat.infolist_integer(infolist, 'number')
full_name = weechat.infolist_string(infolist, 'full_name')
if not full_name:
full_name = '%s.%s' % (
weechat.infolist_string(infolist, 'plugin_name'),
weechat.infolist_string(infolist, 'name'))
pointer = weechat.infolist_pointer(infolist, 'pointer')
matchers = strinput.split()
matches = []
matching = True
for i in range(len(matchers)):
matches.append(name.lower().find(matchers[i]))
if matches[i] < 0 or (i > 0 and matches[i] < matches[i-1]):
matching = False
break
if not matching and strinput[-1] == ' ':
matching = name.lower().endswith(strinput.strip())
if not matching and strinput.isdigit():
matching = str(number).startswith(strinput)
if len(strinput) == 0 or matching:
listbuf.append({
'number': number,
'short_name': short_name,
'name': name,
'full_name': full_name,
'pointer': pointer,
})
weechat.infolist_free(infolist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment