]> git.rmz.io Git - dotfiles.git/blobdiff - weechat/perl/buffers.pl
vim: add choice snippet for sh
[dotfiles.git] / weechat / perl / buffers.pl
index c8935c409b745f458d4efe8677fcc71b2f12f8ed..73eb4b55cd74b09ced7312121d5631611812449a 100644 (file)
 #
 # History:
 #
+# 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
+# 2014-08-29, Patrick Steinhardt <ps@pks.im>:
+#     v4.9: add support for specifying custom buffer names
+# 2014-07-19, Sebastien Helleu <flashcode@flashtux.org>:
+#     v4.8: add support of ctrl + mouse wheel to jump to previous/next buffer,
+#           new option "mouse_wheel"
+# 2014-06-22, Sebastien Helleu <flashcode@flashtux.org>:
+#     v4.7: fix typos in options
 # 2014-04-05, Sebastien Helleu <flashcode@flashtux.org>:
 #     v4.6: add support of hidden buffers (WeeChat >= 0.4.4)
 # 2014-01-01, Sebastien Helleu <flashcode@flashtux.org>:
@@ -155,15 +172,19 @@ use strict;
 use Encode qw( decode encode );
 # -----------------------------[ internal ]-------------------------------------
 my $SCRIPT_NAME = "buffers";
-my $SCRIPT_VERSION = "4.6";
+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");
+                  "\@item(buffers):button2*" => "hsignal:buffers_mouse",
+                  "\@bar(buffers):ctrl-wheelup" => "hsignal:buffers_mouse",
+                  "\@bar(buffers):ctrl-wheeldown" => "hsignal:buffers_mouse");
 my %options;
 my %hotlist_level = (0 => "low", 1 => "message", 2 => "private", 3 => "highlight");
 my @whitelist_buffers = ();
@@ -201,6 +222,8 @@ weechat::hook_signal("buffer_renamed", "buffers_signal_buffer", "");
 weechat::hook_signal("buffer_switch", "buffers_signal_buffer", "");
 weechat::hook_signal("buffer_hidden", "buffers_signal_buffer", "");  # WeeChat >= 0.4.4
 weechat::hook_signal("buffer_unhidden", "buffers_signal_buffer", "");  # WeeChat >= 0.4.4
+weechat::hook_signal("buffer_localvar_added", "buffers_signal_buffer", "");
+weechat::hook_signal("buffer_localvar_changed", "buffers_signal_buffer", "");
 
 weechat::hook_signal("window_switch", "buffers_signal_buffer", "");
 weechat::hook_signal("hotlist_changed", "buffers_signal_hotlist", "");
@@ -628,7 +651,7 @@ my %default_options_look =
  ],
  "show_lag" => [
      "show_lag", "boolean",
-     "show lag behind servername. This option is using \"irc.color.".
+     "show lag behind server name. This option is using \"irc.color.".
      "item_lag_finished\", ".
      "\"irc.network.lag_min_show\" and \"irc.network.lag_refresh_interval\"",
      "", 0, 0, "off", "off", 0,
@@ -662,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)",
@@ -670,31 +700,31 @@ my %default_options_look =
  ],
  "show_number" => [
      "show_number", "boolean",
-     "display channel number in front of buffername",
+     "display buffer number in front of buffer name",
      "", 0, 0, "on", "on", 0,
      "", "", "buffers_signal_config", "", "", ""
  ],
  "show_number_char" => [
      "number_char", "string",
-     "display a char behind channel number",
+     "display a char behind buffer number",
      "", 0, 0, ".", ".", 0,
      "", "", "buffers_signal_config", "", "", ""
  ],
  "show_prefix_bufname" => [
      "prefix_bufname", "string",
-     "prefix displayed in front of buffername",
+     "prefix displayed in front of buffer name",
      "", 0, 0, "", "", 0,
      "", "", "buffers_signal_config", "", "", ""
  ],
  "show_suffix_bufname" => [
      "suffix_bufname", "string",
-     "suffix displayed at end of buffername",
+     "suffix displayed at end of buffer name",
      "", 0, 0, "", "", 0,
      "", "", "buffers_signal_config", "", "", ""
  ],
  "show_prefix" => [
      "prefix", "boolean",
-     "displays your prefix for channel in front of buffername",
+     "displays your prefix for channel in front of buffer name",
      "", 0, 0, "off", "off", 0,
      "", "", "buffers_signal_config", "", "", ""
  ],
