[SVN] Request for additional input types

Brad Choate brad at bradchoate.com
Fri Feb 10 19:59:00 UTC 2006


Hey Allan,

I'm still working on my own version of "Reformat paragraph". The  
builtin version doesn't work quite like I want it to.  I was happy to  
find that when I assign ^Q to my command it does in fact override the  
Text menu command that had the same key assignment.

It works great when I have a selection.  When I don't, it processes  
the whole document.  That's not bad, but I think I would prefer that  
it process the current paragraph.  Now, I know-- I can just feed the  
whole document and use my command to "find" the current paragraph  
using the current line number.  But that's a lot of extra work.  What  
I would like is an "Input" choice on the bundle command dialog of  
"Current Paragraph". So I could say Input:  Selected Text or Current  
Paragraph.

And naturally, if it is configured to replace the text, it would  
replace that paragraph when returning the result.

Another input type I would love to see is "Scoped Text".  Lets say  
your command is relevant to a particular scope.  Maybe the scope is  
one of the SQL scopes that would identify a query string.  TextMate  
knows the bounds of that scope, so it could send the full query to  
the command.

-Brad

For fun, here's what I've got for my reformat paragraph command  
(requires the Text::Wrap Perl module which should be a standard  
module... at least it is for Tiger)...

----

#!/usr/bin/perl

use strict;
use Text::Wrap qw(wrap $columns $huge);

$huge = 'overflow';
$columns = $ENV{TM_COLUMNS} || 78;
$Text::Wrap::tabstop = $ENV{TM_TAB_SIZE} || 8;

my $count = 0;
sub wrappit {
	my ($p) = @_;
	my ($st) = $p =~ m/^(\s+)/s;
	$p =~ s/^\s+//;
	$st = '' unless defined $st;
	my $pfx;
	my $nx = $st;
	if ($p =~ m/^([-\*]\s+)/) {   #  *, - are recognized bullets
		$pfx = $1;
		$nx .= (' ') x length($pfx);
	} elsif ($p =~ m/^(\d+\.\s+)/) {   # n.  is recognized for lists
		$pfx = $1;
		$nx .= (' ') x length($pfx);
	}
	$p = wrap($st, $nx, $p);
	print "\n\n" if $count;
	print $p;
	$count++;
}

my $p = '';
my $st = '';
while (my $l = <>) {
	chomp $l;
	if ($l eq '') {
	    wrappit($p); $p = '';
	    next;
	}
	if ($p ne '') {
	    $l =~ s/^\s+//s;
	    $p .= ' ' . $l;
	} else {
		$p .= $l;
	}
}
wrappit($p);
print "\n" if $p ne '';




More information about the textmate-dev mailing list