NAME

Nlib - weechat perl library with helper functions for infolists and to map screen coordinates

USAGE

To use this library in a weechat perl script, put the library file in either the weechat perl directory or in the same place as the script file you use in the /perl load command.

Then, add the following preamble to your script, replacing YOUR_SCRIPT_NAME_HERE with the name of your script and the call to weechat::register with the appropriate data:

  use constant SCRIPT_NAME => 'YOUR_SCRIPT_NAME_HERE';
  weechat::register(SCRIPT_NAME, 'Author <address>', '9.99', 'License', 'Script description', 'stop_script_function', 'parameters');
  sub SCRIPT_FILE() {
        my $infolistptr = weechat::infolist_get('perl_script', '', SCRIPT_NAME);
        my $filename = weechat::infolist_string($infolistptr, 'filename') if weechat::infolist_next($infolistptr);
        weechat::infolist_free($infolistptr);
        return $filename unless @_;
        my $sep = weechat::info_get('dir_separator', '');
        my @path = split $sep, $filename;
        my $link = readlink $filename;
        my @lpath = split $sep, $link if defined $link;
        (join '/', @path[0..$#path-1]),
        ($path[-2] eq 'autoload' ? join '/', @path[0..$#path-2] : ()),
        (@lpath ? join '/', ($lpath[0] ne '' ? @path[0..$#path-1] : ''), @lpath[0..$#lpath-1] : ()),
        (join '/', (split $sep, weechat::info_get('weechat_dir', '')), 'perl')
  }
  require lib; lib->import(&SCRIPT_FILE(1));
  require Nlib;

To use the functions provided herein, call them with Nlib::function_name parameters...

FUNCTION DESCRIPTION

for full pod documentation, filter this script with

  perl -pE'
  (s/^## (.*?) -- (.*)/=head2 $1\n\n$2\n\n=over\n/ and $o=1) or
   s/^## (.*?) - (.*)/=item I<$1>\n\n$2\n/ or
  (s/^## (.*)/=back\n\n$1\n\n=cut\n/ and $o=0,1) or
  ($o and $o=0,1 and s/^sub /=back\n\n=cut\n\nsub /)'

i2h

copy weechat infolist content into perl hash

$infolist

name of the infolist in weechat

$ptr

pointer argument (infolist dependend)

@args

arguments to the infolist (list dependend)

$fields

string of ref type "fields" if only certain keys are needed (optional)

returns perl list with perl hashes for each infolist entry

hdh

hdata helper

$_[0]

arg pointer or hdata list name

$_[1]

hdata name

$_[2..$#_]

hdata variable name

$_[-1]

hashref with key/value to update (optional)

returns value of hdata, and hdata name in list ctx, or number of variables updated

l2l

copy weechat list into perl list

$ptr

weechat list pointer

$clear

if true, clear weechat list

returns perl list

find_bar_window

find the bar window where the coordinates belong to

$row

row

$col

column

returns bar window infolist and bar infolist in a array ref if found

in_window

check if given coordinates are in a window

$row

row

$col

column

$wininfo

infolist of window to check

returns true if in window

in_chat_window

check if given coordinates are in the chat part of a window

$row

row

$col

column

$wininfo

infolist of window to check

returns true if in chat part of window

has_true_value

some constants for "true"

$v

value string

returns true if string looks like a true thing

has_false_value

some constants for "false"

$v

value string

returns true if string looks like a false thing

hook_dynamic

weechat::hook something and store hook reference

$hook_call

hook type (e.g. modifier)

$what

event type to hook (depends on $hook_call)

$sub

subroutine name to install

@params

parameters

unhook_dynamic

weechat::unhook something where hook reference has been stored with hook_dynamic

$what

event type that was hooked

$sub

subroutine name that was installed

bar_filling

get current filling according to position

$bar_infos

info about bar (from find_bar_window)

returns filling as an integer number

bar_column_max_length

get max item length for column based filling

$bar_infos

info about bar (from find_bar_window)

returns max item length

find_bar_item_pos

get position of an item in a bar structure

$bar_infos

instance and general info about bar (from find_bar_window)

$search

search pattern for item name

returns (outer position, inner position, true if found)

bar_line_wrap_horiz

apply linebreak for horizontal bar filling

$prefix_col_r

reference to column counter

$prefix_y_r

reference to row counter

$bar_infos

info about bar (from find_bar_window)

bar_lines_column_vert

count lines in column layout

$bar_infos

info about bar (from find_bar_window)

returns lines needed for columns_horizontal layout

bar_items_skip_to

skip several bar items on search for subitem position

$bar_infos

info about bar (from find_bar_window)

$search

patter of item to skip to

$col

pointer column

$row

pointer row

bar_item_get_subitem_at

extract subitem from a bar item at given coords

$bar_infos

info about bar

$search

search pattern for item whose subitems to get

$col

pointer column

$row

pointer row

returns error message, subitem index, subitem text

bar_item_get_item_and_subitem_at

gets item and subitem at position

$bar_infos

info about bar

$col

pointer column

$row

pointer row

returns generic item, error if outside subitem, index of subitem and text of subitem

get_desc_from_pod

return setting description from pod documentation

$file

filename with pod

$setting

name of setting

returns description as text

get_settings_from_pod

retrieve all settings in settings section of pod

$file

file with pod

returns list of all settings

mangle_man_for_wee

turn man output into weechat codes

@_

list of grotty lines that should be turned into weechat attributes

returns modified lines and modifies lines in-place

read_manpage

read a man page in weechat window

$file

file with pod

$name

buffer name