@@ -745,32 +775,44 @@ my %default_options_look =
  ],
  "detach" => [
      "detach", "integer",
-     "detach channel from buffers list after a specific period of time ".
+     "detach buffer from buffers list after a specific period of time ".
      "(in seconds) without action (weechat ≥ 0.3.8 required) (0 means \"off\")",
      "", 0, 31536000, 0, "number", 0,
      "", "", "buffers_signal_config", "", "", ""
  ],
  "immune_detach_buffers" => [
      "immune_detach_buffers", "string",
-     "comma separated list of buffers to NOT automatically detatch. ".
+     "comma separated list of buffers to NOT automatically detach. ".
      "Allows \"*\" wildcard. Ex: \"BitlBee,freenode.*\"",
      "", 0, 0, "", "", 0,
      "", "", "buffers_signal_config_immune_detach_buffers", "", "", ""
  ],
  "detach_query" => [
      "detach_query", "boolean",
-     "query buffer will be detachted",
+     "query buffer will be detached",
      "", 0, 0, "off", "off", 0,
      "", "", "buffers_signal_config", "", "", ""
  ],
  "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)",
@@ -798,7 +840,7 @@ my %default_options_look =
      "", "", "buffers_signal_config", "", "", ""
  ],
  "toggle_bar" => [
-     "toogle_bar", "boolean",
+     "toggle_bar", "boolean",
      "if option is \"on\", buffers bar will hide/show when script is ".
      "(un)loaded.",
      "", 0, 0, "on", "on", 0,
@@ -810,6 +852,12 @@ my %default_options_look =
      "", 0, 0, "on", "on", 0,
      "", "", "buffers_signal_config", "", "", ""
  ],
+ "mouse_wheel" => [
+     "mouse_wheel", "boolean",
+     "if option is \"on\", mouse wheel jumps to previous/next buffer in list.",
+     "", 0, 0, "on", "on", 0,
+     "", "", "buffers_signal_config", "", "", ""
+ ],
 );
     # section "color"
     my $section_color = weechat::config_new_section(
@@ -973,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)
         {
@@ -1089,10 +1137,22 @@ sub build_buffers
             my $key;
             if (weechat::config_integer( $options{"sort"} ) eq 1) # number = 0; name = 1
             {
-                my $name = $buffer->{"name"};
-                $name = $buffer->{"short_name"} if (weechat::config_boolean( $options{"short_names"} ) eq 1);
-                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"})));
+                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)
                 {
@@ -1273,8 +1333,17 @@ sub build_buffers
             }
             else
             {
-                my $indent = "";
-                $indent = ((" " x length($buffer->{"number"}))." ") if (($position eq "left") || ($position eq "right"));
+                # Indentation aligns channels in a visually appealing way
+                # when viewing list top-to-bottom...
+                my $indent = (" " x length($buffer->{"number"}))." ";
+                # ...except when list is top/bottom and channels left-to-right.
+                my $option_pos = weechat::config_string( weechat::config_get( "weechat.bar.buffers.position" ) );
+                if (($option_pos eq 'top') || ($option_pos eq 'bottom')) {
+                    my $option_filling = weechat::config_string( weechat::config_get( "weechat.bar.buffers.filling_top_bottom" ) );
+                    if ($option_filling =~ /horizontal/) {
+                        $indent = '';
+                    }
+                }
                 $str .= weechat::color("default")
                     .$color_bg
                     .$indent;
@@ -1289,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"} ) ) );
                     }
                 }
             }
@@ -1351,38 +1421,38 @@ sub build_buffers
 
         $str .= weechat::color($color) . weechat::color(",".$bg);
 
