Changeset f3e44eb


Ignore:
Timestamp:
Dec 27, 2009, 3:15:19 PM (10 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.7, release-1.8, release-1.9
Children:
986c9b1
Parents:
c9bdb46
Message:
Add a command to count characters.

Includes an awful hack to correctly handle @-replies.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/BarnOwl/Module/Twitter.pm

    r40c9dac rf3e44eb  
    2626our @twitter_handles = ();
    2727our $default_handle = undef;
     28
     29our $prefix;
    2830
    2931my $desc = <<'END_DESC';
     
    282284);
    283285
     286BarnOwl::new_command('twitter-count-chars' => \&cmd_count_chars, {
     287    summary     => 'Count the number of characters in the edit window',
     288    usage       => 'twitter-count-chars',
     289    description => <<END_DESCRIPTION
     290Displays the number of characters entered in the edit window so far. Correctly
     291takes into account any \@user prefix that will be added by the Twitter plugin.
     292END_DESCRIPTION
     293   });
     294
     295
    284296sub cmd_twitter {
    285297    my $cmd = shift;
     
    292304        }
    293305    }
     306    undef $prefix;
    294307    BarnOwl::start_edit_win("What's happening?" . (defined $account ? " ($account)" : ""), sub{twitter($account, shift)});
    295308}
     
    300313    die("Usage: $cmd USER\n") unless $user;
    301314    my $account = find_account_default(shift);
     315    undef $prefix;
    302316    BarnOwl::start_edit_win("$cmd $user " . ($account->nickname||""),
    303317                            sub { $account->twitter_direct($user, shift) });
     
    310324    my $account = find_account_default(shift);
    311325
     326    $prefix = "@\$user ";
    312327    BarnOwl::start_edit_win("Reply to \@" . $user . ($account->nickname ? (" on " . $account->nickname) : ""),
    313328                            sub { $account->twitter_atreply($user, $id, shift) });
     
    342357}
    343358
     359use BarnOwl::Editwin qw(:all);
     360sub cmd_count_chars {
     361    my $cmd = shift;
     362    my $text = save_excursion {
     363        move_to_buffer_start();
     364        set_mark();
     365        move_to_buffer_end();
     366        get_region();
     367    };
     368    my $len = length($text);
     369    $len += length($prefix) if $prefix;
     370    BarnOwl::message($len);
     371    return $len;
     372}
     373
    344374BarnOwl::filter(qw{twitter type ^twitter$});
    345375
Note: See TracChangeset for help on using the changeset viewer.