Commit 717e4601 authored by arza's avatar arza Committed by Sébastien Helleu

buffers.pl 5.5: fix memory leak in perl 5.23.7-5.24.1, fix truncation and...

buffers.pl 5.5: fix memory leak in perl 5.23.7-5.24.1, fix truncation and crop_suffix when truncating to 1-4 characters, fix prefix_empty for inactive buffers, tidy code
parent b0630945
......@@ -20,15 +20,20 @@
#
# History:
#
# 2017-02-21, arza <[email protected]>:
# v5.5: fix memory leak in perl 5.23.7-5.24.1
# fix truncation and crop_suffix when truncating to 1-4 characters
# fix prefix_empty for inactive buffers
# tidy code
# 2016-05-01, mumixam <[email protected]>:
# v5.4: added option "detach_buffer_immediately_level"
# v5.4: add option "detach_buffer_immediately_level"
# 2015-08-21, Matthew Cox <[email protected]>
# v5.3: add option "indenting_amount", to adjust the indenting of channel buffers
# 2015-05-02, arza <[email protected]>:
# v5.2: truncate long names (name_size_max) more when mark_inactive adds parenthesis
# 2015-03-29, Ed Santiago <[email protected]>:
# v5.1: merged buffers: always indent, except when filling is horizontal
# 2014-12-12
# 2014-12-12, oakkitten
# v5.0: fix cropping non-latin buffer names
# 2014-08-29, Patrick Steinhardt <[email protected]>:
# v4.9: add support for specifying custom buffer names
......@@ -46,8 +51,8 @@
# weechat.look.buffer_auto_renumber is off
# 2013-12-10, [email protected]#weechat:
# v4.3: add options "prefix_bufname" and "suffix_bufname (idea by silverd)
# : fix hook_timer() for show_lag wasn't disabled
# : improved signal handling (less updating of buffers list)
# fix hook_timer() for show_lag wasn't disabled
# improve signal handling (less updating of buffers list)
# 2013-11-07, Sebastien Helleu <[email protected]>:
# v4.2: use default filling "columns_vertical" when bar position is top/bottom
# 2013-10-31, [email protected]#weechat:
......@@ -56,11 +61,11 @@
# v4.0: add options "detach_displayed_buffers", "detach_display_window_number"
# 2013-09-27, [email protected]#weechat:
# v3.9: add option "toggle_bar" and option "show_prefix_query" (idea by IvarB)
# : fix problem with linefeed at end of list of buffers (reported by grawity)
# fix problem with linefeed at end of list of buffers (reported by grawity)
# 2012-10-18, [email protected]#weechat:
# v3.8: add option "mark_inactive", to mark buffers you are not in (idea by xrdodrx)
# : add wildcard "*" for immune_detach_buffers (idea by StarWeaver)
# : add new options "detach_query" and "detach_free_content" (idea by StarWeaver)
# add wildcard "*" for immune_detach_buffers (idea by StarWeaver)
# add new options "detach_query" and "detach_free_content" (idea by StarWeaver)
# 2012-10-06, Nei <anti.teamidiot.de>:
# v3.7: call menu on right mouse if menu script is loaded.
# 2012-10-06, nils_2 <[email protected]>:
......@@ -104,7 +109,7 @@
# 2011-08-24, Sebastien Helleu <[email protected]>:
# v2.4: add mouse support
# 2011-06-06, nils_2 <[email protected]>:
# v2.3: added: missed option "color_whitelist_default"
# v2.3: add missing option "color_whitelist_default"
# 2011-03-23, Sebastien Helleu <[email protected]>:
# v2.2: fix color of nick prefix with WeeChat >= 0.3.5
# 2011-02-13, nils_2 <[email protected]>:
......@@ -172,15 +177,13 @@ use strict;
use Encode qw( decode encode );
# -----------------------------[ internal ]-------------------------------------
my $SCRIPT_NAME = "buffers";
my $SCRIPT_VERSION = "5.4";
my $SCRIPT_VERSION = "5.5";
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",
......@@ -323,6 +326,7 @@ my ( $data, $buffer, $args ) = @_;
}
return weechat::WEECHAT_RC_OK;
}
sub buffers_cmd_detach
{
my ( $data, $buffer, $args ) = @_;
......@@ -367,12 +371,12 @@ sub create_whitelist
{
my @buffers_list = @{$_[0]};
my $buffers_list = "";
foreach (@buffers_list)
{
$buffers_list .= $_ .",";
}
# remove last ","
chop $buffers_list;
foreach (@buffers_list)
{
$buffers_list .= $_ .",";
}
# remove last ","
chop $buffers_list;
return $buffers_list;
}
......@@ -388,7 +392,7 @@ sub hook_timer_detach
else
{
weechat::unhook($Hooks{timer_detach}) if $Hooks{timer_detach};
$Hooks{timer_detach} = weechat::hook_timer( weechat::config_integer( $options{"detach"}) * 1000, 60, 0, "buffers_signal_hotlist", "");
$Hooks{timer_detach} = weechat::hook_timer( weechat::config_integer($options{"detach"}) * 1000, 60, 0, "buffers_signal_hotlist", "");
}
weechat::bar_item_update($SCRIPT_NAME);
return weechat::WEECHAT_RC_OK;
......@@ -415,15 +419,18 @@ sub buffers_config_read
{
return weechat::config_read($buffers_config_file) if ($buffers_config_file ne "");
}
sub buffers_config_write
{
return weechat::config_write($buffers_config_file) if ($buffers_config_file ne "");
}
sub buffers_config_reload_cb
{
my ($data, $config_file) = ($_[0], $_[1]);
return weechat::config_reload($config_file)
}
sub buffers_config_init
{
$buffers_config_file = weechat::config_new($BUFFERS_CONFIG_FILE_NAME,
......@@ -859,6 +866,7 @@ my %default_options_look =
"", "", "buffers_signal_config", "", "", ""
],
);
# section "color"
my $section_color = weechat::config_new_section(
$buffers_config_file,
......@@ -923,6 +931,297 @@ my %default_options_look =
}
}
# get sort key of buffer
sub key_of_buffer
{
my ($buffer, $number) = @_;
my $key = "";
if (weechat::config_integer($options{"sort"}) eq 1) # number = 0; name = 1
{
my $name = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_custom_name");
if (not defined $name or $name eq "")
{
if (weechat::config_boolean( $options{"short_names"} ) eq 1)
{
$name = $buffer->{"short_name"};
}
else
{
$name = $buffer->{"name"};
}
}
if ( weechat::config_boolean($options{"core_to_front"}) eq 1)
{
if ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "channel" and
weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "private" )
{
my $type = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type");
if ( $type eq "" and $name ne "weechat")
{
$name = " " . $name;
}
else
{
$name = " " . $name;
}
}
}
$key = sprintf("%s%08d", lc($name), $buffer->{"number"});
}
else
{
$key = sprintf("%08d", $number);
}
return $key;
}
# whether to skip this buffer
sub skip_buffer
{
my ($buffer) = @_;
return 0 if $buffer->{"active"};
if ( weechat::config_string($options{"hide_merged_buffers"}) eq "server" and
($buffer->{"type"} eq "server" or $buffer->{"plugin_name"} eq "core") )
{
return 1;
}
if ( weechat::config_string($options{"hide_merged_buffers"}) eq "channel" and
($buffer->{"type"} eq "channel" or $buffer->{"plugin_name"} eq "core") )
{
return 1;
}
if ( weechat::config_string($options{"hide_merged_buffers"}) eq "private" and
($buffer->{"type"} eq "private" or $buffer->{"plugin_name"} eq "core") )
{
return 1;
}
if ( weechat::config_string($options{"hide_merged_buffers"}) eq "keepserver" and
($buffer->{"type"} ne "server" or $buffer->{"plugin_name"} eq "core") )
{
return 1;
}
if ( weechat::config_string($options{"hide_merged_buffers"}) eq "all" )
{
return 1;
}
return 0;
}
# truncate string from the end to $maxlength, 0 = don't truncate
sub truncate_end
{
my ($name, $maxlength) = @_;
if ($maxlength == 0)
{
return $name;
}
my $str = decode("UTF-8", $name);
$str = substr($str, 0, $maxlength);
$str = encode("UTF-8", $str);
return $str;
}
# format one buffer name in buffers bar: truncate and add parentheses
sub format_name
{
my ($buffer, $fg, $bg) = @_;
my $output = "";
my $crop_suffix = weechat::color( weechat::config_color($options{"color_number_char"}) ) . weechat::config_string($options{"name_crop_suffix"});
my $maxlength = weechat::config_integer($options{"name_size_max"});
my $name = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_custom_name");
if (not defined $name or $name eq "")
{
if (weechat::config_boolean( $options{"short_names"} ) eq 1)
{
$name = $buffer->{"short_name"};
}
else
{
$name = $buffer->{"name"};
}
}
if ( $buffer->{"type"} eq "channel" &&
weechat::config_boolean($options{"mark_inactive"}) eq 1 &&
$buffer->{"nicks_count"} == 0 &&
$maxlength > 2 )
{
$output = weechat::color( weechat::config_color($options{"color_number_char"}) ).
"(".
weechat::color($fg).
weechat::color(",$bg").
truncate_end($name, $maxlength-2).
(length($name) > $maxlength-2 ? $crop_suffix : "").
weechat::color( weechat::config_color($options{"color_number_char"}) ).
")";
}
else
{
$output = weechat::color($fg).
weechat::color(",$bg").
truncate_end($name, $maxlength).
(length($name) > $maxlength && $maxlength > 0 ? $crop_suffix : "");
}
return $output;
}
# get fg and bg for a buffer
sub get_colors
{
my ($buffer, %hotlist) = @_;
my $fg = weechat::config_color( $options{"color_default_fg"} );
my $bg = weechat::config_color( $options{"color_default_bg"} );
if ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") eq "private" )
{
if ( weechat::config_color($options{"queries_default_bg"}) ne "default" || weechat::config_color($options{"queries_default_fg"}) ne "default" )
{
$fg = weechat::config_color( $options{"queries_default_fg"} );
$bg = weechat::config_color( $options{"queries_default_bg"} );
}
}
# check for core and buffer with free content
elsif ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "channel" and
weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "private" )
{
$fg = weechat::config_color( $options{"color_none_channel_fg"} );
$bg = weechat::config_color( $options{"color_none_channel_bg"} );
}
# default whitelist buffer?
if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
{
$fg = weechat::config_color( $options{"color_whitelist_default_fg"} );
$bg = weechat::config_color( $options{"color_whitelist_default_bg"} );
}
$fg = "default" if ($fg eq "");
$bg = "default" if ($bg eq "");
# color for channel and query buffer
if (exists $hotlist{$buffer->{"pointer"}})
{
delete $buffers_timer{$buffer->{"pointer"}};
# check if buffer is in whitelist buffer
if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
{
$fg = weechat::config_color( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
$bg = weechat::config_color( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
}
elsif ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") eq "private" )
{
# queries_default_fg/bg and buffers.color.queries_message_fg/bg
if ( weechat::config_color($options{"queries_highlight_fg"}) ne "default" ||
weechat::config_color($options{"queries_highlight_bg"}) ne "default" ||
weechat::config_color($options{"queries_message_fg"}) ne "default" ||
weechat::config_color($options{"queries_message_bg"}) ne "default" )
{
if ( ($hotlist{$buffer->{"pointer"}}) == 2 )
{
$fg = weechat::config_color( $options{"queries_message_fg"} );
$bg = weechat::config_color( $options{"queries_message_bg"} );
}
elsif ( ($hotlist{$buffer->{"pointer"}}) == 3 )
{
$fg = weechat::config_color( $options{"queries_highlight_fg"} );
$bg = weechat::config_color( $options{"queries_highlight_bg"} );
}
}
else
{
$fg = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
$bg = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
}
}
else
{
$fg = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
$bg = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
}
}
if ($buffer->{"current_buffer"})
{
$fg = weechat::config_color( $options{"color_current_fg"} );
$bg = weechat::config_color( $options{"color_current_bg"} );
}
return ($fg, $bg);
}
# get nick prefix of channel
sub nick_prefix
{
my ($buffer) = @_;
my $output = "";
my $nickname = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_nick");
if ($nickname eq "")
{
return "";
}
# with version >= 0.3.2, this infolist will return only nick
# with older versions, whole nicklist is returned for buffer, and this can be very slow
my $infolist_nick = weechat::infolist_get("nicklist", $buffer->{"pointer"}, "nick_".$nickname);
if ($infolist_nick eq "")
{
return weechat::config_boolean($options{"show_prefix_empty"}) eq 1 && $buffer->{"type"} eq "channel" ? " " : "";
}
while (weechat::infolist_next($infolist_nick))
{
if ( (weechat::infolist_string($infolist_nick, "type") eq "nick")
&& (weechat::infolist_string($infolist_nick, "name") eq $nickname) )
{
my $prefix = weechat::infolist_string($infolist_nick, "prefix");
if ( ($prefix eq " ") and (weechat::config_boolean($options{"show_prefix_empty"}) eq 0) )
{
last;
}
# with version >= 0.3.5, it is now a color name (for older versions: option name with color)
if ($weechat_version >= 0x00030500)
{
$output .= weechat::color(weechat::infolist_string($infolist_nick, "prefix_color"));
}
else
{
$output .= weechat::color(weechat::config_color(
weechat::config_get(
weechat::infolist_string($infolist_nick, "prefix_color"))));
}
$output .= $prefix;
last;
}
}
weechat::infolist_free($infolist_nick);
return $output;
}
# get all hotlist counts for a buffer
sub hotlist_counts
{
my ($buffer, %hotlist) = @_;
my $delim_color = weechat::color( weechat::config_color($options{"color_number_char"}) );
my $counters = "";
foreach my $counter ("low", "message", "private", "highlight")
{
if ($hotlist{$buffer."_count_${counter}"})
{
$counters =~ s/([0-9])$/$1,/;
$counters .= weechat::color( weechat::config_color($options{"color_hotlist_${counter}_fg"}) ) . $hotlist{$buffer."_count_${counter}"};
}
}
return " $delim_color($counters$delim_color)";
}
# buffers item
sub build_buffers
{
my $str = "";
......@@ -942,15 +1241,15 @@ sub build_buffers
{
$hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")} =
weechat::infolist_integer($infolist, "priority");
if ( weechat::config_boolean( $options{"hotlist_counter"} ) eq 1 and $weechat_version >= 0x00030500)
if ( weechat::config_boolean( $options{"hotlist_counter"} ) eq 1 and $weechat_version >= 0x00030500 )
{
$hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_00"} =
$hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_low"} =
weechat::infolist_integer($infolist, "count_00"); # low message
$hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_01"} =
$hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_message"} =
weechat::infolist_integer($infolist, "count_01"); # channel message
$hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_02"} =
$hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_private"} =
weechat::infolist_integer($infolist, "count_02"); # private message
$hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_03"} =
$hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_highlight"} =
weechat::infolist_integer($infolist, "count_03"); # highlight message
}
}
......@@ -965,13 +1264,15 @@ sub build_buffers
my $max_number = 0;
my $max_number_digits = 0;
my $active_seen = 0;
my $current_time = time();
$infolist = weechat::infolist_get("buffer", "", "");
while (weechat::infolist_next($infolist))
{
# ignore hidden buffers (WeeChat >= 0.4.4)
if ($weechat_version >= 0x00040400)
if ($weechat_version >= 0x00040400 and weechat::infolist_integer($infolist, "hidden"))
{
next if (weechat::infolist_integer($infolist, "hidden"));
next;
}
my $buffer;
my $number = weechat::infolist_integer($infolist, "number");
......@@ -1002,35 +1303,44 @@ sub build_buffers
$buffer->{"short_name"} = weechat::infolist_string($infolist, "short_name");
$buffer->{"full_name"} = $buffer->{"plugin_name"}.".".$buffer->{"name"};
$buffer->{"type"} = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type");
#weechat::print("", $buffer->{"type"});
# check if buffer is active (or maybe a /part, /kick channel)
if ($buffer->{"type"} eq "channel" and weechat::config_boolean( $options{"mark_inactive"} ) eq 1)
{
my $server = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_server");
my $channel = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_channel");
my $infolist_channel = weechat::infolist_get("irc_channel", "", $server.",".$channel);
my $infolist_channel = weechat::infolist_get("irc_channel", "", "$server,$channel");
if ($infolist_channel)
{
weechat::infolist_next($infolist_channel);
$buffer->{"nicks_count"} = weechat::infolist_integer($infolist_channel, "nicks_count");
}else
}
else
{
$buffer->{"nicks_count"} = 0;
}
weechat::infolist_free($infolist_channel);
}
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"}} < $maxlevel) ); # checking for buffer to immediately detach
unless ($result)
if (check_immune_detached_buffers($buffer->{"name"}))
{
my $detach_time = weechat::config_integer( $options{"detach"});
my $current_time = time();
if ($active_seen)
{
push(@current2, $buffer);
}
else
{
push(@current1, $buffer);
}
}
else
{
my $detach_time = weechat::config_integer($options{"detach"});
# set timer for buffers with no hotlist action
$buffers_timer{$buffer->{"pointer"}} = $current_time
if ( not exists $hotlist{$buffer->{"pointer"}}
......@@ -1039,37 +1349,40 @@ sub build_buffers
and $detach_time > 0);
$buffers_timer{$buffer->{"pointer"}} = $current_time
if (weechat::config_boolean($options{"detach_query"}) eq 1
and not exists $hotlist{$buffer->{"pointer"}}
and $buffer->{"type"} eq "private"
and not exists $buffers_timer{$buffer->{"pointer"}}
and $detach_time > 0);
if (weechat::config_boolean($options{"detach_query"}) eq 1
and not exists $hotlist{$buffer->{"pointer"}}
and $buffer->{"type"} eq "private"
and not exists $buffers_timer{$buffer->{"pointer"}}
and $detach_time > 0);
$detach_time = 0
if (weechat::config_boolean($options{"detach_query"}) eq 0
and $buffer->{"type"} eq "private");
if (weechat::config_boolean($options{"detach_query"}) eq 0
and $buffer->{"type"} eq "private");
# free content buffer
$buffers_timer{$buffer->{"pointer"}} = $current_time
if (weechat::config_boolean($options{"detach_free_content"}) eq 1
and not exists $hotlist{$buffer->{"pointer"}}
and $buffer->{"type"} eq ""
and not exists $buffers_timer{$buffer->{"pointer"}}
and $detach_time > 0);
if (weechat::config_boolean($options{"detach_free_content"}) eq 1
and not exists $hotlist{$buffer->{"pointer"}}
and $buffer->{"type"} eq ""
and not exists $buffers_timer{$buffer->{"pointer"}}
and $detach_time > 0);
$detach_time = 0
if (weechat::config_boolean($options{"detach_free_content"}) eq 0
and $buffer->{"type"} eq "");
if (weechat::config_boolean($options{"detach_free_content"}) eq 0
and $buffer->{"type"} eq "");
$detach_time = 0 if (weechat::config_boolean($options{"mark_inactive"}) eq 1 and defined $buffer->{"nicks_count"} and $buffer->{"nicks_count"} == 0);
$detach_time = 0
if (weechat::config_boolean($options{"mark_inactive"}) eq 1
and defined $buffer->{"nicks_count"}
and $buffer->{"nicks_count"} == 0);
# check for detach
unless ( $buffer->{"current_buffer"} eq 0
and not exists $hotlist{$buffer->{"pointer"}}
# and $buffer->{"type"} eq "channel"
and exists $buffers_timer{$buffer->{"pointer"}}
and $detach_time > 0
and $weechat_version >= 0x00030800
and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
and not exists $hotlist{$buffer->{"pointer"}}
and exists $buffers_timer{$buffer->{"pointer"}}
and $detach_time > 0
and $weechat_version >= 0x00030800
and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
{
if ($active_seen)
{
......@@ -1081,102 +1394,42 @@ sub build_buffers
}
}
elsif ( $buffer->{"current_buffer"} eq 0
and not exists $hotlist{$buffer->{"pointer"}}
# and $buffer->{"type"} eq "channel"
and exists $buffers_timer{$buffer->{"pointer"}}
and $detach_time > 0
and $weechat_version >= 0x00030800
and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
{ # check for option detach_displayed_buffers and if buffer is displayed in a split window
if ( $buffer->{"num_displayed"} eq 1
and weechat::config_boolean($options{"detach_displayed_buffers"}) eq 0 )
and not exists $hotlist{$buffer->{"pointer"}}
and exists $buffers_timer{$buffer->{"pointer"}}
and $detach_time > 0
and $weechat_version >= 0x00030800
and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time
and $buffer->{"num_displayed"} eq 1 # check for option detach_displayed_buffers and if buffer is displayed in a split window
and weechat::config_boolean($options{"detach_displayed_buffers"}) eq 0 )
{
my $infolist_window = weechat::infolist_get("window", "", "");
while (weechat::infolist_next($infolist_window))
{
my $infolist_window = weechat::infolist_get("window", "", "");
while (weechat::infolist_next($infolist_window))
my $buffer_ptr = weechat::infolist_pointer($infolist_window, "buffer");
if ($buffer_ptr eq $buffer->{"pointer"})
{
my $buffer_ptr = weechat::infolist_pointer($infolist_window, "buffer");
if ($buffer_ptr eq $buffer->{"pointer"})
{
$buffer->{"window"} = weechat::infolist_integer($infolist_window, "number");
}
$buffer->{"window"} = weechat::infolist_integer($infolist_window, "number");
}
weechat::infolist_free($infolist_window);
push(@current2, $buffer);
}
weechat::infolist_free($infolist_window);
push(@current2, $buffer);
}
}
else # buffer in "immune_detach_buffers"
{
if ($active_seen)
{
push(@current2, $buffer);
}
else
{
push(@current1, $buffer);
}
}
} # while end
} # end of while
if ($max_number >= 1)
{
$max_number_digits = length(int($max_number));
}
$max_number_digits = length($max_number);
@buffers = (@buffers, @current2, @current1);
weechat::infolist_free($infolist);
# sort buffers by number, name or shortname
my %sorted_buffers;
if (1)
my $number = 0;
for my $buffer (@buffers)
{
my $number = 0;
for my $buffer (@buffers)
{
my $key;
if (weechat::config_integer( $options{"sort"} ) eq 1) # number = 0; name = 1
{
my $name = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_custom_name");
if (not defined $name or $name eq "") {
if (weechat::config_boolean( $options{"short_names"} ) eq 1) {
$name = $buffer->{"short_name"};
} else {
$name = $buffer->{"name"};
}
}
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)
{
if ( (weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "private") )
{
my $type = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type");
if ( $type eq "" and $name ne "weechat")
{
$name = " " . $name
}else
{
$name = " " . $name;
}
}
}
$key = sprintf("%s%08d", lc($name), $buffer->{"number"});
}
else
{
$key = sprintf("%08d", $number);
}
$sorted_buffers{$key} = $buffer;
$number++;
}
$sorted_buffers{key_of_buffer($buffer, $number)} = $buffer;
$number++;
}
# build string with buffers
......@@ -1185,274 +1438,84 @@ sub build_buffers
{
my $buffer = $sorted_buffers{$key};
if ( weechat::config_string($options{"hide_merged_buffers"}) eq "server" )
{
# buffer type "server" or merged with core?
if ( ($buffer->{"type"} eq "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
{
next;
}
}
if ( weechat::config_string($options{"hide_merged_buffers"}) eq "channel" )
{