From: mschee@bcarh600.bnr.ca (Michael SamChee)
Newsgroups: comp.editors
Subject: Solutions to using CTAGS in VI..
Keywords: recursive call, pop, stack
Date: 19 Aug 92 22:31:46 GMT
Organization: Bell-Northern Research, Ottawa, Canada

Hi there,

A few days ago I sent the following news item asking for help on
using CTAGS in VI:

> Hi,
> 
> Please, I need some help! using CTAGs in unix:
> 
> If I recursively invoke tags (by typing "CNTRL ]" on each
> identifier I wish to search for), say 3 times, I am unable
> to "pop back" to the file where I *first* invoked tags. 
> 
> When I was on campus, it used to work the way I wanted 
> it to, but now on my job, when I create a tags file and
> invoke it in a nested (recursive) fashion, I'm only able
> to "pop back" to the *previous* file where tags was invoked.
> 
> Also, invoking tags seem to be case sensitive ie. identifier
> "Ct" is not treated the same as "ct". Is there a way to make it
> case insensitive?
> 
> Anybody ever had these experiences, or knows how to
> overcome these problems ?
> 
> Your help will be very much appreciated !
> 
> 
> Thanks,
> Michael.


Based on email and newsgroup replies, I would like to share
the following solution with you:

First of all, it seem to be general concensus that tag stacking 
is only available on newer versions of vi. 

Since we don't have access to the source for vi, the following
solution, given by

           "s-fujii@sramha.sra.co.jp (Seigo Fujii)"

can be used to solve the problem:

First,

Map a key (say ^Y) to push the file on the stack and invoke tags:
    map ^Y  :1,.w !exec vifs push %^M^M^]

Map a key (say ^P) to pop the previous file from the stack:
    map ^P  :!exec vifs pop^M:so ~/tmp/vifs_pop.ex^M^M

Create a directory called "tmp" in your home directory,
and put the following perl script program (given at the end
of this news item) in a file and name it "vifs".

You can now use ^Y to invoke tags and ^P to pop back
to the *previous* file where tags was invoked.

As for the last problem in the original posting, no one was
able to give a solution to making tags case insensitive..

Cheers,
Michael.


--------------start of vifs file--------------------
#!/usr/local/bin/perl
#
# vifs : vi edit-file stack
#usage: vifs [show|push file|pop|clear|clean]
#
$PPID = getppid;
$HOME = $ENV{'HOME'};
$STACKFILEBASE = $HOME . '/tmp/#vifs_stack';
$STACKFILE = $STACKFILEBASE . ".$PPID";
$POPEXFILE = $HOME . '/tmp/vifs_pop.ex';

if ($ARGV[0] eq 'push' && $#ARGV == 1) {
    &countline;
    &getstack;
    push(@stack, "$ARGV[1] $line\n");
    &putstack;
} elsif ($ARGV[0] eq 'show' || $#ARGV == -1) {
    &getstack;
    print @stack;
} elsif ($ARGV[0] eq 'pop') {
    &getstack;
    $_ = pop(@stack);
    chop;
    ($file, $line) = split(' ');
    &makepopex;
    &putstack;
} elsif ($ARGV[0] eq 'clear') {
    truncate($STACKFILE, 0);
} elsif ($ARGV[0] eq 'clean') {
    unlink <$STACKFILEBASE.*>, $POPEXFILE;
} else {
    &usage;
}
exit 0;

sub usage {
    print STDERR "usage: vifs [show|push file|pop|clear|clean]\n";
    exit 1;
}

sub countline {
    while (<STDIN>) {}
    $line = $.;
}

sub getstack {
    if (open(STACK, "<$STACKFILE")) {
       @stack = <STACK>;
       close(STACK);
    }
}

sub putstack {
    open(STACK, ">$STACKFILE") || die "can not open $STACKFILE\n";
    print STACK @stack;
    close(STACK);
}

sub makepopex {
    open(POPEX, ">$POPEXFILE") || die "can not open $POPEXFILE\n";
    if ($file && $line) {
         print POPEX "e +$line $file\n$line\n";
    } else {
         print STDERR "edit-file stack empty\n";
         print POPEX qq/" edit-file stack empty\n/;
    }
    close(POPEX);
}
-----------end of vifs file--------------------
Newsgroups: comp.editors