[m-dev.] for review: changes to mtags

David Overton dmo at cs.mu.OZ.AU
Mon Dec 4 15:20:39 AEDT 2000


Hi,

Does anyone have any objections to the following changes?

Estimated hours taken: 3

scripts/mtags:
	Modify the options to mtags to make them more complete and to
	simplify the implementation.  There are now three orthogonal
	low-level options (`--keep-duplicates', `--search-definitions'
	and `--extended-attributes') and several high-level options
	(`--emacs', `--vim', `--elvis', `--traditional-vi', and
	`--simple') which set combinations of low-level options
	appropriate for various editors.

	Also, make `--vim' the default option.  This creates a tags
	file which allows vim to make use of its extended
	tags-handling facilities while remaining backwards compatible
	with vi.  (You can still achieve the old default behaviour by
	specifying `--traditional-vi' if you want.)

Index: mtags
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mtags,v
retrieving revision 1.24
diff -u -r1.24 mtags
--- mtags	2000/12/04 02:10:55	1.24
+++ mtags	2000/12/04 04:07:39
@@ -27,22 +27,81 @@
 	files.
 
 Options:
-	With no options specified, mtags defaults to creating a vi-style 
-	tags file.  If multiple identical tags are found, only the first
-	occurrence of the tag is placed in the tags file.
+	With no options specified, mtags defaults to creating a vim-style 
+	tags file.  This file format is backwards compatible with vi,
+	but tags contain extra attributes that are used by vim.
+	Duplicate tags are not removed.
 
 	-e, --emacs
-		Produce an emacs-style TAGS file.
+		Produce an emacs-style TAGS file.  If this option is
+		present, all other options are ignored.
 
-	--vim
+	--vim, --ext
+		This option is the default, but is retained for
+		backwards compatibility.
+
+		This option is shorthand for `--keep-duplicates
+		--search-definitions --vim-extended-attributes'.
+
+	--elvis
+		Produces an extended tags file in a format that will
+		work with elvis 2.1+.
+
+		This option is shorthand for `--keep-duplicates
+		--no-search-definitions --elvis-extended-attributes'.
+
+	--traditional-vi
+		Produces a tags file that contains only information
+		useful for traditional vi.  This was the default in
+		previous versions of mtags, but is no longer since
+		vim-style tags files are backwards compatible with vi.
+		You may want to use this option if you only use vi and
+		you want to reduce the size of the tags file.
+		However, we suggest you investigate vim since it's
+		tags support is far superior for languages such as
+		Mercury which support overloading.
+
+		This option is shorthand for `--no-keep-duplicates
+		--search-definitions --no-extended-attributes'.
+
+	--simple
 		Produce a dumbed-down vi-style tags file that will work 
 		with versions of vim prior to 5.0, and versions of elvis
-		prior to 2.1.
+		prior to 2.1.  These versions cannot handle multiple
+		commands for a tag.
+
+		This option is shorthand for `--keep-duplicates
+		--no-search-definitions --no-extended-attributes'.
 
-	--ext
-		Produce a tags file in the extended format supported by 
-		vim 5.0+.  Duplicate tags are allowed in the tags file.
-		Extra attributes are added to each tag to say whether it
+	--keep-duplicates
+		Allow multiple definitions for a tag.
+		This option is the default, but is retained for
+		backwards compatibility.
+
+	--no-keep-duplicates.
+		If a tag has multiple definitions, ignore all but the
+		first.  Also ignores typeclass instance tags.
+
+	--search-definitions
+		This option is on by default.
+		Output extra ex commands which place the tag in
+		the search buffer to allow the definition to be found
+		by pressing `n' after a tag lookup.  For predicate and
+		function declarations this will attempt to find the
+		clauses by searching for occurrences of the tag at the
+		start of a line.  For other declarations, just the tag
+		itself will be placed in the search buffer.
+
+	--no-search-definitions
+		Do not output extra commands to allow searching for
+		definitions.
+
+	--no-extended-attributes
+		Do not output the extra tag attributes for vim/elvis.
+
+	--extended-attributes, --vim-extended-attributes
+		This option is the default.
+		Output extra attributes for each tag to say whether it
 		is in the implementation or interface of the source file
 		and to describe the kind of tag.  Tag kinds used are:
 		\`pred' for predicate declarations
@@ -59,21 +118,12 @@
 		(Vim assumes that the \`kind' attribute has at most 4
 		characters.)
 
-	--elvis
-		Without \`--ext', works the same as \`--vim' and supports 
-		versions of elvis prior to 2.1.  When used in
-		conjunction with \`--ext', produces an extended tags file
-		in a format that will work with elvis 2.1+.
-
-	--keep-duplicates
-		By default, mtags removes duplicate tags from the tags
-		file. With this option, duplicate tags are not removed.
-		Also, with this option, tags are created for typeclass
-		instances.  This option is implied by \`--emacs' and by
-		\`--ext'.
+	--elvis-extended-attributes
+		Output extra attributes as for `--vim-extended-attributes',
+		but in the format required by elvis.
 
 	-h, --help
-		Dislay this help message and exit.
+		Display this help message and exit.
 
 	--
 		Treat all remaining arguments as source file names.  This is
@@ -82,34 +132,47 @@
 
 $warnings = 0;
 $emacs = 0;
-$vim = 0;
-$ext = 0;
-$elvis = 0;
-$keep_dups = 0;
+$extended_attributes = "vim";
+$keep_dups = 1;
+$search_definitions = 1;
 
 OPTION:
 while ($#ARGV >= 0 && $ARGV[0] =~ /^-/) {
 	if ($ARGV[0] eq "-e" || $ARGV[0] eq "--emacs") {
 		$emacs = 1;
+		shift(ARGV);
+		next OPTION;
+	}
+	if ($ARGV[0] eq "--ext" || $ARGV[0] eq "--vim") {
+		$extended_attributes = "vim";
 		$keep_dups = 1;
+		$search_definitions = 1;
 		shift(ARGV);
 		next OPTION;
 	}
-	if ($ARGV[0] eq "--vim") {
-		$vim = 1;
-		$elvis = 0;
+	if ($ARGV[0] eq "--elvis") {
+		$extended_attributes = "elvis";
+		$keep_dups = 1;
+		$search_definitions = 0;
 		shift(ARGV);
 		next OPTION;
 	}
-	if ($ARGV[0] eq "--ext") {
-		$ext = 1;
+	if ($ARGV[0] eq "--traditional-vi") {
+		$extended_attributes = "none";
+		$keep_dups = 0;
+		$search_definitions = 1;
+		shift(ARGV);
+		next OPTION;
+	}
+	if ($ARGV[0] eq "--simple") {
+		$extended_attributes = "none";
 		$keep_dups = 1;
+		$search_definitions = 0;
 		shift(ARGV);
 		next OPTION;
 	}
-	if ($ARGV[0] eq "--elvis") {
-		$elvis = 1;
-		$vim = 0;
+	if ($ARGV[0] eq "--no-keep-duplicates") {
+		$keep_dups = 0;
 		shift(ARGV);
 		next OPTION;
 	}
@@ -118,6 +181,32 @@
 		shift(ARGV);
 		next OPTION;
 	}
+	if ($ARGV[0] eq "--no-search-definitions") {
+		$search_definitions = 0;
+		shift(ARGV);
+		next OPTION;
+	}
+	if ($ARGV[0] eq "--search-definitions") {
+		$search_definitions = 1;
+		shift(ARGV);
+		next OPTION;
+	}
+	if ($ARGV[0] eq "--no-extended-attributes") {
+		$extended_attributes = "none";
+		shift(ARGV);
+		next OPTION;
+	}
+	if ($ARGV[0] eq "--vim-extended-attributes" ||
+	    $ARGV[0] eq "--extended-attributes") {
+		$extended_attributes = "vim";
+		shift(ARGV);
+		next OPTION;
+	}
+	if ($ARGV[0] eq "--elvis-extended-attributes") {
+		$extended_attributes = "elvis";
+		shift(ARGV);
+		next OPTION;
+	}
 	if ($ARGV[0] eq "-h" || $ARGV[0] eq "--help") {
 		print "$help";
 		exit(0);
@@ -183,67 +272,36 @@
 	    if ($emacs) {
 		printf out "%s\177%s\001%d,%d\n",
 		    $_, $name, $., $.;
-	    } elsif ($ext) {
-		# In ``ext'' mode, print the extra attributes used by
-		# vim 5.0+ and elvis 2.1+.
-		if ($context =~ /\bimplementation\b/) {
+	    } else {
+	    	# Output basic tag line for vi/vim/elvis.
+	    	printf out "%s\t%s\t/^%s\$/",
+		    $name, $file, $match_line;
+
+		# Output commands to alter the search buffer.
+		if ($search_definitions) {
+		    if ($kind eq "pred" || $kind eq "func") {
+			printf out ";kq|/^\\<%s\\>/;'q", $name;
+		    } else {
+			printf out ";kq|-;/\\<%s\\>/;'q", $name;
+		    }
+		}
+
+		# Output extended attributes for vim and elvis.
+		if ($extended_attributes ne "none") {
+		    if ($context =~ /\bimplementation\b/) {
 			$static = "\tfile:";
 			$sfile = $file;
-		} else {
+		    } else {
 			$static = "";
 			$sfile = "";
+		    }
+		    printf out ";\"\tkind:%s%s", $kind, $static;
+		    if ($extended_attributes eq "elvis") {
+		    	printf out "%s", $sfile;
+		    }
 		}
-		if ($elvis) {
-		    # Elvis 2.1+
 
-		    # Elvis (as of 2.1i) seems to require `[' to be escaped
-		    # in tag patterns, even though they are supposed to use
-		    # `nomagic' mode.
-		    $match_line =~ s/\[/\\\[/g;
-
-		    # Elvis allows only a single search pattern or line
-		    # number rather than an arbitrary sequence of
-		    # semicolon-separated ex commands.
-		    printf out "%s\t%s\t/^%s\$/;\"\tkind:%s%s%s\n",
-			$name, $file, $match_line, $kind, $static, $sfile;
-		} else {
-		    # Vim 5.0+
-
-		    # Vim 5.0, like vi, allows an arbitrary number of 
-		    # colon-separated ex commands.  However if more than
-		    # one command is given, it seems to ignore the extra
-		    # tag attributes.  For now, we only output a single
-		    # search command so that vim will recognise the
-		    # extra attributes. If you would prefer the more
-		    # complex command used for vi (see below) instead of
-		    # the extra attributes, use `mtags --keep-duplicates'
-		    # instead of `mtags --ext'.
-		    printf out "%s\t%s\t/^%s\$/;\"\tkind:%s%s\n",
-			$name, $file, $match_line, $kind, $static;
-		}
-	    } elsif ($vim || $elvis) {
-	    	# Works with any version of vim, elvis or vi.
-	    	printf out "%s\t%s\t/^%s\$/\n",
-		    $name, $file, $match_line;
-	    } else {
-		# Works with vi or vim 5.0+.  The ex command searches
-		# for the matching line and then places a new search
-		# string in the search buffer.  If this is a pred/func 
-		# declaration, the new search string is the tag name,
-		# anchored to start in column 1.  The lets you type
-		# `n' to go to the pred/func body.  For other declarations,
-		# we just put the (unanchored) tag name in the string
-		# buffer, so typing `n' will take you to uses of that name.
-		# The way it places the tag in the search buffer
-		# is by making a mark, doing a search, and then
-		# returning to the marked position.
-		if ($kind eq "pred" || $kind eq "func") {
-		    printf out "%s\t%s\t/^%s\$/;kq|/^\\<%s\\>/;'q\n",
-		        $name, $file, $match_line, $name;
-		} else {
-		    printf out "%s\t%s\t/^%s\$/;kq|-;/\\<%s\\>/;'q\n",
-		        $name, $file, $match_line, $name;
-		}
+		printf out "\n";
 	    }
 	    $seen{$name} = 1;
 	    $prev_file{$name} = $file;
@@ -256,8 +314,6 @@
 if ($emacs) {
 	open(out, "> TAGS") || die "mtags: error opening TAGS: $!\n";
 } elsif ($keep_dups) {
-	# Vim 5.0+ and elvis 2.1+ allow multiple matches for a tag, so don't
-	# remove duplicate tags.
 	# Vim and elvis expect the tags file to be sorted so they can do
 	# binary search.
 	open(out, "| sort > tags") ||
-- 
David Overton      Department of Computer Science & Software Engineering
PhD Student        The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159    http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list