Changeset 2153


Ignore:
Timestamp:
12/21/08 23:19:47 (3 years ago)
Author:
azawawi
Message:

Code cleanup: Trim trailing spaces and tabs to space

Location:
trunk/Padre-Plugin-Perl6/lib/Padre
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre-Plugin-Perl6/lib/Padre/Document/Perl6.pm

    r2118 r2153  
    1818# Naive way to parse and colorize perl6 files 
    1919sub colorize { 
    20     my ($self, $first) = @_; 
     20    my ($self, $first) = @_; 
    2121 
    22     my $editor = $self->editor; 
    23     my $text   = $self->text_get; 
    24    
     22    my $editor = $self->editor; 
     23    my $text   = $self->text_get; 
     24 
    2525  my $t0 = Benchmark->new; 
    2626  my $p = Syntax::Highlight::Perl6->new( 
    2727    text => $text, 
    2828  ); 
    29    
     29 
    3030  my @tokens; 
    3131 
    32     eval { 
    33     @tokens = $p->tokens; 
     32    eval { 
     33    @tokens = $p->tokens; 
    3434  1; 
    35     }; 
    36      
    37     if($EVAL_ERROR) { 
    38         say "Parsing error, bye bye ->colorize"; 
    39         return; 
    40     } 
    41      
    42     $self->remove_color; 
    43      
     35    }; 
     36 
     37    if($EVAL_ERROR) { 
     38        say "Parsing error, bye bye ->colorize"; 
     39        return; 
     40    } 
     41 
     42    $self->remove_color; 
     43 
    4444  my %colors = ( 
    45         'comp_unit'  => Px::PADRE_BLUE,  
    46         'scope_declarator' => Px::PADRE_RED, 
    47         'routine_declarator' => Px::PADRE_RED, 
    48         'regex_declarator' => Px::PADRE_RED, 
    49         'package_declarator' => Px::PADRE_RED, 
    50         'statement_control' => Px::PADRE_RED, 
    51         'block' => Px::PADRE_BLACK, 
    52         'regex_block' => Px::PADRE_BLACK, 
    53         'noun' => Px::PADRE_BLACK, 
    54         'sigil' => Px::PADRE_GREEN, 
    55         'variable' => Px::PADRE_GREEN,  
    56         'assertion' => Px::PADRE_GREEN, 
    57         'quote' => Px::PADRE_MAGENTA, 
    58         'number' => Px::PADRE_ORANGE, 
    59         'infix' => Px::PADRE_DIM_GRAY, 
    60         'methodop' => Px::PADRE_BLACK, 
    61         'pod_comment' => Px::PADRE_GREEN, 
    62         'param_var' => Px::PADRE_CRIMSON, 
    63         '_scalar' => Px::PADRE_RED, 
    64         '_array' => Px::PADRE_BROWN, 
    65         '_hash' => Px::PADRE_ORANGE, 
    66         '_comment' => Px::PADRE_GREEN, 
     45        'comp_unit'  => Px::PADRE_BLUE, 
     46        'scope_declarator' => Px::PADRE_RED, 
     47        'routine_declarator' => Px::PADRE_RED, 
     48        'regex_declarator' => Px::PADRE_RED, 
     49        'package_declarator' => Px::PADRE_RED, 
     50        'statement_control' => Px::PADRE_RED, 
     51        'block' => Px::PADRE_BLACK, 
     52        'regex_block' => Px::PADRE_BLACK, 
     53        'noun' => Px::PADRE_BLACK, 
     54        'sigil' => Px::PADRE_GREEN, 
     55        'variable' => Px::PADRE_GREEN, 
     56        'assertion' => Px::PADRE_GREEN, 
     57        'quote' => Px::PADRE_MAGENTA, 
     58        'number' => Px::PADRE_ORANGE, 
     59        'infix' => Px::PADRE_DIM_GRAY, 
     60        'methodop' => Px::PADRE_BLACK, 
     61        'pod_comment' => Px::PADRE_GREEN, 
     62        'param_var' => Px::PADRE_CRIMSON, 
     63        '_scalar' => Px::PADRE_RED, 
     64        '_array' => Px::PADRE_BROWN, 
     65        '_hash' => Px::PADRE_ORANGE, 
     66        '_comment' => Px::PADRE_GREEN, 
    6767  ); 
    6868  for my $htoken (@tokens) { 
     
    7676    } 
    7777  } 
    78    
     78 
    7979  my $td = timediff(new Benchmark, $t0); 
    80   say "->colorize took:" . timestr($td) ;   
     80  say "->colorize took:" . timestr($td) ; 
    8181} 
    8282 
    8383sub get_command { 
    84     my $self     = shift; 
    85      
    86     my $filename = $self->filename; 
     84    my $self     = shift; 
    8785 
    88     if (not $ENV{PARROT_PATH}) { 
    89         die "PARROT_PATH is not defined. Need to point to trunk of Parrot SVN checkout.\n"; 
    90     } 
    91     my $parrot = File::Spec->catfile($ENV{PARROT_PATH}, 'parrot'); 
    92     if (not -x $parrot) { 
    93         die "$parrot is not an executable.\n"; 
    94     } 
    95     my $rakudo = File::Spec->catfile($ENV{PARROT_PATH}, 'languages', 'perl6', 'perl6.pbc'); 
    96     if (not -e $rakudo) { 
    97         die "Cannot find Rakudo ($rakudo)\n"; 
    98     } 
     86    my $filename = $self->filename; 
    9987 
    100     return qq{"$parrot" "$rakudo" "$filename"}; 
     88    if (not $ENV{PARROT_PATH}) { 
     89        die "PARROT_PATH is not defined. Need to point to trunk of Parrot SVN checkout.\n"; 
     90    } 
     91    my $parrot = File::Spec->catfile($ENV{PARROT_PATH}, 'parrot'); 
     92    if (not -x $parrot) { 
     93        die "$parrot is not an executable.\n"; 
     94    } 
     95    my $rakudo = File::Spec->catfile($ENV{PARROT_PATH}, 'languages', 'perl6', 'perl6.pbc'); 
     96    if (not -e $rakudo) { 
     97        die "Cannot find Rakudo ($rakudo)\n"; 
     98    } 
     99 
     100    return qq{"$parrot" "$rakudo" "$filename"}; 
    101101 
    102102} 
    103103 
    104104sub keywords { 
    105     if (! defined $keywords) { 
    106         $keywords = YAML::Tiny::LoadFile( 
    107             Padre::Util::sharefile( 'languages', 'perl6', 'perl6.yml' ) 
    108         ); 
    109     } 
    110     return $keywords; 
     105    if (! defined $keywords) { 
     106        $keywords = YAML::Tiny::LoadFile( 
     107            Padre::Util::sharefile( 'languages', 'perl6', 'perl6.yml' ) 
     108        ); 
     109    } 
     110    return $keywords; 
    111111} 
    112112 
  • trunk/Padre-Plugin-Perl6/lib/Padre/Plugin/Perl6.pm

    r2152 r2153  
    2828 
    2929sub padre_interfaces { 
    30     return 'Padre::Plugin'         => 0.20, 
     30    return 'Padre::Plugin'         => 0.20, 
    3131} 
    3232 
    3333 
    3434sub menu_plugins_simple { 
    35     my $self = shift; 
    36     return 'Perl 6' => [ 
    37         'Export Full HTML' => sub { $self->export_html($FULL_HTML); }, 
    38         'Export Simple HTML' => sub { $self->export_html($SIMPLE_HTML); }, 
    39         'Export Snippet HTML' => sub { $self->export_html($SNIPPET_HTML); }, 
    40         'About' => sub { $self->show_about }, 
    41     ]; 
     35    my $self = shift; 
     36    return 'Perl 6' => [ 
     37        'Export Full HTML' => sub { $self->export_html($FULL_HTML); }, 
     38        'Export Simple HTML' => sub { $self->export_html($SIMPLE_HTML); }, 
     39        'Export Snippet HTML' => sub { $self->export_html($SNIPPET_HTML); }, 
     40        'About' => sub { $self->show_about }, 
     41    ]; 
    4242} 
    4343 
    4444sub registered_documents { 
    45     return 'application/x-perl6'    => 'Padre::Document::Perl6', 
     45    return 'application/x-perl6'    => 'Padre::Document::Perl6', 
    4646} 
    4747 
    4848 
    4949sub show_about { 
    50     my ($main) = @ARG; 
     50    my ($main) = @ARG; 
    5151 
    52     my $about = Wx::AboutDialogInfo->new; 
    53     $about->SetName("Padre::Plugin::Perl6"); 
    54     $about->SetDescription( 
    55         "Perl6 syntax highlighting that is based on\nSyntax::Highlight::Perl6\n" 
    56     ); 
    57     Wx::AboutBox( $about ); 
    58     return; 
     52    my $about = Wx::AboutDialogInfo->new; 
     53    $about->SetName("Padre::Plugin::Perl6"); 
     54    $about->SetDescription( 
     55        "Perl6 syntax highlighting that is based on\nSyntax::Highlight::Perl6\n" 
     56    ); 
     57    Wx::AboutBox( $about ); 
     58    return; 
    5959} 
    6060 
    6161sub export_html { 
    62     my ($self, $type) = @ARG; 
     62    my ($self, $type) = @ARG; 
    6363 
    64     if(!defined Padre::Documents->current) { 
    65         return; 
    66     } 
     64    if(!defined Padre::Documents->current) { 
     65        return; 
     66    } 
    6767 
    68     my $text = Padre::Documents->current->text_get() // ''; 
     68    my $text = Padre::Documents->current->text_get() // ''; 
    6969 
    7070    my $p = Syntax::Highlight::Perl6->new( 
    7171        text => $text, 
    72         inline_resources => 1,  
     72        inline_resources => 1, 
    7373    ); 
    7474 
    7575    my $html; 
    7676    eval { 
    77         given($type) { 
    78             when ($FULL_HTML) { $html = $p->full_html; } 
    79             when ($SIMPLE_HTML) { $html = $p->simple_html; } 
    80             when ($SNIPPET_HTML) { $html = $p->snippet_html; } 
    81             default { 
    82                 croak "'$type' should full_html, simple_html or snippet_html"; 
    83             } 
    84         } 
    85         1; 
    86     }; 
     77        given($type) { 
     78            when ($FULL_HTML) { $html = $p->full_html; } 
     79            when ($SIMPLE_HTML) { $html = $p->simple_html; } 
     80            when ($SNIPPET_HTML) { $html = $p->snippet_html; } 
     81            default { 
     82                croak "'$type' should full_html, simple_html or snippet_html"; 
     83            } 
     84        } 
     85        1; 
     86    }; 
    8787 
    88     if($EVAL_ERROR) { 
    89         say 'Parsing error, bye bye ->export_html'; 
    90         return; 
    91     } 
     88    if($EVAL_ERROR) { 
     89        say 'Parsing error, bye bye ->export_html'; 
     90        return; 
     91    } 
    9292 
    93     # create a temporary HTML file 
    94     my $tmp = File::Temp->new(SUFFIX => '.html'); 
    95     $tmp->unlink_on_destroy(0); 
    96     my $filename = $tmp->filename; 
    97     print $tmp $html; 
    98     close $tmp 
    99         or croak "Could not close $filename"; 
     93    # create a temporary HTML file 
     94    my $tmp = File::Temp->new(SUFFIX => '.html'); 
     95    $tmp->unlink_on_destroy(0); 
     96    my $filename = $tmp->filename; 
     97    print $tmp $html; 
     98    close $tmp 
     99        or croak "Could not close $filename"; 
    100100 
    101     # try to open the HTML file 
    102     my $main   = Padre->ide->wx->main_window; 
    103     $main->setup_editor($filename); 
     101    # try to open the HTML file 
     102    my $main   = Padre->ide->wx->main_window; 
     103    $main->setup_editor($filename); 
    104104 
    105     # launch the HTML file in your default browser 
    106     my $file_url = URI::file->new($filename); 
    107     Wx::LaunchDefaultBrowser($file_url); 
    108      
     105    # launch the HTML file in your default browser 
     106    my $file_url = URI::file->new($filename); 
     107    Wx::LaunchDefaultBrowser($file_url); 
     108 
    109109    return; 
    110110} 
Note: See TracChangeset for help on using the changeset viewer.