-        if (weechat::config_boolean( $options{"short_names"} ) eq 1)
+        my $name = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_custom_name");
+        if (not defined $name or $name eq "")
         {
-            if (weechat::config_integer($options{"name_size_max"}) >= 1)                # check max_size of buffer name
-            {
-                $str .= encode("UTF-8", substr(decode("UTF-8", $buffer->{"short_name"}), 0, weechat::config_integer($options{"name_size_max"})));
-                $str .= weechat::color(weechat::config_color( $options{"color_number_char"})).weechat::config_string($options{"name_crop_suffix"}) if (length($buffer->{"short_name"}) > weechat::config_integer($options{"name_size_max"}));
-                $str .= add_inactive_parentless($buffer->{"type"}, $buffer->{"nicks_count"});
-                $str .= add_hotlist_count($buffer->{"pointer"}, %hotlist);
+            if (weechat::config_boolean( $options{"short_names"} ) eq 1) {
+                $name = $buffer->{"short_name"};
+            } else {
+                $name = $buffer->{"name"};
             }
-            else
+        }
+
+        if (weechat::config_integer($options{"name_size_max"}) >= 1)                # check max_size of buffer name
+        {
+            $name = decode("UTF-8", $name);
+
+            $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)
             {
-                $str .= $buffer->{"short_name"};
-                $str .= add_inactive_parentless($buffer->{"type"}, $buffer->{"nicks_count"});
-                $str .= add_hotlist_count($buffer->{"pointer"}, %hotlist);
+                $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);
         }
         else
         {
-            if (weechat::config_integer($options{"name_size_max"}) >= 1)                # check max_size of buffer name
-            {
-                $str .= encode("UTF-8", substr(decode("UTF-8", $buffer->{"name"},), 0, weechat::config_integer($options{"name_size_max"})));
-                $str .= weechat::color(weechat::config_color( $options{"color_number_char"})).weechat::config_string($options{"name_crop_suffix"}) if (length($buffer->{"name"}) > weechat::config_integer($options{"name_size_max"}));
-                $str .= add_inactive_parentless($buffer->{"type"}, $buffer->{"nicks_count"});
-                $str .= add_hotlist_count($buffer->{"pointer"}, %hotlist);
-            }
-            else
-            {
-                $str .= $buffer->{"name"};
-                $str .= add_inactive_parentless($buffer->{"type"}, $buffer->{"nicks_count"});
-                $str .= add_hotlist_count($buffer->{"pointer"}, %hotlist);
-            }
+            $str .= $name;
+            $str .= add_inactive_parentless($buffer->{"type"}, $buffer->{"nicks_count"});
+            $str .= add_hotlist_count($buffer->{"pointer"}, %hotlist);
         }
+
         if ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") eq "server" and weechat::config_boolean($options{"show_lag"}) eq 1)
         {
             my $color_lag = weechat::config_color(weechat::config_get("irc.color.item_lag_finished"));
@@ -1615,11 +1685,12 @@ sub buffers_hsignal_mouse
     my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
     my $current_buffer = weechat::buffer_get_integer(weechat::current_buffer(), "number"); # get current buffer number
 
-    if ( $hash{"_key"} eq "button1" )           # left mouse button
+    if ( $hash{"_key"} eq "button1" )
     {
+        # left mouse button
         if ($hash{"number"} eq $hash{"number2"})
         {
-            if ( weechat::config_integer($options{"jump_prev_next_visited_buffer"}) eq 1 )
+            if ( weechat::config_boolean($options{"jump_prev_next_visited_buffer"}) )
             {
                 if ( $current_buffer eq $hash{"number"} )
                 {
@@ -1640,13 +1711,30 @@ sub buffers_hsignal_mouse
             move_buffer(%hash) if (weechat::config_boolean($options{"mouse_move_buffer"}));
         }
     }
-    elsif ( ($hash{"_key"} eq "button2") && (weechat::config_integer($options{"jump_prev_next_visited_buffer"}) eq 1) )# right mouse button
+    elsif ( ($hash{"_key"} eq "button2") && (weechat::config_boolean($options{"jump_prev_next_visited_buffer"})) )
     {
+        # right mouse button
         if ( $current_buffer eq $hash{"number2"} )
         {
             weechat::command("", "/input jump_next_visited_buffer");
         }
     }
+    elsif ( $hash{"_key"} =~ /wheelup$/ )
+    {
+        # wheel up
+        if (weechat::config_boolean($options{"mouse_wheel"}))
+        {
+            weechat::command("", "/buffer -1");
+        }
+    }
+    elsif ( $hash{"_key"} =~ /wheeldown$/ )
+    {
+        # wheel down
+        if (weechat::config_boolean($options{"mouse_wheel"}))
+        {
+            weechat::command("", "/buffer +1");
+        }
+    }
     else
     {
         my $infolist = weechat::infolist_get("hook", "", "command,menu");