dslinux/user/perl/emacs cperl-mode.el e2ctags.pl ptags

cayenne dslinux_cayenne at user.in-berlin.de
Mon Dec 4 17:59:05 CET 2006


Update of /cvsroot/dslinux/dslinux/user/perl/emacs
In directory antilope:/tmp/cvs-serv17422/emacs

Added Files:
	cperl-mode.el e2ctags.pl ptags 
Log Message:
Adding fresh perl source to HEAD to branch from

--- NEW FILE: cperl-mode.el ---
;;; cperl-mode.el --- Perl code editing commands for Emacs

;; Copyright (C) 1985, 86, 87, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2003
;;     Free Software Foundation, Inc.

;; Author: Ilya Zakharevich and Bob Olson
;; Maintainer: Ilya Zakharevich <cperl at ilyaz.org>
;; Keywords: languages, Perl

;; This file is part of GNU Emacs.

;;; This code started from the following message of long time ago
;;; (IZ), but Bob does not maintain this mode any more:

;;; From: olson at mcs.anl.gov (Bob Olson)
;;; Newsgroups: comp.lang.perl
;;; Subject: cperl-mode: Another perl mode for Gnuemacs
;;; Date: 14 Aug 91 15:20:01 GMT

[...8437 lines suppressed...]

(defun cperl-update-syntaxification (from to)
  (if (and cperl-use-syntax-table-text-property
	   cperl-syntaxify-by-font-lock
	   (or (null cperl-syntax-done-to)
	       (< cperl-syntax-done-to to)))
      (progn
	(save-excursion
	  (goto-char from)
	  (cperl-fontify-syntaxically to)))))

(defvar cperl-version
  (let ((v  "$Revision: 1.2 $"))
    (string-match ":\\s *\\([0-9.]+\\)" v)
    (substring v (match-beginning 1) (match-end 1)))
  "Version of IZ-supported CPerl package this file is based on.")

(provide 'cperl-mode)

;;; cperl-mode.el ends here

--- NEW FILE: e2ctags.pl ---

##e2ctags.pl
##Convert an Emacs-style TAGS file to a standard ctags file.
##Runs in a single pass over the TAGS file and keeps the first
##tag entry found, and the file name and line number the tag can
##be found on.
##Then it opens all relevant files and builds the regular expression
##for ctags.
##Run over a few test files and compared with a real ctags file shows
##only extra tags in the translated file, which probably won't hurt
##vi.
##

use strict;

my $filename;
my ($tag,$line_no,$line);
my %tags = ();
my %filetags = ();
my %files = ();
my @lines = ();

while (<>) {
  if ($_ eq "\x0C\n") {
    ##Grab next line and parse it for the filename
    $_ = <>;
    chomp;
    s/,\d+$//;
    $filename = $_;
    ++$files{$filename};
    next;
  }
  ##Figure out how many records in this line and
  ##extract the tag name and the line that it is found on
  next if /struct/;
  if (/\x01/) {
    ($tag,$line_no) = /\x7F(\w+)\x01(\d+)/;
  }
  else {
    tr/(//d;
    ($tag,$line_no) = /(\w+)\s*\x7F(\d+),/;
  }
  next unless $tag;
  ##Take only the first entry per tag
  next if defined($tags{$tag});
  $tags{$tag}{FILE} = $filename;
  $tags{$tag}{LINE_NO} = $line_no;
  push @{$filetags{$filename}}, $tag;
}

foreach $filename (keys %files) {
  open FILE, $filename or die "Couldn't open $filename: $!\n";
  @lines = <FILE>;
  close FILE;
  chomp @lines;
  foreach $tag ( @{$filetags{$filename}} ) {
    $line = $lines[$tags{$tag}{LINE_NO}-1];
    if (length($line) >= 50) {
      $line = substr($line,0,50);
    }
    else {
      $line .= '$';
    }
    $line =~ s#\\#\\\\#;
    $tags{$tag}{LINE} = join '', '/^',$line,'/';
  }
}

foreach $tag ( sort keys %tags ) {
  print "$tag\t$tags{$tag}{FILE}\t$tags{$tag}{LINE}\n";
}

--- NEW FILE: ptags ---
# Make a TAGS file for emacs ``M-x find-tag'' from all <c,h,y,xs> source files.
# (``make realclean'' first to avoid generated files, or ``make'' first
# to get tags from all files.)
#
#
# usage: sh emacs/ptags <options>
# 
# options:
#
# fullpath - use full paths in TAGS (default: relative to the root)
#
# (IZ: to be a happier jumper: install 'imenu-go.el' from
#      ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs.)
#
# (Some tags should probably live in their own subdirs, like those in x2p/,
# but I have never been interested in x2p anyway.)
#
# Hallvard B Furuseth <h.b.furuseth at usit.uio.no>, Aug -96.
#
# Ilya Zakharevich, Oct 97: minor comments, add CPerl scan;
#   Use Hallvard's scan for XS files - since he processes the "C" part too -
#   but with a lot of improvements: now it is no worse than CPerl's one.

# Avoid builtin on OS/2:
if test ! -z "$OS2_SHELL"; then alias find=gnufind; fi

case "$1" in
  fullpath)
    cwd=`pwd`
    cperl_add_tags='cperl-add-tags-recurse-noxs-fullpath'
    echo "Building TAGS with full paths"
  ;;
  *)
    cperl_add_tags='cperl-add-tags-recurse-noxs'
    cwd='.'
    echo "Building TAGS with relative paths"
