Page 1 of 1

Find All command

Posted: Wed Dec 30, 2009 6:18 pm
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.

Posted: Thu Feb 25, 2010 8:33 pm
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".

Find all in current file

Posted: Thu Jun 03, 2010 12:30 pm
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");