Forum OpenACS Q&A: Tcl namespaces and Emacs etags

Posted by Lars Pind on
One of the few annoying things about namespaces is that they don't
work well with the handy Emacs etags.

Has anyone found a good solution to this?

Posted by John Sequeira on

Is the following helpful?

My very-slowly progressing OpenACS sql server port is done on Windows (naturally), where I couldn't get the usual find/grep/etags magic to work. I wrote a small perl script using - it also will add tags for sql files (just 'create function'). It doesn't support namespaces, but I think it would if the 'w' below was tweaked to be (w|:)

use Tags;
use Data::Dumper;
use File::Find;
use vars qw/*name *dir *prune @files/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;
*prune  = *File::Find::prune;

# Traverse desired filesystems
File::Find::find({wanted => &wanted}, 'k:/projects/ms_oacs/packages/');

sub wanted {
    return unless (/^.*.(tcl|sql)z/s && !(/foo/ || /^_/ || /,v$/));
    push @files, $File::Find::name;
      $tagparser=new Tags ('tcl',
  		     {pattern=>q{(?:ad_)?proc (?:-public|-private)? (w+)},
  		     {pattern=>q{create +function +(w+)},
  		      help=>'plpgsql functions'});

    $tagparser->parse(files=>@files, vi=>undef, emacs=>'TAGS',add=>['plpgsql']);

Also, the CPAN file had a bug in it. I don't remember what it was, but here's my modified file
Posted by Dan Wickstrom on
It depends on the style used for declaring namespaces. If you declare namespaces that don't have proc definitions and then later declare the procs separately as follows, then etags will work with tcl namespaces:

namespace eval blah {
	variable foo_var

proc blah::bar_proc {} {


proc blah::baz_proc {} {


I use an alias to generate the etags file:

alias tcltags='etags --regex="/proc[ 	]+([^ 	]+)//" --regex="/proc_doc[ 	]+([^ 	]+)//" --regex="/ad_proc[ 	]+((-([^ 	]+)[ 	]+)+)?([^ 	]+)//" `find . -name "*.tcl"`'
This should actually be rewritten to use xargs, but so far I haven't had problems with too many files yet.

If you use the namespace declaration style that encloses the proc defintions:

namespace eval blah {

	proc bar_proc {} {


	proc bax_proc {} {

Then I think it gets pretty hard to handle this format with a simple regexp. I've looked at the etags file format, and I think it would be fairly straight forward to create a perl script (or with a little more work a tcl script) that would generate the correct tag file for either package declaration format.