X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/8c794ed6ed5364ef9c50454ad6c3aedf98bee718..e13c0a2b5802f55a1aeab48dc9b88c18222cd5bd:/weechat/python/buffer_autoset.py diff --git a/weechat/python/buffer_autoset.py b/weechat/python/buffer_autoset.py index 305bd6b..9725cd7 100644 --- a/weechat/python/buffer_autoset.py +++ b/weechat/python/buffer_autoset.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2010-2015 Sébastien Helleu +# Copyright (C) 2010-2017 Sébastien Helleu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,14 +22,20 @@ # # History: # +# 2021-06-02, Sébastien Helleu : +# version 1.2: fix /help buffer_autoset +# 2018-04-14, Kim B. Heino: +# version 1.1: on startup apply settings to already opened buffers +# 2017-06-21, Sébastien Helleu : +# version 1.0: rename command /autosetbuffer to /buffer_autoset # 2015-09-28, Simmo Saan : # version 0.9: instantly apply properties # 2015-07-12, Sébastien Helleu : # version 0.8: add option buffer_autoset.look.timer to add a small timer # before setting buffer properties -# 2015-04-05, Nils Görs : +# 2015-04-05, Nils Görs : # version 0.7: increase priority of hook_signal('buffer_opened') -# 2012-12-09, Nils Görs : +# 2012-12-09, Nils Görs : # version 0.6: add support of core buffer # 2012-03-09, Sébastien Helleu : # version 0.5: fix reload of config file @@ -46,11 +52,11 @@ SCRIPT_NAME = "buffer_autoset" SCRIPT_AUTHOR = "Sébastien Helleu " -SCRIPT_VERSION = "0.9" +SCRIPT_VERSION = "1.2" SCRIPT_LICENSE = "GPL3" SCRIPT_DESC = "Auto-set buffer properties when a buffer is opened" -SCRIPT_COMMAND = "autosetbuffer" +SCRIPT_COMMAND = SCRIPT_NAME import_ok = True @@ -143,7 +149,7 @@ def bas_config_write(): # ================================[ command ]================================= def bas_cmd(data, buffer, args): - """Callback for /autosetbuffer command.""" + """Callback for /buffer_autoset command.""" args = args.strip() if args == "": weechat.command("", "/set %s.buffer.*" % CONFIG_FILE_NAME) @@ -172,7 +178,7 @@ def bas_completion_current_buffer_cb(data, completion_item, buffer, completion): """ Complete with current buffer name (plugin.name), - for command '/autosetbuffer'. + for command '/buffer_autoset'. """ name = "%s.%s" % (weechat.buffer_get_string(buffer, "plugin"), weechat.buffer_get_string(buffer, "name")) @@ -182,7 +188,7 @@ def bas_completion_current_buffer_cb(data, completion_item, buffer, def bas_completion_options_cb(data, completion_item, buffer, completion): - """Complete with config options, for command '/autosetbuffer'.""" + """Complete with config options, for command '/buffer_autoset'.""" options = weechat.infolist_get("option", "", "%s.buffer.*" % CONFIG_FILE_NAME) if options: @@ -240,11 +246,12 @@ def bas_signal_buffer_opened_cb(data, signal, signal_data): weechat.buffer_get_string(buffer, "full_name")) return weechat.WEECHAT_RC_OK + def bas_config_option_cb(data, option, value): if not weechat.config_boolean(bas_options["look_instant"]): return weechat.WEECHAT_RC_OK - if not weechat.config_get(option): # option was deleted + if not weechat.config_get(option): # option was deleted return weechat.WEECHAT_RC_OK option = option[len("%s.buffer." % CONFIG_FILE_NAME):] @@ -267,6 +274,7 @@ def bas_config_option_cb(data, option, value): return weechat.WEECHAT_RC_OK + # ==================================[ main ]================================== if __name__ == "__main__" and import_ok: @@ -285,26 +293,25 @@ if __name__ == "__main__" and import_ok: "[add buffer property value] | [del option]", " add: add a buffer/property/value in configuration file\n" " del: delete an option from configuration file\n" - " buffer: name of a buffer (can start or end with \"*\" as " - "wildcard)\n" + " buffer: name of a buffer (wildcard \"*\" is allowed)\n" "property: buffer property\n" " value: value for property\n" " option: name of option from configuration file\n\n" "Examples:\n" " disable timestamp on channel #weechat:\n" - " /" + SCRIPT_COMMAND + " add irc.freenode.#weechat " + " /" + SCRIPT_COMMAND + " add irc.libera.#weechat " "time_for_each_line 0\n" " add word \"weechat\" in highlight list on channel " "#savannah:\n" - " /" + SCRIPT_COMMAND + " add irc.freenode.#savannah " + " /" + SCRIPT_COMMAND + " add irc.libera.#savannah " "highlight_words_add weechat\n" - " disable highlights from nick \"mike\" on freenode server, " + " disable highlights from nick \"mike\" on libera server, " "channel #weechat (requires WeeChat >= 0.3.4):\n" - " /" + SCRIPT_COMMAND + " add irc.freenode.#weechat " + " /" + SCRIPT_COMMAND + " add irc.libera.#weechat " "hotlist_max_level_nicks_add mike:2\n" - " disable hotlist changes for nick \"bot\" on freenode " + " disable hotlist changes for nick \"bot\" on libera " "server (all channels) (requires WeeChat >= 0.3.4):\n" - " /" + SCRIPT_COMMAND + " add irc.freenode.* " + " /" + SCRIPT_COMMAND + " add irc.libera.* " "hotlist_max_level_nicks_add bot:-1", "add %(buffers_plugins_names)|" "%(buffer_autoset_current_buffer) " @@ -324,8 +331,13 @@ if __name__ == "__main__" and import_ok: weechat.hook_config("%s.buffer.*" % CONFIG_FILE_NAME, "bas_config_option_cb", "") - # core buffer is already open on script startup, check manually! - bas_signal_buffer_opened_cb("", "", weechat.buffer_search_main()) + # apply settings to all already opened buffers + buffers = weechat.infolist_get("buffer", "", "") + if buffers: + while weechat.infolist_next(buffers): + buffer = weechat.infolist_pointer(buffers, "pointer") + bas_signal_buffer_opened_cb("", "", buffer) + weechat.infolist_free(buffers) # ==================================[ end ]===================================