Ignore:
Timestamp:
03/15/10 04:51:54 (2 years ago)
Author:
azawawi
Message:

Perl tidy (25 files)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/Wx/Editor.pm

    r11106 r11120  
    4444# Brace* methods 
    4545# always altern opening and starting braces in the constant 
    46 my $BRACES = '{}[]()'; 
    47 my $STC_INVALID_POSITION =  Wx::wxSTC_INVALID_POSITION; 
     46my $BRACES               = '{}[]()'; 
     47my $STC_INVALID_POSITION = Wx::wxSTC_INVALID_POSITION; 
    4848 
    4949my $data; 
     
    169169# return the character at a given position as a perl string 
    170170sub get_character_at { 
    171     my ($self, $pos) = @_; 
     171    my ( $self, $pos ) = @_; 
    172172    return chr( $self->GetCharAt($pos) ); 
    173173} 
     
    424424 
    425425 
    426      
    427      
    428  
    429426 
    430427 
     
    456453 
    457454sub get_brace_info { 
    458     my ($self, $pos) = @_; 
     455    my ( $self, $pos ) = @_; 
    459456    $pos = $self->GetCurrentPos unless defined $pos; 
    460       
     457 
    461458    # try the after position first (default one for BraceMatch) 
    462459    my $is_after = 1; 
    463     my $brace = $self->get_character_at($pos); 
     460    my $brace    = $self->get_character_at($pos); 
    464461    my $is_brace = $self->get_brace_type($brace); 
    465     if (!$is_brace && $pos > 0) { # try the before position 
    466         $brace = $self->get_character_at(--$pos); 
    467         $is_brace  = $self->get_brace_type($brace) or return undef; 
     462    if ( !$is_brace && $pos > 0 ) { # try the before position 
     463        $brace    = $self->get_character_at( --$pos ); 
     464        $is_brace = $self->get_brace_type($brace) or return undef; 
    468465        $is_after = 0; 
    469466    } 
    470467    my $is_opening = $is_brace % 2; # odd values are opening 
    471     return [$pos, $brace, $is_after, $is_opening]; 
     468    return [ $pos, $brace, $is_after, $is_opening ]; 
    472469} 
    473470 
     
    485482 
    486483=cut 
     484 
    487485my %_cached_braces; 
     486 
    488487sub get_brace_type { 
    489     my ($self, $char) = @_; 
     488    my ( $self, $char ) = @_; 
    490489    unless (%_cached_braces) { 
    491490        my $i = 1; # start from one so that all values are true 
    492         $_cached_braces{$_} = $i++ foreach (split //, $BRACES); 
     491        $_cached_braces{$_} = $i++ foreach ( split //, $BRACES ); 
    493492    } 
    494493    my $v = $_cached_braces{$char} or return 0; 
     
    501500# {} : never highlighted 
    502501# { } : always correct 
    503 #  
    504502# 
     503# 
    505504 
    506505sub apply_style { 
    507     my ($self, $style_info) = @_; 
     506    my ( $self, $style_info ) = @_; 
    508507    my %previous_style = %$style_info; 
    509     $previous_style{style} = $self->GetStyleAt($style_info->{start}); 
    510      
     508    $previous_style{style} = $self->GetStyleAt( $style_info->{start} ); 
     509 
    511510    $self->StartStyling( $style_info->{start}, 0xFF ); 
    512511    $self->SetStyling( $style_info->{len}, $style_info->{style} ); 
    513      
     512 
    514513    return \%previous_style; 
    515514} 
     
    517516 
    518517my $previous_expr_hiliting_style; 
     518 
    519519sub highlight_braces { 
    520520    my ($self) = @_; 
    521      
     521 
    522522    my $expression_highlighting = $self->get_config->editor_brace_expression_highlighting; 
    523      
     523 
    524524    # remove current highlighting if any 
    525     $self->BraceHighlight( $STC_INVALID_POSITION, $STC_INVALID_POSITION  ); 
     525    $self->BraceHighlight( $STC_INVALID_POSITION, $STC_INVALID_POSITION ); 
    526526    if ($previous_expr_hiliting_style) { 
    527527        $self->apply_style($previous_expr_hiliting_style); 
    528528        $previous_expr_hiliting_style = undef; 
    529529    } 
    530      
    531     my $pos1 = $self->GetCurrentPos; 
    532     my $info1 = $self->get_brace_info($pos1) or return; 
     530 
     531    my $pos1          = $self->GetCurrentPos; 
     532    my $info1         = $self->get_brace_info($pos1) or return; 
    533533    my ($actual_pos1) = @$info1; 
    534      
     534 
    535535    my $actual_pos2 = $self->BraceMatch($actual_pos1); 
    536 #   return if abs( $pos1 - $pos2 ) < 2; 
     536 
     537    #   return if abs( $pos1 - $pos2 ) < 2; 
    537538 
    538539    return if $actual_pos2 == $STC_INVALID_POSITION; #Wx::wxSTC_INVALID_POSITION  #???? 
    539540 
    540541    $self->BraceHighlight( $actual_pos1, $actual_pos2 ); 
    541      
     542 
    542543    if ($expression_highlighting) { 
    543         my $pos2  = $self->find_matching_brace($pos1) or return; 
    544         my %style = (start => $pos1 < $pos2 ? $pos1 : $pos2,  
    545             len => abs($pos1-$pos2), style => Wx::wxSTC_STYLE_DEFAULT); 
    546         $previous_expr_hiliting_style = $self->apply_style(\%style); 
     544        my $pos2 = $self->find_matching_brace($pos1) or return; 
     545        my %style = ( 
     546            start => $pos1 < $pos2 ? $pos1 : $pos2, 
     547            len => abs( $pos1 - $pos2 ), style => Wx::wxSTC_STYLE_DEFAULT 
     548        ); 
     549        $previous_expr_hiliting_style = $self->apply_style( \%style ); 
    547550    } 
    548551 
     
    564567 
    565568=cut 
     569 
    566570sub find_matching_brace { 
    567     my ($self, $pos) = @_; 
     571    my ( $self, $pos ) = @_; 
    568572    $pos = $self->GetCurrentPos unless defined $pos; 
    569573    my $info1 = $self->get_brace_info($pos) or return; 
    570     my ($actual_pos1, $brace, $is_after, $is_opening) = @$info1; 
    571      
     574    my ( $actual_pos1, $brace, $is_after, $is_opening ) = @$info1; 
     575 
    572576    my $actual_pos2 = $self->BraceMatch($actual_pos1); 
    573577    return if $actual_pos2 == $STC_INVALID_POSITION; 
     
    587591 
    588592=cut 
     593 
    589594sub goto_matching_brace { 
    590     my ($self, $pos) = @_; 
    591     my $pos2  = $self->find_matching_brace($pos) or return; 
     595    my ( $self, $pos ) = @_; 
     596    my $pos2 = $self->find_matching_brace($pos) or return; 
    592597    $self->GotoPos($pos2); 
    593598} 
     
    606611 
    607612sub select_to_matching_brace { 
    608     my ($self, $pos) = @_; 
     613    my ( $self, $pos ) = @_; 
    609614    $pos = $self->GetCurrentPos unless defined $pos; 
    610     my $pos2  = $self->find_matching_brace($pos) or return; 
    611     my $start = ($pos < $pos2) ? $self->GetSelectionStart() : $self->GetSelectionEnd(); 
    612     $self->SetSelection($start, $pos2); 
    613          
    614 } 
    615          
     615    my $pos2 = $self->find_matching_brace($pos) or return; 
     616    my $start = ( $pos < $pos2 ) ? $self->GetSelectionStart() : $self->GetSelectionEnd(); 
     617    $self->SetSelection( $start, $pos2 ); 
     618 
     619} 
     620 
    616621# currently if there are 9 lines we set the margin to 1 width and then 
    617622# if another line is added it is not seen well. 
Note: See TracChangeset for help on using the changeset viewer.