]> git.rmz.io Git - dotfiles.git/commitdiff
weechat: update plugins
authorSamir Benmendil <samir.benmendil@ultrahaptics.com>
Mon, 2 Sep 2019 11:37:05 +0000 (12:37 +0100)
committerSamir Benmendil <samir.benmendil@ultrahaptics.com>
Mon, 2 Sep 2019 11:37:05 +0000 (12:37 +0100)
weechat/perl/highmon.pl
weechat/python/autosort.py
weechat/python/grep.py

index 1c0771250afef3cb39685b3959f5ae39cc7c3223..066fa4370997aa43c653df0aa097bd037f11a999 100644 (file)
@@ -1,6 +1,6 @@
 #
 # highmon.pl - Highlight Monitoring for weechat 0.3.0
-# Version 2.5
+# Version 2.6
 #
 # Add 'Highlight Monitor' buffer/bar to log all highlights in one spot
 #
@@ -73,6 +73,8 @@
 # Bugs and feature requests at: https://github.com/KenjiE20/highmon
 
 # History:
+# 2019-05-13, HubbeKing <hubbe128@gmail.com>
+#      v2.6:   -add: send "logger_backlog" signal on buffer open if logging is enabled
 # 2014-08-16, KenjiE20 <longbow@longbowslair.co.uk>:
 #      v2.5:   -add: clearbar command to clear bar output
 #                      -add: firstrun output prompt to check the help text for set up hints as they were being missed
@@ -306,7 +308,7 @@ sub highmon_buffer_open
        # Turn off notify, highlights
        if ($highmon_buffer ne "")
        {
-               if (weechat::config_get_plugin("hotlist_show" eq "off"))
+               if (weechat::config_get_plugin("hotlist_show") eq "off")
                {
                        weechat::buffer_set($highmon_buffer, "notify", "0");
                }
@@ -317,6 +319,11 @@ sub highmon_buffer_open
                {
                        weechat::buffer_set($highmon_buffer, "localvar_set_no_log", "1");
                }
+               # send "logger_backlog" signal if logging is enabled to display backlog
+               if (weechat::config_get_plugin("logging") eq "on")
+               {
+                       weechat::hook_signal_send("logger_backlog", weechat::WEECHAT_HOOK_SIGNAL_POINTER, $highmon_buffer)
+               }
        }
        return weechat::WEECHAT_RC_OK;
 }
@@ -1124,7 +1131,7 @@ sub format_buffer_name
 }
 
 # Check result of register, and attempt to behave in a sane manner
-if (!weechat::register("highmon", "KenjiE20", "2.5", "GPL3", "Highlight Monitor", "", ""))
+if (!weechat::register("highmon", "KenjiE20", "2.6", "GPL3", "Highlight Monitor", "", ""))
 {
        # Double load
        weechat::print ("", "\tHighmon is already loaded");
index 46a840c34a4d0573a5c007c05da8323728b3c629..8f7c263e149ae1b24868b0c840f480b887710f8a 100644 (file)
 
 #
 # Changelog:
+# 3.6:
+#   * Add more documentation on provided info hooks.
+# 3.5:
+#   * Add ${info:autosort_escape,...} to escape arguments for other info hooks.
 # 3.4:
 #   * Fix rate-limit of sorting to prevent high CPU load and lock-ups.
 #   * Fix bug in parsing empty arguments for info hooks.
@@ -76,7 +80,7 @@ import weechat
 
 SCRIPT_NAME     = 'autosort'
 SCRIPT_AUTHOR   = 'Maarten de Vries <maarten@de-vri.es>'
-SCRIPT_VERSION  = '3.4'
+SCRIPT_VERSION  = '3.6'
 SCRIPT_LICENSE  = 'GPL3'
 SCRIPT_DESC     = 'Flexible automatic (or manual) buffer sorting based on eval expressions.'
 
@@ -184,7 +188,7 @@ class Config:
                'irc_last':       '${if:${buffer.plugin.name}==irc}',
                'irc_raw_first':  '${if:${buffer.full_name}!=irc.irc_raw}',
                'irc_raw_last':   '${if:${buffer.full_name}==irc.irc_raw}',
-               'hashless_name':  '${info:autosort_replace,#,,${buffer.name}}',
+               'hashless_name':  '${info:autosort_replace,#,,${info:autosort_escape,${buffer.name}}}',
        })
 
        default_signal_delay = 5
