Esempio n. 1
0
def reorder_buffers():
    """Reorders the buffers once the whitelist has changed
    """

    count = 2
    chan = ""

    ilist = weechat.infolist_get("buffer", "", "")

    for chan in whitelist:
        if -1 == chan.find(".#"): #network name is not set, matching by short_name
            weechat.infolist_reset_item_cursor(ilist)

            while weechat.infolist_next(ilist):
                if weechat.infolist_string(ilist, "short_name") == chan:
                    chan = weechat.infolist_string(ilist, "name")
                    break

        buff = weechat.buffer_search("irc", chan)

        if buff:
            weechat.buffer_set(buff, "number", str(count))
            count += 1

    weechat.infolist_free(ilist)

    return weechat.WEECHAT_RC_OK
Esempio n. 2
0
def cb_vimode_cmd(data, buf, args):
    """Handle script commands (``/vimode <command>``)."""
    # ``/vimode`` or ``/vimode help``
    if not args or args == "help":
        weechat.prnt('', "[vimode.py] %s" % README_URL)
    # ``/vimode bind_keys`` or ``/vimode bind_keys --list``
    elif args.startswith("bind_keys"):
        infolist = weechat.infolist_get("key", '', "default")
        weechat.infolist_reset_item_cursor(infolist)
        commands = [
            "/key unbind ctrl-W", "/key bind ctrl-^ /input jump_last_buffer",
            "/key bind ctrl-Wh /window left", "/key bind ctrl-Wj /window down",
            "/key bind ctrl-Wk /window up", "/key bind ctrl-Wl /window right",
            "/key bind ctrl-W= /window balance",
            "/key bind ctrl-Wx /window swap",
            "/key bind ctrl-Ws /window splith",
            "/key bind ctrl-Wv /window splitv",
            "/key bind ctrl-Wq /window merge"
        ]
        while weechat.infolist_next(infolist):
            key = weechat.infolist_string(infolist, "key")
            if re.match(REGEX_PROBLEMATIC_KEYBINDINGS, key):
                commands.append("/key unbind %s" % key)
        if args == "bind_keys":
            weechat.prnt('', "Running commands:")
            for command in commands:
                weechat.command('', command)
            weechat.prnt('', "Done.")
        elif args == "bind_keys --list":
            weechat.prnt('', "Listing commands we'll run:")
            for command in commands:
                weechat.prnt('', "    %s" % command)
            weechat.prnt('', "Done.")
    return weechat.WEECHAT_RC_OK
Esempio n. 3
0
def cb_vimode_cmd(data, buf, args):
    """Handle script commands (``/vimode <command>``)."""
    # ``/vimode`` or ``/vimode help``
    if not args or args == "help":
        weechat.prnt('', "[vimode.py] %s" % README_URL)
    # ``/vimode bind_keys`` or ``/vimode bind_keys --list``
    elif args.startswith("bind_keys"):
        infolist = weechat.infolist_get("key", '', "default")
        weechat.infolist_reset_item_cursor(infolist)
        commands = ["/key unbind ctrl-W",
                    "/key bind ctrl-^ /input jump_last_buffer",
                    "/key bind ctrl-Wh /window left",
                    "/key bind ctrl-Wj /window down",
                    "/key bind ctrl-Wk /window up",
                    "/key bind ctrl-Wl /window right",
                    "/key bind ctrl-W= /window balance",
                    "/key bind ctrl-Wx /window swap",
                    "/key bind ctrl-Ws /window splith",
                    "/key bind ctrl-Wv /window splitv",
                    "/key bind ctrl-Wq /window merge"]
        while weechat.infolist_next(infolist):
            key = weechat.infolist_string(infolist, "key")
            if re.match(REGEX_PROBLEMATIC_KEYBINDINGS, key):
                commands.append("/key unbind %s" % key)
        if args == "bind_keys":
            weechat.prnt('', "Running commands:")
            for command in commands:
                weechat.command('', command)
            weechat.prnt('', "Done.")
        elif args == "bind_keys --list":
            weechat.prnt('', "Listing commands we'll run:")
            for command in commands:
                weechat.prnt('', "    %s" % command)
            weechat.prnt('', "Done.")
    return weechat.WEECHAT_RC_OK
def walk_nicklist(nicklist,word):
    weechat.infolist_reset_item_cursor(nicklist)
    ni = weechat.infolist_next(nicklist)
    while ni :
        type = weechat.infolist_string(nicklist,'type')
        if type == 'nick':
            nick = weechat.infolist_string(nicklist,'name')
            if nick.lower().startswith(word):
                return nick
        ni = weechat.infolist_next(nicklist)
    return ''
Esempio n. 5
0
def dev_reset(ptr):
    """ reset cursor on an infolist """
    w.infolist_reset_item_cursor(ptr)
    w.prnt('', f"attempted to reset cursor for infolist {ptr}")
Esempio n. 6
0
def command_cb(data, buffer, args):
	cmd, args = tuple(args.split(" ", 1))

	if cmd == "list" or cmd == "listctxt":
		ctxt = ""
		if cmd == "listctxt":
			ctxt, args = tuple(args.split(" ", 1))

		r = re.compile(args)

		keys = weechat.infolist_get("key", "", ctxt)
		cnt = 0
		while weechat.infolist_next(keys):
			key = weechat.infolist_string(keys, "key")

			if (r.search(key)):
				cnt += 1

		prntr = args
		if cmd == "list":
			weechat.prnt("", "%d key bindings matching \"%s\"" % (cnt, prntr))
		elif cmd == "listctxt":
			weechat.prnt("", "%d key bindings for context \"%s\" matching \"%s\"" % (cnt, ctxt, prntr))

		weechat.infolist_reset_item_cursor(keys)
		while weechat.infolist_next(keys):
			key = weechat.infolist_string(keys, "key")
			command = weechat.infolist_string(keys, "command")

			if (r.search(key)):
				weechat.prnt("", "  %s %s=>%s %s" % (key, weechat.color("green"), weechat.color("reset"), command))

		weechat.infolist_free(keys)

	elif cmd == "reset" or cmd == "resetctxt":
		ctxt = ""
		if cmd == "resetctxt":
			ctxt, args = tuple(args.split(" ", 1))

		r = re.compile(args)

		keys = weechat.infolist_get("key", "", ctxt)
		while weechat.infolist_next(keys):
			key = weechat.infolist_string(keys, "key")

			if (r.search(key)):
				if cmd == "reset":
					weechat.command("", "/key reset %s" % key)
				elif cmd == "resetctxt":
					weechat.command("", "/key resetctxt %s %s" % (ctxt, key))

		weechat.infolist_free(keys)

	elif cmd == "unbind" or cmd == "unbindctxt":
		ctxt = ""
		if cmd == "unbindctxt":
			ctxt, args = tuple(args.split(" ", 1))

		r = re.compile(args)

		keys = weechat.infolist_get("key", "", ctxt)
		while weechat.infolist_next(keys):
			key = weechat.infolist_string(keys, "key")

			if (r.search(key)):
				if cmd == "unbind":
					weechat.command("", "/key unbind %s" % key)
				elif cmd == "unbindctxt":
					weechat.command("", "/key unbindctxt %s %s" % (ctxt, key))

		weechat.infolist_free(keys)

	return weechat.WEECHAT_RC_OK
Esempio n. 7
0
def dev_reset(ptr):
    """ reset cursor on an infolist """
    w.infolist_reset_item_cursor(ptr)
    w.prnt('', f"attempted to reset cursor for infolist {ptr}")