Article 11812 of comp.lang.perl: Path: feenix.metronet.com!news.utdallas.edu!wupost!howland.reston.ans.net!EU.net!Germany.EU.net!pki-nbg.philips.de!pki-nbg.philips.de!ln_smr From: Stephen Riehm Newsgroups: comp.lang.perl Subject: ptags - for those using vi. Date: 22 Mar 94 10:42:38 GMT Organization: Philips KOmmunikations Industrie AG Lines: 113 Message-ID: Reply-To: steve@dingbat.franken.de NNTP-Posting-Host: hitkw14.pki-nbg.philips.de I haven't seen many scripts posted lately, and here's one which I find quite useful, so here goes. BTW, is there a repository of scripts like this around somewhere?? (mail-ftp only please) This is a simple perl script to create a tags file for use with vi, (if you don't know what tags are, have a look at the :ta command, or ^] (not escape, ctrl-]) in vi for details) it really helps when you start dealing with larger scripts, and scripts which depend on .pl files etc. I'll probably add some features like a merge flag to merge the perl tags with whatever tags are already in the tags file, and possibly a flag to automatically create tags for all 'required' files aswell. Anyway, here's an early release. The manpage is of course included as part of the script :-). All comments greatfully accepted by me at steve@dingbat.franken.de Share and Enjoy Steve - hacking perl and quietly supporting Randal through his latest challenge --- cut here --- file: ~/scr/ptags #!/usr/local/bin/perl 'di'; 'ig00'; # # ptags: create a tags file for perl scripts # blats any existing tags file - cus I am too lazy to merge them yet # # obvious... :-) sub usage { print <<_EOUSAGE_ ; USAGE: $program [-v] [-t ] -v include variable definitions (variables mentioned at the start of a line) -t name of tags file to create (default is 'tags') list of files to scan for tags _EOUSAGE_ exit 0 } # # initialisations # ($program = $0) =~ s,.*/,,; require 'getopts.pl'; # # parse command line # &Getopts( "t:vw" ) || &usage(); $tags_file = $opt_t || 'tags'; $variable_tags = $opt_v; $allow_warnings = ! $opt_w; # # for each line of every file listed on the command line, look for a # 'sub' definition, or, if variables are wanted aswell, look for a # variable definition at the start of a line # while( <> ) { next unless /^sub\s+(\w+)/ || ( $variable_tags && /^[(\s]*[\$\@\%]{1}(\w+).*=/ ); chop; warn "$1 - duplicate ignored\n" if ( $tag_names{$1}++ || $tags{sprintf( "%s\t%s\t?^%s\$?\n", $1, $ARGV, $_ )}++ ) && $allow_warnings; } rename( "$tags_file", "$tags_file.bak" ); open( TAGS, "> $tags_file" ); foreach( sort( keys %tags ) ) { print TAGS; } close( TAGS ); exit 0; ############################################################ # The next few lines are legal in both Perl and Nroff! .00; 'di \" Finish diversion-previous line must be blank .nr nl 0-1 \" fake up transition to first page again .nr % 0 \" start at page 1 '; __END__ ##### From here on it's a standard manual page ##### .TH ptags 1 "NMS Utilities" .SH NAME ptags \- Create a tags file for Perl scripts. .SH SYNOPSIS .B ptags [\fI-v\fP] [\fI-t \fP] .SH DESCRIPTION .IP \fB-v\fP include variable definitions (variables mentioned at the start of a line) .IP "\fB-t \fP" name of tags file to create (default is 'tags') \fBPtags\fP scans the specified files for subroutines and possibly variable definitions, and creates a \fBvi\fP style tags file. .SH FILES .IP \fBtags\fP Tags file containing a sorted list of tags, one tag per line. The format is the same as that used by \fBvi\fP(1) .SH AUTHOR Stephen Riehm .br steve@dingbat.franken.de .SH "SEE ALSO" perl(1), ctags(1). Article 11820 of comp.lang.perl: Path: feenix.metronet.com!news.ecn.bgu.edu!usenet.ins.cwru.edu!howland.reston.ans.net!agate!boulder!wraeththu.cs.colorado.edu!tchrist From: Tom Christiansen Newsgroups: comp.lang.perl Subject: Re: ptags - for those using vi. Date: 22 Mar 1994 14:36:06 GMT Organization: University of Colorado, Boulder Lines: 41 Message-ID: <2mmvom$av8@lace.Colorado.EDU> References: Reply-To: tchrist@cs.colorado.edu (Tom Christiansen) NNTP-Posting-Host: wraeththu.cs.colorado.edu Originator: tchrist@wraeththu.cs.colorado.edu :-> In comp.lang.perl, steve@dingbat.franken.de writes: :This is a simple perl script to create a tags file for use with vi, :while( <> ) : { : next unless /^sub\s+(\w+)/ : || ( $variable_tags && /^[(\s]*[\$\@\%]{1}(\w+).*=/ ); : chop; : warn "$1 - duplicate ignored\n" : if ( $tag_names{$1}++ : || $tags{sprintf( "%s\t%s\t?^%s\$?\n", $1, $ARGV, $_ )}++ ) : && $allow_warnings; : } This might be better: /^\s*sub\s+(\w+('|::))?(\w+)/) I've always used this; yours is much more complete. #!/usr/local/bin/perl open(STDOUT, "| sort > tags"); while (<>) { chop; if (/^\s*sub\s+(\w+')?(\w+)/) { $func = $2; s,[\\\[\]/.*],\\$&,g; print "$func\t", $ARGV, "\t/^$_\$/\n"; } if (/^\s*(\w+):/) { $func = $1; s,[\\\[\]/.*],\\$&,g; print "$func\t", $ARGV, "\t/^$_\$/\n"; } } --tom -- Tom Christiansen tchrist@cs.colorado.edu "Will Hack Perl for Fine Food and Fun" Boulder Colorado 303-444-3212 Article 11863 of comp.lang.perl: Path: feenix.metronet.com!news.utdallas.edu!convex!cs.utexas.edu!howland.reston.ans.net!EU.net!Germany.EU.net!pki-nbg.philips.de!pki-nbg.philips.de!ln_smr From: Stephen Riehm Newsgroups: comp.lang.perl Subject: ptags v1.11 Date: 22 Mar 94 18:35:33 GMT Organization: Philips KOmmunikations Industrie AG Lines: 137 Message-ID: Reply-To: steve@dingbat.franken.de NNTP-Posting-Host: hitkw14.pki-nbg.philips.de Well it doesn't take long to get a responce around here!!! Tom Christiansen suggested a better regexp for catching packaged subroutines etc, which I have built in, I have also added a merge option, which is very quick (compared to what ctags does), and there's some extra version info in there now for future reference. If you want to add all the .pl stuff, you can call ptags like this: ptags my_file some_other_file /usr/local/lib/perl/*.pl or merge them with your existing tags file with ptags -m /usr/local/lib/perl/*.pl Enjoy! Steve steve@dingbat.franken.de --- cut here --- file: ~/scr/ptags #!/usr/local/bin/perl 'di'; 'ig00'; # # ptags: create a tags file for perl scripts # @id = split( ' ', '$Id: ptags,v 1.11 1994/03/22 18:34:33 ln_smr Exp $' ); $id[1] =~ s/,v//; # obvious... :-) sub usage { print <<_EOUSAGE_ ; USAGE: $program [-mvwV] [-t ] -m Merge with existing tags file. -t Name of tags file to create. (default is 'tags') -v Include variable definitions. (variables mentioned at the start of a line) -V Print version information. -w Suppress "duplicate tag" warnings. List of files to scan for tags. _EOUSAGE_ exit 0 } # # initialisations # ($program = $0) =~ s,.*/,,; require 'getopts.pl'; # # parse command line # &Getopts( "mt:vVw" ) || &usage(); $tags_file = $opt_t || 'tags'; $merge = $opt_m; $variable_tags = $opt_v; $allow_warnings = ! $opt_w; die "$id[1]: ($id[5]) Version: $id[2] $id[3] $id[4]\n" if $opt_V; if( $merge && open( TAGS, "< $tags_file" ) ) { while( ) { /^\S+/; $tags{$&} = $_; } close( TAGS ); } # # for each line of every file listed on the command line, look for a # 'sub' definition, or, if variables are wanted aswell, look for a # variable definition at the start of a line # while( <> ) { next unless /^\s*sub\s+(\w+('|::))?(\w+)/ || ( $variable_tags && /^(([(\s]*[\$\@\%]{1}(\w+).*=))/ ); chop; warn "$3 - duplicate ignored\n" if ( $new{$3}++ || !( $tags{$3} = sprintf( "%s\t%s\t?^%s\$?\n", $3, $ARGV, $_ ) ) ) && $allow_warnings; } rename( "$tags_file", "$tags_file.bak" ); open( TAGS, "> $tags_file" ); foreach( sort( keys %tags ) ) { print TAGS "$tags{$_}"; } close( TAGS ); ############################################################ # The next few lines are legal in both Perl and Nroff! .00; 'di \" Finish diversion-previous line must be blank .nr nl 0-1 \" fake up transition to first page again .nr % 0 \" start at page 1 '; __END__ ##### From here on it's a standard manual page ##### .TH ptags 1 "NMS Utilities" .SH NAME ptags \- Create a tags file for Perl scripts. .SH SYNOPSIS .B ptags [\fI-mvw\fP] [\fI-t \fP] .SH DESCRIPTION .IP \fB-m\fP Merge new tags with existing tags. Old tags that match new tags will be quietly overwritten, while new duplicated tags will generate warning messages. .IP "\fB-t \fP" Name of tags file to create. (default is 'tags') .IP \fB-v\fP Include variable definitions (variables mentioned at the start of a line) .IP \fB-V\fP Print version information. .IP \fB-w\fP Suppress "duplicate tag" warning messages. .PP \fBPtags\fP scans the specified files for subroutines and possibly variable definitions, and creates a \fBvi\fP style tags file. .SH FILES .IP \fBtags\fP Tags file containing a sorted list of tags, one tag per line. The format is the same as that used by \fBvi\fP(1) .SH AUTHOR Stephen Riehm .br steve@dingbat.franken.de .SH VERSION $Id: ptags,v 1.11 1994/03/22 18:34:33 ln_smr Exp $ .SH "SEE ALSO" perl(1), ctags(1). --- cut here ---