@@ -746,6 +750,17 @@ def parse_args(args, max = None):
                if args is None: break
        return result, args
 
+def on_info_escape(pointer, name, arguments):
+       result = ''
+       for c in arguments:
+               if c == '\\':
+                       result += '\\\\'
+               elif c == ',':
+                       result += '\\,'
+               else:
+                       result +=c
+       return result
+
 def on_info_replace(pointer, name, arguments):
        arguments, rest = parse_args(arguments, 3)
        if rest or len(arguments) < 3:
@@ -910,6 +925,36 @@ Rename a helper variable.
 Swap the expressions of two helper variables in the list.
 
 
+{*white}# Info hooks{reset}
+Autosort comes with a number of info hooks to add some extra functionality to regular weechat eval strings.
+Info hooks can be used in eval strings in the form of {cyan}${{info:some_hook,arguments}}{reset}.
+
+Commas and backslashes in arguments to autosort info hooks (except for {cyan}${{info:autosort_escape}}{reset}) must be escaped with a backslash.
+
+{*white}${{info:{brown}autosort_replace{white},{cyan}pattern{white},{cyan}replacement{white},{cyan}source{white}}}{reset}
+Replace all occurrences of {cyan}pattern{reset} with {cyan}replacement{reset} in the string {cyan}source{reset}.
+Can be used to ignore certain strings when sorting by replacing them with an empty string.
+
+For example: {cyan}${{info:autosort_replace,cat,dog,the dog is meowing}}{reset} expands to "the cat is meowing".
+
+{*white}${{info:{brown}autosort_order{white},{cyan}value{white},{cyan}option0{white},{cyan}option1{white},{cyan}option2{white},{cyan}...{white}}}
+Generate a zero-padded number that corresponds to the index of {cyan}value{reset} in the list of options.
+If one of the options is the special value {brown}*{reset}, then any value not explicitly mentioned will be sorted at that position.
+Otherwise, any value that does not match an option is assigned the highest number available.
+Can be used to easily sort buffers based on a manual sequence.
+
+For example: {cyan}${{info:autosort_order,${{server}},freenode,oftc,efnet}}{reset} will sort freenode before oftc, followed by efnet and then any remaining servers.
+Alternatively, {cyan}${{info:autosort_order,${{server}},freenode,oftc,*,efnet}}{reset} will sort any unlisted servers after freenode and oftc, but before efnet.
+
+{*white}${{info:{brown}autosort_escape{white},{cyan}text{white}}}{reset}
+Escape commas and backslashes in {cyan}text{reset} by prepending them with a backslash.
+This is mainly useful to pass arbitrary eval strings as arguments to other autosort info hooks.
+Otherwise, an eval string that expands to something with a comma would be interpreted as multiple arguments.
+
+For example, it can be used to safely pass buffer names to {cyan}${{info:autosort_replace}}{reset} like so:
+{cyan}${{info:autosort_replace,##,#,${{info:autosort_escape,${{buffer.name}}}}}}{reset}.
+
+
 {*white}# Description
 Autosort is a weechat script to automatically keep your buffers sorted. The sort
 order can be customized by defining your own sort rules, but the default should
@@ -934,17 +979,6 @@ readable. They can be used in the main sort rules as variables. For example,
 a helper variable named `{cyan}foo{reset}` can be accessed in a main rule with the
 string `{cyan}${{foo}}{reset}`.
 
-{*white}# Replacing substrings{reset}
-There is no default method for replacing text inside eval expressions. However,
-autosort adds a `replace` info hook that can be used inside eval expressions:
-  {cyan}${{info:autosort_replace,from,to,text}}{reset}
-
-For example, to strip all hashes from a buffer name, you could write:
-  {cyan}${{info:autosort_replace,#,,${{buffer.name}}}}{reset}
-
-You can escape commas and backslashes inside the arguments by prefixing them with
-a backslash.
-
 {*white}# Automatic or manual sorting{reset}
 By default, autosort will automatically sort your buffer list whenever a buffer
 is opened, merged, unmerged or renamed. This should keep your buffers sorted in
@@ -973,15 +1007,29 @@ structure with the following setting (modify to suit your need):
 
 command_completion = '%(plugin_autosort) %(plugin_autosort) %(plugin_autosort) %(plugin_autosort) %(plugin_autosort)'
 
-info_replace_description = 'Replace all occurences of `from` with `to` in the string `text`.'
-info_replace_arguments   = 'from,to,text'
+info_replace_description = (
+       'Replace all occurrences of `pattern` with `replacement` in the string `source`. '
+       'Can be used to ignore certain strings when sorting by replacing them with an empty string. '
+       'See /help autosort for examples.'
+)
+info_replace_arguments = 'pattern,replacement,source'
 
 info_order_description = (
-       'Get a zero padded index of a value in a list of possible values.'
-       'If the value is not found, the index for `*` is returned.'
-       'If there is no `*` in the list, the highest index + 1 is returned.'
+       'Generate a zero-padded number that corresponds to the index of `value` in the list of options. '
+       'If one of the options is the special value `*`, then any value not explicitly mentioned will be sorted at that position. '
+       'Otherwise, any value that does not match an option is assigned the highest number available. '
+       'Can be used to easily sort buffers based on a manual sequence. '
+       'See /help autosort for examples.'
+)
+info_order_arguments = 'value,first,second,third,...'
+
+info_escape_description = (
+       'Escape commas and backslashes in `text` by prepending them with a backslash. '
+       'This is mainly useful to pass arbitrary eval strings as arguments to other autosort info hooks. '
+       'Otherwise, an eval string that expands to something with a comma would be interpreted as multiple arguments.'
+       'See /help autosort for examples.'
 )
-info_order_arguments   = 'value,first,second,third,...'
+info_escape_arguments = 'text'
 
 
 if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
@@ -1014,6 +1062,7 @@ if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
        weechat.hook_config('autosort.*', 'on_config_changed',  '')
        weechat.hook_completion('plugin_autosort', '', 'on_autosort_complete', '')
        weechat.hook_command('autosort', command_description.format(**colors), '', '', command_completion, 'on_autosort_command', '')
+       weechat.hook_info('autosort_escape',  info_escape_description,  info_escape_arguments,  'on_info_escape', '')
        weechat.hook_info('autosort_replace', info_replace_description, info_replace_arguments, 'on_info_replace', '')
        weechat.hook_info('autosort_order',   info_order_description,   info_order_arguments,   'on_info_order',   '')
 
index 19415311fa33e57855456e162f10ac240fea86ba..64dbc528f55b6afba0b9c34c8c5002e5c4324f07 100644 (file)
 #
 #   History:
 #
+#   2019-06-30, dabbill <dabbill@gmail.com>
+#               and Sébastien Helleu <flashcode@flashtux.org>
+#   version 0.8.2: make script compatible with Python 3
+#
 #   2018-04-10, Sébastien Helleu <flashcode@flashtux.org>
 #   version 0.8.1: fix infolist_time for WeeChat >= 2.2 (WeeChat returns a long
 #                  integer instead of a string)
 #   * supress highlights when printing in grep buffer
 #
 #   2010-10-06
-#   version 0.6.7: by xt <xt@bash.no> 
+#   version 0.6.7: by xt <xt@bash.no>
 #   * better temporary file:
-#    use tempfile.mkstemp. to create a temp file in log dir, 
+#    use tempfile.mkstemp. to create a temp file in log dir,
 #    makes it safer with regards to write permission and multi user
 #
 #   2010-04-08
@@ -226,7 +230,7 @@ except ImportError:
 
 SCRIPT_NAME    = "grep"
 SCRIPT_AUTHOR  = "Elián Hanisch <lambdae2@gmail.com>"
-SCRIPT_VERSION = "0.8.1"
+SCRIPT_VERSION = "0.8.2"
 SCRIPT_LICENSE = "GPL3"
 SCRIPT_DESC    = "Search in buffers and logs"
 SCRIPT_COMMAND = "grep"
@@ -259,14 +263,14 @@ class linesDict(dict):
     def get_matches_count(self):
         """Return the sum of total matches stored."""
         if dict.__len__(self):
-            return sum(map(lambda L: L.matches_count, self.itervalues()))
+            return sum(map(lambda L: L.matches_count, self.values()))
         else:
             return 0
 
     def __len__(self):
         """Return the sum of total lines stored."""
         if dict.__len__(self):
-            return sum(map(len, self.itervalues()))
+            return sum(map(len, self.values()))
         else:
             return 0
 
@@ -274,7 +278,7 @@ class linesDict(dict):
         """Returns buffer count or buffer name if there's just one stored."""
         n = len(self.keys())
         if n == 1:
-            return self.keys()[0]
+            return list(self.keys())[0]
         elif n > 1:
             return '%s logs' %n
         else:
@@ -282,18 +286,18 @@ class linesDict(dict):
 
     def items(self):
         """Returns a list of items sorted by line count."""
-        items = dict.items(self)
+        items = list(dict.items(self))
         items.sort(key=lambda i: len(i[1]))
         return items
 
     def items_count(self):
         """Returns a list of items sorted by match count."""
-        items = dict.items(self)
+        items = list(dict.items(self))
         items.sort(key=lambda i: i[1].matches_count)
         return items
 
     def strip_separator(self):
-        for L in self.itervalues():
+        for L in self.values():
             L.strip_separator()
 
     def get_last_lines(self, n):
@@ -302,7 +306,7 @@ class linesDict(dict):
         if n >= total_lines:
             # nothing to do
             return
-        for k, v in reversed(self.items()):
+        for k, v in reversed(list(self.items())):
             l = len(v)
             if n > 0:
                 if l > n:
@@ -487,7 +491,7 @@ def dir_list(dir, filter_list=(), filter_excludes=True, include_dir=False):
         return cache_dir[key]
     except KeyError:
         pass
-    
+
     filter_list = filter_list or get_config_log_filter()
     dir_len = len(dir)
     if filter_list:
@@ -657,8 +661,8 @@ def make_regexp(pattern, matchcase=False):
             regexp = re.compile(pattern, re.IGNORECASE)
         else:
             regexp = re.compile(pattern)
-    except Exception, e:
-        raise Exception, 'Bad pattern, %s' %e
+    except Exception as e:
+        raise Exception('Bad pattern, %s' % e)
     return regexp
 
 def check_string(s, regexp, hilight='', exact=False):
@@ -716,7 +720,7 @@ def grep_file(file, head, tail, after_context, before_context, count, regexp, hi
                 return s
     else:
         check = lambda s: check_string(s, regexp, hilight, exact)
-    
+
     try:
         file_object = open(file, 'r')
     except IOError:
@@ -736,7 +740,7 @@ def grep_file(file, head, tail, after_context, before_context, count, regexp, hi
             before_context, after_context = after_context, before_context
 
         if before_context:
-            before_context_range = range(1, before_context + 1)
+            before_context_range = list(range(1, before_context + 1))
             before_context_range.reverse()
 
         limit = tail or head
@@ -800,7 +804,7 @@ def grep_file(file, head, tail, after_context, before_context, count, regexp, hi
                     while id < after_context + offset:
                         id += 1
                         try:
-                            context_line = file_object.next()
+                            context_line = next(file_object)
                             _context_line = check(context_line)
                             if _context_line:
                                 offset = id
@@ -1002,7 +1006,7 @@ def grep_process(*args):
         global grep_options, log_pairs
         for log_name, log in log_pairs:
             result[log_name] = grep_file(log, *grep_options)
-    except Exception, e:
+    except Exception as e:
         result = e
 
     return pickle.dumps(result)
@@ -1038,7 +1042,7 @@ def grep_process_cb(data, command, return_code, out, err):
             if isinstance(data, Exception):
                 raise data
             matched_lines.update(data)
-        except Exception, e:
+        except Exception as e:
             set_buffer_error(repr(e))
             return WEECHAT_RC_OK
         else:
@@ -1180,7 +1184,7 @@ def buffer_update():
 
     # free matched_lines so it can be removed from memory
     del matched_lines
-    
+
 def split_line(s):
     """Splits log's line 's' in 3 parts, date, nick and msg."""
     global weechat_format
@@ -1280,12 +1284,12 @@ def buffer_input(data, buffer, input_data):
                 weechat.infolist_free(infolist)
             try:
                 cmd_grep_parsing(input_data)
-            except Exception, e:
-                error('Argument error, %s' %e, buffer=buffer)
+            except Exception as e:
+                error('Argument error, %s' % e, buffer=buffer)
                 return WEECHAT_RC_OK
             try:
                 show_matching_lines()
-            except Exception, e:
+            except Exception as e:
                 error(e)
     except NameError:
         error("There isn't any previous search to repeat.", buffer=buffer)
@@ -1342,11 +1346,11 @@ def cmd_grep_parsing(args):
 
     args = ' '.join(args) # join pattern for keep spaces
     if args:
-        pattern_tmpl = args  
+        pattern_tmpl = args
         pattern = _tmplRe.sub(tmplReplacer, args)
         debug('Using regexp: %s', pattern)
     if not pattern:
-        raise Exception, 'No pattern for grep the logs.'
+        raise Exception('No pattern for grep the logs.')
 
     def positive_number(opt, val):
         try:
@@ -1359,7 +1363,7 @@ def cmd_grep_parsing(args):
                 opt = '-' + opt
             else:
                 opt = '--' + opt
-            raise Exception, "argument for %s must be a positive integer." %opt
+            raise Exception("argument for %s must be a positive integer." % opt)
 
     for opt, val in opts:
         opt = opt.strip('-')
@@ -1454,8 +1458,8 @@ def cmd_grep(data, buffer, args):
     # parse
     try:
         cmd_grep_parsing(args)
-    except Exception, e:
-        error('Argument error, %s' %e)
+    except Exception as e:
+        error('Argument error, %s' % e)
         return WEECHAT_RC_OK
 
     # find logs
@@ -1501,7 +1505,7 @@ def cmd_grep(data, buffer, args):
     # grepping
     try:
         show_matching_lines()
-    except Exception, e:
+    except Exception as e:
         error(e)
     return WEECHAT_RC_OK
 
@@ -1520,8 +1524,8 @@ def cmd_logs(data, buffer, args):
             opt = opt.strip('-')
             if opt in ('size', 's'):
                 sort_by_size = True
-    except Exception, e:
-        error('Argument error, %s' %e)
+    except Exception as e:
+        error('Argument error, %s' % e)
         return WEECHAT_RC_OK
 
     # is there's a filter, filter_excludes should be False
@@ -1703,7 +1707,7 @@ Examples:
             'completion_grep_args', '')
 
     # settings
-    for opt, val in settings.iteritems():
+    for opt, val in settings.items():
         if not weechat.config_is_set_plugin(opt):
             weechat.config_set_plugin(opt, val)
 
@@ -1716,7 +1720,7 @@ Examples:
     color_summary     = weechat.color('lightcyan')
     color_delimiter   = weechat.color('chat_delimiters')
     color_script_nick = weechat.color('chat_nick')
-    
+
     # pretty [grep]
     script_nick = '%s[%s%s%s]%s' %(color_delimiter, color_script_nick, SCRIPT_NAME, color_delimiter,
             color_reset)