Article View: comp.emacs
Article #9529Re: Force exact matching of tag name
From: Kim Letkeman
Date: Mon, 05 Feb 1990 14:00
Date: Mon, 05 Feb 1990 14:00
116 lines
3863 bytes
3863 bytes
In article <9002021705.AA06173@sn1987a.compass.com>, worley@compass.UUCP (Dale Worley) writes:
| When I try to look up a tag with find-tag, I wind up seeing every tag
| that contains the tag I'm looking for. (For instance, look up
| "find-file" in Emacs' tags.) I've made changes to fix this problem.
| The first change is to change the search in find-tag to be a regexp
| search rather than a string search. (This should be
|[...]
We made similar changes in our environment, but with one major
difference. We created a second function called find-tag-exact. This
function performs the exact match on a word boundary. We did this
because of the fairly severe penalty you pay for regexp searching over
string searching (the difference is very noticeable even on a sun4.
We would recommend the second function in environments with a lot of
symbols. (Our environment contains about 1500 pascal files with many
symbols each - the tags file is 486191 bytes long.)
By the way, we created an awk script to handle the creation of a tags
file for our variant of pascal. I include it here in case anyone might
find it useful.
Kim
--------cut here-----------------------------------------------------
#! /bin/sh
#
# Creates an emacs (etags equivalent) TAGS file for a variant of
# pascal. Note that this is a filter, so output should be piped to
# your tags file directly.
#
# Syntax expected:
#
# function [entry] <name> (parms)
# or
# procedure [entry] <name> (parms)
#
# where the term entry signifies an exported definition.
#
# Example: To create a file named TAGS for the current srcdir, just
# type:
#
# etags $SRCDIR/*.pas > TAGS &
#
# and in 15 minutes (sun4) or 40 minutes (sun3), you'll have a tags
# file.
gawk '\
BEGIN {
IGNORECASE = 1
}
function dump_tag_entries()
{
if (tag_entry_line>2) {
tag_entries[2] = sprintf ("%s,%d",curr_filename,
total_chars_in_tag_entry);
for (i=1; i<=tag_entry_line; i++) {
print tag_entries[i];
delete tag_entries[i];
}
}
}
# This short null pattern checks to see if we have changed files. If so,
# we dump the previous entries and reinitialize the array and supporting
# variables.
{
if (FILENAME!=curr_filename) {
dump_tag_entries();
curr_filename = FILENAME;
curr_char_posn = 0;
total_chars_in_tag_entry = 0;
tag_entries[1] = "";
tag_entry_line = 2;
}
}
# This pattern selects procedure and function definitions with 99.9%
# accuracy. Only the ugliest of code can slip through and I dont want
# to look at that stuff anyway. The if statement eliminates code that
# does not put the function or procedure name on the same line as the
# definition. The search string is kept to a minimum length by removing
# any parameters.
/^[ ]*(procedure|function)[ ]/ {
if (($2 ~ /entry/ && NF>2) ||
($2 !~ /entry/ && NF>1)) {
search_pattern = $0;
sub ("[ ]*\\(.*$", "", search_pattern);
sub ("[ ]*;.*$", "", search_pattern);
tag_entries[++tag_entry_line] = sprintf ("%s%c%d,%d",
search_pattern, 127,
FNR, curr_char_posn);
total_chars_in_tag_entry += \
length(tag_entries[tag_entry_line])+1;
}
}
# This action updates the character offset for the search string.
{
curr_char_posn += length($0)+1;
}
# After all is said and done there is still one more set of entries.
END {
dump_tag_entries()
}' $*
--
Kim Letkeman uunet!mitel!spock!kim
Technical Details
Message-ID:
<2119@kim>Path:
arc1-ca.pugleaf.net!utzoo!dciem!nrcaer!sce!spock!kimReferences:
<9002021705.AA06173@sn1987a.compass.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!dciem!nrcaer!sce!spock!kim From: kim@spock (Kim Letkeman) Newsgroups: comp.emacs Subject: Re: Force exact matching of tag name Message-ID: <2119@kim> Date: 5 Feb 90 14:00:02 GMT References: <9002021705.AA06173@sn1987a.compass.com> Organization: Mitel. Kanata (Ontario). Canada. Lines: 116 In-reply-to: worley@compass.UUCP's message of 2 Feb 90 17:05:00 GMT