Find All command

Ideas for new features

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
dag20k
Posts: 1
Joined: Wed Dec 30, 2009 5:33 pm
Location: United States

Find All command

Post by dag20k »

I would like a "Find All" command that will put all the lines with a the searched text found in a seperate window, like "Search Results", maybe call it "Find Results". And by clicking the lines in the Find Results window the Text Editor will go to that line for editing.
Thanks,
David A. Green
User avatar
kengrubb
Posts: 324
Joined: Thu Dec 11, 2003 5:23 pm
Location: Olympia, WA, USA

Post by kengrubb »

As a workaround, do a "Find In Files".

Click "Defaults" which selects the current folder.

Click the contents of "In files", then "Browse" to the current file.

I too would like to see a "Find In Current File" option which could be a simplified clone of "Find In Files".
(2[Bb]|[^2].|.[^Bb])

That is the question.
polebridge
Posts: 8
Joined: Thu Jun 03, 2010 12:21 pm
Location: A2, Mi, US

Find all in current file

Post by polebridge »

If you have perl installed then this following script will work. It will find all instances of the selected text in the current file.

#
# TP-Find-All-In-Current-File.pl
#
# Purpose: TextPad tool to FindAll in current file for the current selected text
# This is like the built-in TextPad Find-In-Files, but limited to current file.
# It produces a new window with the results of the find operation. You click
# on a line in that window to go to to the line and column in the file.
#
# Requirements: perl
#
# Caution: TextPad automatically saves the current file before running the tool. That's good
# because you can search the most up-to-date version, but bad because you may
# not have been ready to save intermediate edits.
#
# Notes: 1) Currently this tool does not allow you to regex search. In the next incarnation
# in might pop-up a "Find what:" box to allow you to provide a regex search string.
# 2) The search is case insensitive
# 3) The final "$nFound matches" lies! It is actually number of lines.
# 4) bug: won't find patterns containing " quotation mark
#
# TextPad configuration:
# Put this file on your path to allow the perl -S option to find it.
# Or under the TextPad installation directory and use the fully qual'ed form.
# Then, in TextPad:
# Configure / Preferences / Tools / Add / DOS Command
# DOS command:
# perl -S TP-Find-All-In-Current-File.pl "$File" "$SelWord" "$Line"
# (or perl "c:\Program Files\TextPad 4\bin\TP-Find-All-In-Current-File.pl" "$File" "$SelWord" "$Line" )
# Capture output, Regex should be (depending on whether you have default or POSIX RE's):
# ^([0-9]+):([0-9]+): or ^\([0-9]+\):\([0-9]+\):
# Set Line to 1, and Col to 2, leave File blank
#
# rjm June 2008
# 10jul08 rjm - added * to show the current line, the one you started on. Handy to get back.
# 03jun10 rjm - fixed install comments, \Q the pattern to find special chars
#==================================================================================================+

use strict;

my $filename = $ARGV[0]; # the name of the file we're in
my $selection = $ARGV[1]; # the selected text we're looking for
my $inline = $ARGV[2]; # the line number where the text was selected

#($!=0,die "Selection is empty or whitespace (Select some text and try again).\n") if ($selection =~ /^\s*$/ );
if ($selection =~ /^\s*$/ ) {
print "Selection is empty or whitespace (Select some text and try again).\n";
exit 0;
}
else {
print "$filename\n";
print "Searching for \"$selection\" (file $filename line $inline)\n";
print "\n";
}

open (INFILE, "<$filename") || die "Failed to open file '$filename'";
my @lines = (<INFILE>);
close INFILE;

my $linenum = 1;
my $colnum;
my $nFound=0;
my $line;
foreach $line (@lines) {
if ( $line =~ /\Q${selection}/gi ) {
$colnum = length($`) + 1; # the len of the $PREMATCH is also the colnum, yes?
my $lincol = sprintf( "%04u:%03u:%s", $linenum, $colnum, ($linenum==$inline? "*" : " ") );
print "$lincol $line"; # $line already has a \n
++$nFound;
}
$linenum = $linenum + 1;
}

print ("\nFound $nFound matches for \"$selection\"\n");
Post Reply