vitree.pl pl pm t #### # ViTree use warnings; use strict; use File::Find; use Win32::Process; use Time::HiRes qw(sleep); # get set of extensions to work with. my %extensions; @extensions{ @ARGV } = (); # Come up with a more or less unique gVim server name. my $seed = int( rand 1000 ); my $servername = GetServerName( $seed ); # Build a list of files to open. my @files; find( \&MatchFiles, '.' ); exit unless @files; # and open them. my $counter = 0; print "Opening files:\n"; foreach my $file ( @files ) { print "$counter\t$file\n"; my $ProcessObj; # I was using system(1,blah blah) but that maxed out at 64 files. # Process::Create seems to handle anything I throw at it. Win32::Process::Create( $ProcessObj, "C:/WINDOWS/gvim.BAT", qq(gvim --servername $servername --remote-silent "$file"), 0, NORMAL_PRIORITY_CLASS, "." ) || die ErrorReport(); # Waiting for a bit keeps files from disappearing. # Also prevents "Application failed to initialize" errors. if ( $counter++ ) { sleep(0.1); } else { # need to wait longer at the first invocation # otherwise we sometimes miss a file or two. sleep(1); } } # the "wanted" function for File::Find sub MatchFiles { no warnings 'uninitialized'; /\.(\w*)$/; my $ext = $1; return unless length $ext; push @files, $File::Find::name if exists $extensions{$ext}; } # I broke this out earlier when # I thought I needed to spawn # multiple gVim servers to work # around a limit in gVim. # # The problem is with windows, and # the work around is different, but # I never put this back. Damn lazy. sub GetServerName { my $seed = shift; my $time = time; return "$seed-$time"; } # Copied straight from the Win32::Process docs. sub ErrorReport { print Win32::FormatMessage( Win32::GetLastError() ); }