Padre::Plugin::Autoformat - Reformats your text within Padre


Padre-Plugin-Autoformat documentation Contained in the Padre-Plugin-Autoformat distribution.

Index


Code Index:

NAME

Top

Padre::Plugin::Autoformat - Reformats your text within Padre

VERSION

Top

version 1.22

SYNOPSIS

Top

    $ padre
    Ctrl+Shift+J

DESCRIPTION

Top

This plugin allows one to reformat her text automatically with Ctrl+Shift+J. It is using Text::Autoformat underneath, so check this module's pod for more information.

PUBLIC METHODS

Top

Standard Padre::Plugin API

Padre::Plugin::Autoformat defines a plugin which follows Padre::Plugin API. Refer to this module's documentation for more information.

The following methods are implemented:

padre_interfaces()
plugin_icon()
plugin_name()

Formatting methods

* autoformat()

Replace the current selection with its autoformatted content.

BUGS

Top

Please report any bugs or feature requests to padre-plugin-autoformat at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Padre-Plugin-Autoformat. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SEE ALSO

Top

Plugin icon courtesy of Mark James, at http://www.famfamfam.com/lab/icons/silk/.

You can also look for information on this module at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Padre-Plugin-Autoformat

* CPAN Ratings

http://cpanratings.perl.org/d/Padre-Plugin-Autoformat

* Open bugs

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Padre-Plugin-Autoformat

AUTHORS

Top

COPYRIGHT AND LICENSE

Top


Padre-Plugin-Autoformat documentation Contained in the Padre-Plugin-Autoformat distribution.

package Padre::Plugin::Autoformat;
BEGIN {
  $Padre::Plugin::Autoformat::VERSION = '1.22';
}

# ABSTRACT: Reformats your text within Padre

use strict;
use warnings;

use File::Basename        qw{ fileparse };
use File::Spec::Functions qw{ catfile };
use base qw{ Padre::Plugin };

# -- padre plugin api, refer to Padre::Plugin

# plugin name
sub plugin_name { 'Autoformat' }

# plugin icon
sub plugin_icon {
    # find icon path using Padre API
    my $dir = File::Spec->catdir( Padre::Util::share('Autoformat'), 'icons' );
    my $icon_file = File::Spec->catfile( $dir, 'justify.png' );

    # create and return icon
    return Wx::Bitmap->new( $icon_file, Wx::wxBITMAP_TYPE_PNG );
}

# padre interfaces
sub padre_interfaces {
    'Padre::Plugin'     => 0.68,
    'Padre::Wx::Editor' => 0.30,
}

# plugin menu.
sub menu_plugins_simple {
    my ($self) = @_;
    Wx::gettext('Autoformat') => [
        #'About'                    => 'show_about',
        Wx::gettext("Autoformat\tCtrl+Shift+J") => 'autoformat',
    ];
}


# -- public methods

sub autoformat {
    my ($self) = @_;

    my $main     = $self->main;
    my $current  = $main->current;
    my $document = $current->document;
    my $editor   = $current->editor;
    return unless $editor;

    # no selection means autoformat current paragraph
    if ( not $editor->GetSelectedText ) {
        my ($b, $e) = $editor->current_paragraph;
        return if $b == $e; # in between paragraphs
        $editor->SetSelection($b, $e);
    }

    require Text::Autoformat;
    my $messy  = $editor->GetSelectedText;
    my $tidied = Text::Autoformat::autoformat($messy);
    $editor->ReplaceSelection($tidied);
}




1;



__END__