diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2016-11-06 03:09:47 +0100 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2017-06-01 18:37:35 +0200 |
commit | ed6e136d971a9152e539b17418680e00d0b25d6e (patch) | |
tree | a6f026e0bf327fa450886d0022c937c164c3d407 /weechat/perl | |
parent | 168664e365b8b97362875eb8d0f3f0cf99ff5576 (diff) | |
download | dotfiles-ed6e136d971a9152e539b17418680e00d0b25d6e.tar.xz |
weechat: Update scripts
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
Diffstat (limited to 'weechat/perl')
-rw-r--r-- | weechat/perl/buffers.pl | 69 | ||||
-rw-r--r-- | weechat/perl/iset.pl | 198 |
2 files changed, 223 insertions, 44 deletions
diff --git a/weechat/perl/buffers.pl b/weechat/perl/buffers.pl index c31d8fc..73eb4b5 100644 --- a/weechat/perl/buffers.pl +++ b/weechat/perl/buffers.pl @@ -20,7 +20,13 @@ # # History: # -# 2015-03-29, Ed Santiago <ed@edsantiago.com> +# 2016-05-01, mumixam <mumixam@gmail.com>: +# v5.4: added option "detach_buffer_immediately_level" +# 2015-08-21, Matthew Cox <matthewcpcox@gmail.com> +# v5.3: add option "indenting_amount", to adjust the indenting of channel buffers +# 2015-05-02, arza <arza@arza.us>: +# v5.2: truncate long names (name_size_max) more when mark_inactive adds parenthesis +# 2015-03-29, Ed Santiago <ed@edsantiago.com>: # v5.1: merged buffers: always indent, except when filling is horizontal # 2014-12-12 # v5.0: fix cropping non-latin buffer names @@ -166,13 +172,15 @@ use strict; use Encode qw( decode encode ); # -----------------------------[ internal ]------------------------------------- my $SCRIPT_NAME = "buffers"; -my $SCRIPT_VERSION = "5.1"; +my $SCRIPT_VERSION = "5.4"; my $BUFFERS_CONFIG_FILE_NAME = "buffers"; my $buffers_config_file; my $cmd_buffers_whitelist= "buffers_whitelist"; my $cmd_buffers_detach = "buffers_detach"; +my $maxlength; + my %mouse_keys = ("\@item(buffers):button1*" => "hsignal:buffers_mouse", "\@item(buffers):button2*" => "hsignal:buffers_mouse", "\@bar(buffers):ctrl-wheelup" => "hsignal:buffers_mouse", @@ -677,6 +685,13 @@ my %default_options_look = "", 0, 0, "on", "on", 0, "", "", "buffers_signal_config", "", "", "" ], + "indenting_amount" => [ + "indenting_amount", "integer", + "amount of indenting to use. This option only takes effect if bar ". + "is left/right positioned, and indenting is enabled", + "", 0, 16, 2, 2, 0, + "", "", "buffers_signal_config", "", "", "" + ], "short_names" => [ "short_names", "boolean", "display short names (remove text before first \".\" in buffer name)", @@ -780,12 +795,24 @@ my %default_options_look = ], "detach_buffer_immediately" => [ "detach_buffer_immediately", "string", - "comma separated list of buffers to detach immediately. A query and ". - "highlight message will attach buffer again. Allows \"*\" wildcard. ". + "comma separated list of buffers to detach immediately. Buffers ". + "will attach again based on notify level set in ". + "\"detach_buffer_immediately_level\". Allows \"*\" wildcard. ". "Ex: \"BitlBee,freenode.*\"", "", 0, 0, "", "", 0, "", "", "buffers_signal_config_detach_buffer_immediately", "", "", "" ], + "detach_buffer_immediately_level" => [ + "detach_buffer_immediately_level", "integer", + "The value determines what notify level messages are reattached from activity. ". + " This option works in conjunction with \"detach_buffer_immediately\" ". + "0: low priority (like join/part messages), ". + "1: message, ". + "2: private, ". + "3: highlight", + "", 0, 3, 2, 2, 0, + "", "", "buffers_signal_config", "", "", "" + ], "detach_free_content" => [ "detach_free_content", "boolean", "buffers with free content will be detached (Ex: iset, chanmon)", @@ -994,11 +1021,11 @@ sub build_buffers weechat::infolist_free($infolist_channel); } - my $result = check_immune_detached_buffers($buffer->{"name"}); # checking for wildcard - + my $result = check_immune_detached_buffers($buffer->{"name"}); # checking for wildcard + my $maxlevel = weechat::config_integer($options{"detach_buffer_immediately_level"}); next if ( check_detach_buffer_immediately($buffer->{"name"}) eq 1 and $buffer->{"current_buffer"} eq 0 - and ( not exists $hotlist{$buffer->{"pointer"}} or $hotlist{$buffer->{"pointer"}} < 2) ); # checking for buffer to immediately detach + and ( not exists $hotlist{$buffer->{"pointer"}} or $hotlist{$buffer->{"pointer"}} < $maxlevel) ); # checking for buffer to immediately detach unless ($result) { @@ -1118,8 +1145,14 @@ sub build_buffers $name = $buffer->{"name"}; } } - if (weechat::config_integer($options{"name_size_max"}) >= 1){ - $name = encode("UTF-8", substr(decode("UTF-8", $name), 0, weechat::config_integer($options{"name_size_max"}))); + if (weechat::config_integer($options{"name_size_max"}) >= 1) + { + $maxlength = weechat::config_integer($options{"name_size_max"}); + if($buffer->{"type"} eq "channel" and weechat::config_boolean( $options{"mark_inactive"} ) eq 1 and $buffer->{"nicks_count"} == 0) + { + $maxlength -= 2; + } + $name = encode("UTF-8", substr(decode("UTF-8", $name), 0, $maxlength)); } if ( weechat::config_boolean($options{"core_to_front"}) eq 1) { @@ -1325,16 +1358,17 @@ sub build_buffers { if ( weechat::config_integer( $options{"indenting"} ) eq 1 ) { - $str .= " "; + $str .= (" " x weechat::config_integer( $options{"indenting_amount"} ) ); } elsif ( (weechat::config_integer($options{"indenting"}) eq 2) and (weechat::config_integer($options{"indenting_number"}) eq 0) ) #under_name { if ( weechat::config_boolean( $options{"show_number"} ) eq 0 ) { - $str .= " "; - }else + $str .= (" " x weechat::config_integer( $options{"indenting_amount"} ) ); + } + else { - $str .= ( (" " x ( $max_number_digits - length($buffer->{"number"}) ))." " ); + $str .= ( (" " x ( $max_number_digits - length($buffer->{"number"}) )).(" " x weechat::config_integer( $options{"indenting_amount"} ) ) ); } } } @@ -1400,7 +1434,14 @@ sub build_buffers if (weechat::config_integer($options{"name_size_max"}) >= 1) # check max_size of buffer name { $name = decode("UTF-8", $name); - $str .= encode("UTF-8", substr($name, 0, weechat::config_integer($options{"name_size_max"}))); + + $maxlength = weechat::config_integer($options{"name_size_max"}); + if($buffer->{"type"} eq "channel" and weechat::config_boolean( $options{"mark_inactive"} ) eq 1 and $buffer->{"nicks_count"} == 0) + { + $maxlength -= 2; + } + + $str .= encode("UTF-8", substr($name, 0, $maxlength)); $str .= weechat::color(weechat::config_color( $options{"color_number_char"})).weechat::config_string($options{"name_crop_suffix"}) if (length($name) > weechat::config_integer($options{"name_size_max"})); $str .= add_inactive_parentless($buffer->{"type"}, $buffer->{"nicks_count"}); $str .= add_hotlist_count($buffer->{"pointer"}, %hotlist); diff --git a/weechat/perl/iset.pl b/weechat/perl/iset.pl index af74767..163dfb5 100644 --- a/weechat/perl/iset.pl +++ b/weechat/perl/iset.pl @@ -19,6 +19,13 @@ # # History: # +# 2016-07-08, nils_2 <weechatter@arcor.de> +# version 4.2: add diff function +# 2016-02-06, Sebastien Helleu <flashcode@flashtux.org>: +# version 4.1: remove debug print +# 2015-12-24, Sebastien Helleu <flashcode@flashtux.org>: +# version 4.0: add support of parent options (inherited values in irc servers) +# with WeeChat >= 1.4 # 2015-05-16, Sebastien Helleu <flashcode@flashtux.org>: # version 3.9: fix cursor position when editing an option with WeeChat >= 1.2 # 2015-05-02, arza <arza@arza.us>: @@ -123,7 +130,7 @@ use strict; my $PRGNAME = "iset"; -my $VERSION = "3.9"; +my $VERSION = "4.2"; my $DESCR = "Interactive Set for configuration options"; my $AUTHOR = "Sebastien Helleu <flashcode\@flashtux.org>"; my $LICENSE = "GPL3"; @@ -135,9 +142,11 @@ my $iset_buffer = ""; my $wee_version_number = 0; my @iset_focus = (); my @options_names = (); +my @options_parent_names = (); my @options_types = (); my @options_values = (); my @options_default_values = (); +my @options_parent_values = (); my @options_is_null = (); my $option_max_length = 0; my $current_line = 0; @@ -145,7 +154,7 @@ my $filter = "*"; my $description = ""; my $options_name_copy = ""; my $iset_filter_title = ""; -# search modes: 0 = index() on value, 1 = grep() on value, 2 = grep() on option, 3 = grep on option & value +# search modes: 0 = index() on value, 1 = grep() on value, 2 = grep() on option, 3 = grep on option & value, 4 = diff all, 5 = diff parts my $search_mode = 2; my $search_value = ""; my $help_text_keys = "alt + space: toggle, +/-: increase/decrease, enter: change, ir: reset, iu: unset, v: toggle help bar"; @@ -195,6 +204,12 @@ sub iset_title $filter = "*" if ($filter eq ""); $show_filter = $filter; } + elsif ($search_mode == 4 or $search_mode == 5) + { + $iset_filter_title = "diff: "; + $show_filter = "all"; + $show_filter = $search_value if $search_mode == 5; + } elsif ($search_mode eq 3) { $iset_filter_title = "(option) "; @@ -267,10 +282,27 @@ sub iset_buffer_input weechat::buffer_set($iset_buffer, "localvar_set_iset_search_value", $search_value); } } + # show all diff values + elsif ($string eq "d") + { + $search_mode = 4; +# iset_title(); + iset_create_filter("*"); + iset_get_options("*"); + } + elsif ( $array_count >= 2 and $cmd_array[0] eq "d") + { + $search_mode = 5; + $search_value = substr($cmd_array[1], 0); # cut value_search_char + $search_value = substr($cmd_array[2], 0) if ( $array_count > 2); # cut value_search_char + iset_create_filter($search_value); + iset_get_options($search_value); + + } else { $search_mode = 2; - if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s") + if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s" ) { if ( defined $cmd_array[1] and substr($cmd_array[1], 0, 1) eq weechat::config_string($options_iset{"value_search_char"}) or defined $cmd_array[2] and substr($cmd_array[2], 0, 1) eq weechat::config_string($options_iset{"value_search_char"}) ) @@ -284,7 +316,8 @@ sub iset_buffer_input { iset_create_filter($string); iset_get_options($search_value); - }else + } + else { iset_create_filter($string); iset_get_options(""); @@ -353,9 +386,11 @@ sub iset_get_options $search_value = $var_value; @iset_focus = (); @options_names = (); + @options_parent_names = (); @options_types = (); @options_values = (); @options_default_values = (); + @options_parent_values = (); @options_is_null = (); $option_max_length = 0; my %options_internal = (); @@ -371,34 +406,61 @@ sub iset_get_options { $key = sprintf("%08d", $i); my $name = weechat::infolist_string($infolist, "full_name"); + my $parent_name = weechat::infolist_string($infolist, "parent_name"); next if (weechat::config_boolean($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1); my $type = weechat::infolist_string($infolist, "type"); my $value = weechat::infolist_string($infolist, "value"); my $default_value = weechat::infolist_string($infolist, "default_value"); + my $parent_value; + if ($parent_name && (($wee_version_number < 0x00040300) || (weechat::infolist_search_var($infolist, "parent_value")))) + { + $parent_value = weechat::infolist_string($infolist, "parent_value"); + } my $is_null = weechat::infolist_integer($infolist, "value_is_null"); + if ($search_mode == 3) { my $value = weechat::infolist_string($infolist, "value"); if ( grep /\Q$var_value/,lc($value) ) { + $options_internal{$name}{"parent_name"} = $parent_name; $options_internal{$name}{"type"} = $type; $options_internal{$name}{"value"} = $value; $options_internal{$name}{"default_value"} = $default_value; + $options_internal{$name}{"parent_value"} = $parent_value; $options_internal{$name}{"is_null"} = $is_null; $option_max_length = length($name) if (length($name) > $option_max_length); - $iset_struct{$key} = $options_internal{$name}; - push(@iset_focus, $iset_struct{$key}); + $iset_struct{$key} = $options_internal{$name}; + push(@iset_focus, $iset_struct{$key}); + } + } + # search for diff? + elsif ( $search_mode == 4 or $search_mode == 5) + { + if ($value ne $default_value ) + { + $options_internal{$name}{"parent_name"} = $parent_name; + $options_internal{$name}{"type"} = $type; + $options_internal{$name}{"value"} = $value; + $options_internal{$name}{"default_value"} = $default_value; + $options_internal{$name}{"parent_value"} = $parent_value; + $options_internal{$name}{"is_null"} = $is_null; + $option_max_length = length($name) if (length($name) > $option_max_length); + $iset_struct{$key} = $options_internal{$name}; + push(@iset_focus, $iset_struct{$key}); } } else { + $options_internal{$name}{"parent_name"} = $parent_name; $options_internal{$name}{"type"} = $type; $options_internal{$name}{"value"} = $value; $options_internal{$name}{"default_value"} = $default_value; + $options_internal{$name}{"parent_value"} = $parent_value; $options_internal{$name}{"is_null"} = $is_null; $option_max_length = length($name) if (length($name) > $option_max_length); - $iset_struct{$key} = $options_internal{$name}; - push(@iset_focus, $iset_struct{$key}); + $iset_struct{$key} = $options_internal{$name}; + push(@iset_focus, $iset_struct{$key}); } $i++; } @@ -407,9 +469,11 @@ sub iset_get_options foreach my $name (sort keys %options_internal) { push(@options_names, $name); + push(@options_parent_names, $options_internal{$name}{"parent_name"}); push(@options_types, $options_internal{$name}{"type"}); push(@options_values, $options_internal{$name}{"value"}); push(@options_default_values, $options_internal{$name}{"default_value"}); + push(@options_parent_values, $options_internal{$name}{"parent_value"}); push(@options_is_null, $options_internal{$name}{"is_null"}); } } @@ -432,9 +496,11 @@ sub iset_search_values { my ($var_value,$search_mode) = ($_[0],$_[1]); @options_names = (); + @options_parent_names = (); @options_types = (); @options_values = (); @options_default_values = (); + @options_parent_values = (); @options_is_null = (); $option_max_length = 0; my %options_internal = (); @@ -443,18 +509,26 @@ sub iset_search_values while (weechat::infolist_next($infolist)) { my $name = weechat::infolist_string($infolist, "full_name"); + my $parent_name = weechat::infolist_string($infolist, "parent_name"); next if (weechat::config_boolean($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1); my $type = weechat::infolist_string($infolist, "type"); my $is_null = weechat::infolist_integer($infolist, "value_is_null"); my $value = weechat::infolist_string($infolist, "value"); my $default_value = weechat::infolist_string($infolist, "default_value"); + my $parent_value; + if ($parent_name && (($wee_version_number < 0x00040300) || (weechat::infolist_search_var($infolist, "parent_value")))) + { + $parent_value = weechat::infolist_string($infolist, "parent_value"); + } if ($search_mode) { if ( grep /\Q$var_value/,lc($value) ) { + $options_internal{$name}{"parent_name"} = $parent_name; $options_internal{$name}{"type"} = $type; $options_internal{$name}{"value"} = $value; $options_internal{$name}{"default_value"} = $default_value; + $options_internal{$name}{"parent_value"} = $parent_value; $options_internal{$name}{"is_null"} = $is_null; $option_max_length = length($name) if (length($name) > $option_max_length); } @@ -464,9 +538,11 @@ sub iset_search_values # if ($value =~ /\Q$var_value/si) if (lc($value) eq $var_value) { + $options_internal{$name}{"parent_name"} = $parent_name; $options_internal{$name}{"type"} = $type; $options_internal{$name}{"value"} = $value; $options_internal{$name}{"default_value"} = $default_value; + $options_internal{$name}{"parent_value"} = $parent_value; $options_internal{$name}{"is_null"} = $is_null; $option_max_length = length($name) if (length($name) > $option_max_length); } @@ -477,9 +553,11 @@ sub iset_search_values foreach my $name (sort keys %options_internal) { push(@options_names, $name); + push(@options_parent_names, $options_internal{$name}{"parent_name"}); push(@options_types, $options_internal{$name}{"type"}); push(@options_values, $options_internal{$name}{"value"}); push(@options_default_values, $options_internal{$name}{"default_value"}); + push(@options_parent_values, $options_internal{$name}{"parent_value"}); push(@options_is_null, $options_internal{$name}{"is_null"}); } } @@ -508,9 +586,11 @@ sub iset_refresh_line my $color1 = weechat::color(weechat::config_color($options_iset{"color_option"})); my $color2 = weechat::color(weechat::config_color($options_iset{"color_type"})); my $color3 = ""; + my $color4 = ""; if ($options_is_null[$y]) { $color3 = weechat::color(weechat::config_color($options_iset{"color_value_undef"})); + $color4 = weechat::color(weechat::config_color($options_iset{"color_value"})); } elsif ($options_values[$y] ne $options_default_values[$y]) { @@ -527,6 +607,7 @@ sub iset_refresh_line if ($options_is_null[$y]) { $color3 = weechat::color(weechat::config_color($options_iset{"color_value_undef_selected"}).",".weechat::config_color($options_iset{"color_bg_selected"})); + $color4 = weechat::color(weechat::config_color($options_iset{"color_value_selected"}).",".weechat::config_color($options_iset{"color_bg_selected"})); } elsif ($options_values[$y] ne $options_default_values[$y]) { @@ -538,7 +619,23 @@ sub iset_refresh_line } } my $value = $options_values[$y]; - $value = "(undef)" if ($options_is_null[$y]); + if ($options_is_null[$y]) + { + $value = "null"; + if ($options_parent_names[$y]) + { + if (defined $options_parent_values[$y]) + { + my $around_parent = ""; + $around_parent = "\"" if ($options_types[$y] eq "string"); + $value .= $color1." -> ".$color4.$around_parent.$options_parent_values[$y].$around_parent; + } + else + { + $value .= $color1." -> ".$color3."null"; + } + } + } my $strline = sprintf($format, $color1, $options_names[$y], $padding, $color2, $options_types[$y], @@ -712,6 +809,39 @@ sub iset_get_option_name_index return -1; } +sub iset_refresh_option +{ + my $option_name = $_[0]; + my $index = $_[1]; + my $infolist = weechat::infolist_get("option", "", $option_name); + if ($infolist) + { + weechat::infolist_next($infolist); + if (weechat::infolist_fields($infolist)) + { + $options_parent_names[$index] = weechat::infolist_string($infolist, "parent_name"); + $options_types[$index] = weechat::infolist_string($infolist, "type"); + $options_values[$index] = weechat::infolist_string($infolist, "value"); + $options_default_values[$index] = weechat::infolist_string($infolist, "default_value"); + $options_is_null[$index] = weechat::infolist_integer($infolist, "value_is_null"); + $options_parent_values[$index] = undef; + if ($options_parent_names[$index] + && (($wee_version_number < 0x00040300) || (weechat::infolist_search_var($infolist, "parent_value")))) + { + $options_parent_values[$index] = weechat::infolist_string($infolist, "parent_value"); + } + iset_refresh_line($index); + iset_title() if ($option_name eq "iset.look.show_current_line"); + } + else + { + iset_full_refresh(1); # if not found, refresh fully without clearing buffer + weechat::print_y($iset_buffer, $#options_names + 1, ""); + } + weechat::infolist_free($infolist); + } +} + sub iset_config_cb { my ($data, $option_name, $value) = ($_[0], $_[1], $_[2]); @@ -724,25 +854,14 @@ sub iset_config_cb if ($index >= 0) { # refresh info about changed option - my $infolist = weechat::infolist_get("option", "", $option_name); - if ($infolist) + iset_refresh_option($option_name, $index); + # refresh any other option having this changed option as parent + foreach my $i (0 .. $#options_names) { - weechat::infolist_next($infolist); - if (weechat::infolist_fields($infolist)) - { - $options_types[$index] = weechat::infolist_string($infolist, "type"); - $options_values[$index] = weechat::infolist_string($infolist, "value"); - $options_default_values[$index] = weechat::infolist_string($infolist, "default_value"); - $options_is_null[$index] = weechat::infolist_integer($infolist, "value_is_null"); - iset_refresh_line($index); - iset_title() if ($option_name eq "iset.look.show_current_line"); - } - else + if ($options_parent_names[$i] eq $option_name) { - iset_full_refresh(1); # if not found, refresh fully without clearing buffer - weechat::print_y($iset_buffer, $#options_names + 1, ""); + iset_refresh_option($options_names[$i], $i); } - weechat::infolist_free($infolist); } } else @@ -817,20 +936,37 @@ sub iset_cmd_cb { # f/s option =value # option =value - $search_mode = 2; + $search_mode = 2; # grep on option if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s") { if ( defined $cmd_array[1] and substr($cmd_array[1], 0, 1) eq weechat::config_string($options_iset{"value_search_char"}) or defined $cmd_array[2] and substr($cmd_array[2], 0, 1) eq weechat::config_string($options_iset{"value_search_char"}) ) { - $search_mode = 3; + $search_mode = 3; # grep on option and value $search_value = substr($cmd_array[1], 1); # cut value_search_char $search_value = substr($cmd_array[2], 1) if ( $array_count > 2); # cut value_search_char } } + + # show all diff values + if ( $args eq "d") + { + $search_mode = 4; + $search_value = "*"; + $args = $search_value; + } + if ( $array_count >= 2 and $cmd_array[0] eq "d") + { + $search_mode = 5; + $search_value = substr($cmd_array[1], 0); # cut value_search_char + $search_value = substr($cmd_array[2], 0) if ( $array_count > 2); # cut value_search_char + $args = $search_value; + } + iset_create_filter($args); $filter_set = 1; my $ptrbuf = weechat::buffer_search($LANG, $PRGNAME); + if ($ptrbuf eq "") { iset_init(); @@ -1421,7 +1557,8 @@ $wee_version_number = weechat::info_get("version_number", "") || 0; iset_config_init(); iset_config_read(); -weechat::hook_command($PRGNAME, "Interactive set", "f <file> || s <section> || [=][=]<text>", +weechat::hook_command($PRGNAME, "Interactive set", "d <text> || f <file> || s <section> || [=][=]<text>", + "d <text> : show only changed options\n". "f file : show options for a file\n". "s section: show options for a section\n". "text : show options with 'text' in name\n". @@ -1442,6 +1579,7 @@ weechat::hook_command($PRGNAME, "Interactive set", "f <file> || s <section> || [ "text,enter : set a new filter using command line (use '*' to see all options)\n". "alt+'v' : toggle help bar on/off\n". "alt+'p' : toggle option \"show_plugin_description\" on/off\n". + "q : as input in iset buffer to close it\n". "\n". "Mouse actions:\n". "wheel up/down : move cursor up/down\n". @@ -1450,8 +1588,8 @@ weechat::hook_command($PRGNAME, "Interactive set", "f <file> || s <section> || [ "right button + drag left/right: increase/decrease value (for integer or color)\n". "\n". "Examples:\n". - " show options for file 'weechat'\n". - " /iset f weechat\n". + " show changed options in 'aspell' plugin\n". + " /iset d aspell\n". " show options for file 'irc'\n". " /iset f irc\n". " show options for section 'look'\n". |