TextMate::JumpTo - Tell TextMate to jump to a particular file, line


TextMate-JumpTo documentation Contained in the TextMate-JumpTo distribution.

Index


Code Index:

NAME

Top

TextMate::JumpTo - Tell TextMate to jump to a particular file, line

VERSION

Top

This document describes TextMate::JumpTo version 0.07

SYNOPSIS

Top

    use TextMate::JumpTo qw(jumpto tm_location);

    jumpto( file => 'mysrc.pl', line => 123 );

    my $textmate_link = tm_location( file => 'foo.t', line => 12 );

DESCRIPTION

Top

On Mac OS The TextMate editor handles urls of the form

    txmt://open?url=file://somefile.pl&line=100

which cause it to jump to the file, line and column specified by the arguments. This module is a simple wrapper which uses the Mac OS 'open' command to send TextMate to the specified location.

I use it in my ~/.perldb to have TextMate track the current debugger position. Here's what it looks like:

    $ cat ~/.perldb
    use TextMate::JumpTo qw(jumpto);
    use File::Spec;

    sub afterinit {
        $trace |= 4;    # Enable watchfunction

        # Needed to work out where filenames are relative to
        chomp( $base_dir = `pwd` );

        $option{animate} = 0;
        push @options, 'animate';
    }

    sub watchfunction {
        my ( $package, $file, $line ) = @_;
        return unless $DB::single || $option{animate};
        local $trace = 0;
        if ( $file =~ /^\(eval\s+\d+\)\[(.+?):(\d+)\]/ ) {
            $file = $1;
            $line += $2 - 1;
        }
        $file = File::Spec->rel2abs( $file, $base_dir );
        jumpto( file => $file, line => $line, bg => 1 );
        return 1;
    }

INTERFACE

Top

jumpto

Instruct TextMate to jump to the specified file, line and column. The arguments are a list of key, value pairs:

    jumpto( file => 'splendid.pl', line => 12, column => 3 );

Possible arguments are:

file

The path to the file to go to.

line

The (one based) line number to go to.

column

The (one based) column to go to.

bg

True to leave TextMate in the background. By default a call to jumpto will bring TextMate to the foreground.

tm_location

Get a URL using the txmt: scheme that jumps to the specified location. Arguments as for jumpto with the exeception of the bg switch which makes no sense in this context.

    my $loc = tm_location( file => 'humbile.pm', line => 42 );

CONFIGURATION AND ENVIRONMENT

Top

TextMate::JumpTo requires no configuration files or environment variables.

DEPENDENCIES

Top

None.

INCOMPATIBILITIES

Top

None reported.

BUGS AND LIMITATIONS

Top

No bugs have been reported.

Please report any bugs or feature requests to bug-textmate-jumpto@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

Top

Andy Armstrong <andy@hexten.net>

LICENCE AND COPYRIGHT

Top


TextMate-JumpTo documentation Contained in the TextMate-JumpTo distribution.
package TextMate::JumpTo;

use warnings;
use strict;
use HTML::Tiny;
use File::Spec;
use Carp;

use base qw(Exporter);

our @EXPORT_OK = qw(jumpto tm_location);

our $VERSION = '0.07';

sub jumpto {
    croak "Odd number of args, needs a list of key => value pairs"
      if @_ % 2;
    my %args = @_;
    my $bg   = delete $args{bg};
    _open( tm_location( %args ), $bg );
}

# Open a URL on Mac OS.
sub _open {
    my ( $url, $bg ) = @_;
    croak "TextMate only runs on Mac OS"
      unless $^O =~ /darwin/;
    my @cmd = ( '/usr/bin/open', ( $bg ? ( '-g' ) : () ), $url );
    system @cmd and croak "Can't open $url ($?)";
}

sub tm_location {
    croak "Odd number of args, needs a list of key => value pairs"
      if @_ % 2;
    my %args = @_;
    croak "You must supply one or more of file, line, column"
      unless grep defined $args{$_}, qw(file line column);
    if ( my $file = delete $args{file} ) {
        $args{url} = "file://" . File::Spec->rel2abs( $file );
    }
    return 'txmt://open?' . HTML::Tiny->new->query_encode( \%args );
}

1;
__END__