esac

emacs=`(which emacs || which xemacs) 2>/dev/null`
[ -x "$emacs" ] || { echo "can't find emacs or xemacs in PATH"; exit 1; }

# Insure proper order (.h after .c, .xs before .c in subdirs):
# Move autogenerated less-informative files to the end:
# Hard to do embed.h and embedvar.h in one sweep:

topfiles="`echo ' ' *.y *.c *.h ' ' | sed 's/ /  /g' | sed 's/ embedvar\.h\|embed\.h\|perlapi\.h\|os2ish\.h\|\(globals\|perlapi\| os2\)\.c / /g'| sed "s#\(^\| \)\([^ ]\)#\1$cwd/\2#g"`"
subdirs="`find $cwd/* -maxdepth 0 -type d`"
subdirfiles="`find $subdirs -name '*.[cy]' -print | sort`"
subdirfiles1="`find $subdirs -name '*.[hH]' -print | sort`"
xsfiles="`find $cwd/ -name '*.xs' -print | sort`"

# etags -d : process defines too (default now)

# These are example lines for global variables and PP-code:
## IEXT SV *       Iparsehook;
## IEXT char *     Isplitstr IINIT(" ");
## dEXTCONST char rcsid[] = "perl.c\nPatch level: ###\n";
## PP(pp_const)
## PERLVARI(Grsfp, PerlIO *, Nullfp)
## PERLVAR(cvcache,      HV *)

# Putting PL_\1 in the substitution line makes etags dump core
# Thus we do it later (but 20.2.92 does it OK).
set x	-d -l c \
	-r '/[dI]?EXT\(CONST\)?[ \t*]+\([a-zA-Z_0-9]+[ \t*]+\)*\([a-zA-Z_0-9]+\)[ \t]*\($\|;\|\[\|[ \t]I+NIT[ \t]*(\|\/\*\)/\3/' \
	-r '/IEXT[ \t][^\/]*[ \t*]I\([a-zA-Z_][a-zA-Z_0-9]*\)[\[; \t]/\1/'  \
	-r '/PERLVAR[a-zA-Z_0-9]*[ \t]*([ \t]*[GIT]?\([a-zA-Z_][a-zA-Z_0-9]*\)[ \t]*[\[,]/\1/'  \
	-r '/PP[ \t]*([ \t]*\([^ \t()]*\)[ \t]*)/\1/'

shift

rm -f TAGS.tmp TAGS.tm2

# Process lines like this: #define MEM_ALIGNBYTES $alignbytes      /**/
etags -o TAGS.tmp \
	-l none -r '/#\(\$[a-zA-Z_0-9]+\|define\)[ \t]+\([a-zA-Z_0-9]+\)/\2/' \
	$cwd/config_h.SH
# Process lines like this: Mcc (Loc.U):
etags -o TAGS.tmp -a \
	-l none -r '/^\([a-zA-Z_0-9]+\)[ \t]+(/\$\1/' \
		-r '/^\([a-zA-Z_0-9]+\)[ \t]+(/\1/' $cwd/Porting/Glossary

etags -o TAGS.tmp -a "$@" $topfiles

# Now add these PL_:
perl -w014pe 'if (s/^( .* PERLVAR A?I?	# 1:   TAG group
		       \s* \( \s* [GIT] #
		       .*		#
		     \x7F		#      End of description
		     ) 
		     ( .* \x01 )	# 2:   Exact group
		   /${1}PL_$2/mgx) {	# Add PL_
		  $chars = chomp;
		  s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
		  $_ .= ("\f" x $chars);
	      }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp


# Now remove these Perl_, add empty- and perl_-flavors:
perl -w014pe 'if (s/^(Perl_		# 1:   First group
		       (\w+) \(		# 2:   Stripped name
		       \x7F		#      End of description
		     )			#      End of description
		     (\d+,\d+\n)	# 3:   TAGS Trail
		   /$1$3$1$2\x01$3$1perl_$2\x01$3/mgx) {	# Repeat, add empty and perl_ flavors
		  $chars = chomp;
		  s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
		  $_ .= ("\f" x $chars);
	      }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp

# Now remove these S_, add empty-flavor:
perl -w014pe 'if (s/^(S_		# 1:   First group
		       (\w+) \(		# 2:   Stripped name
		       \x7F		#      End of description
		     )			#      End of description
		     (\d+,\d+\n)	# 3:   TAGS Trail
		   /$1$3$1$2\x01$3/mgx) {	# Repeat, add empty_ flavor
		  $chars = chomp;
		  s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
		  $_ .= ("\f" x $chars);
	      }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp

etags -o TAGS.tmp -a -D -l none -r '/#define.*\t\(Perl_.*\)/\1/' $cwd/embed.h
etags -o TAGS.tmp -a $cwd/globals.c $cwd/embedvar.h $cwd/perlapi.c $cwd/perlapi.h

# The above processes created a lot of descriptions with an
# an explicitly specified tag.  Such descriptions have higher
# precedence than descriptions without an explicitely specified tag.
# To restore the justice, make all the descriptions explicit.
perl -w014pe 'if (s/^( [^\n\x7F\x01]*\b	# 1:   TAG group
	               (\w+)		#   2: word
		       [^\w\x7F\x01\n]*	#      Most anything
		       \x7F		#      End of description
		     )
		     (\d+,\d+\n)	# 3:   TAGS Trail
		   /$1$2\x01$3/mgx) {	# Add specific marking
		  $chars = chomp;
		  s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
		  $_ .= ("\f" x $chars);
	      }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp

# Add MODULE lines to TAG files (to be postprocessed later),
#   and BOOT: lines (in DynaLoader processed twice?)

# This skips too many XSUBs:

# etags -o TAGS.tmp -a -d -l c \
# 	-r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)\([ \t]*PREFIX[ \t]*=[ \t]*\([^ \t]+\)\)?/\2/' \
# 	-r '/[ \t]*BOOT:/' \
# 	$xsfiles

etags -o TAGS.tmp -a -d -l c \
	-r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)\([ \t]*PREFIX[ \t]*=[ \t]*\([^ \t]+\)\)?/\2/' \
	-r '/[ \t]*BOOT:/' \
	-r '/\([_a-zA-Z][a-zA-Z0-9_:]*\)(/' \
	$xsfiles

#	-r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)/\2/' \
#	-r '/MODULE.*PREFIX[ \t]*=[ \t]*\([^ \t]+\)/\1/'	\
#	$xsfiles

etags -o TAGS.tmp -a "$@" $subdirfiles
etags -o TAGS.tmp -a "$@" $subdirfiles1

if test ! -f emacs/cperl-mode.elc ; then
    ( cd emacs; $emacs -batch -q -no-site-file -f batch-byte-compile cperl-mode.el )
fi

# This should work with newer Emaxen

cp TAGS.tmp TAGS
if $emacs -batch -q -no-site-file -l emacs/cperl-mode.elc -f $cperl_add_tags ; then
    mv TAGS TAGS.tmp
fi

perl -w014pe '
    $update  = s/^PP\(\177\d+,\d+\n//gm;
    $update += s/^(I?EXT.*[ \t])IINIT[ \t]*\((\177)/$1$2/gm;
    if (/^\n*[^\s,]+\.xs,/s) {
	$mod = $cmod = $bmod = $pref = "";
	s/^(.*\n)\1+/$1/mg;			# Remove duplicate lines
	$_ = join("", map {
	    if (/^MODULE[ \t]*=[ \t]*(\S+)(?:[ \t]+PACKAGE[ \t]*=[ \t]*(\S+))?[ \t\177]/m) {
		$mod = $+;
		($bmod = $mod) =~ tr/:/_/;
		$cmod = "XS_${bmod}_";
		$pref = "";
		if (s/[ \t]+PREFIX[ \t]*=[ \t]*([^\s\177]+)(\177)/$+/) {
		    $pref = $1;
		    $pref =~ s/([^\w\s])/\\$1/g;
		    $pref = "(?:$pref)?";
		}
	    } elsif ($mod ne "") {
		# Ref points for Module::subr, XS_Module_subr, subr
		s/^($pref(\w+)[ \t()]*\177)(\d+,\d+)$/$1${mod}::${2}\01$3\n$1$2\01$3\n$1$cmod$2\01$3/gm;
		# Ref for Module::bootstrap bootstrap boot_Module
		s/^([ \t]*BOOT:\177)(\d+,\d+)$/$1${mod}::bootstrap\01$2\n${1}bootstrap\01$2\n${1}boot_$bmod\01$2/gm;
	    }
	    $_;
	} split(/(\nMODULE[ \t]*=[^\n\177]+\177)/));

	$update = 1;
    }
    if ($update) {
	$chars = chomp;
	s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
	$_ .= ("\f" x $chars);
    }' TAGS.tmp > TAGS.tm2

rm -f TAGS
mv TAGS.tm2 TAGS
rm -f TAGS.tmp







More information about the dslinux-commit mailing list