debootstrap is written in shell, and the principal points of interest, debootstrap, functions, and scripts/debian/sid are several hundreds lines each, the last ones being sourced by the first one.

Emacs is supposed to be great, let's look at etags, the Emacs flavour of exuberant ctags. It generates a TAGS file which is then used by Emacs when M-. is pressed, to search for the current word (at the point). etags supports many languages, but I first thought shell was missing. Hopefully, it is possible to add support for new languages, which can be done using two methods: either pass some regexps to etags, or implement a new parser and recompile etags after having added it to the Makefile.

The first method was sufficient here, since debootstrap's code is quite well indented, and at first glance, every function is declared using the following: left-aligned, possibly followed by whitespaces, followed by (possibly spaced) parentheses, possibly followed by whitespaces, possibly followed by an opening brace. That is:

'/^([a-zA-Z0-9_]+)[ \t]*[(][ \t]*[)][ \t]*[{]*[ \t]*/\1/'

One could have used two regexps (using --regex-$LANG twice) to accept only the following, which would have been sufficient, given the current source files:

'/^([a-zA-Z0-9_]+) [(][)] [{]/\1/'
'/^([a-zA-Z0-9_]+)[(][)]/\1/'

Now, it is sufficient to add a tags: target to the Makefile, running etags on the interesting files, defining a new language kibishell (so as to void possible clash with future well-featured shell modes), forcing it for the specified files (since they have no extension, it is not possible to use --langmap=kibishell:.sh).

Added Makefile fragment:

tags:
    etags \
      --totals \
      --langdef=kibishell \
      --regex-kibishell='/^([a-zA-Z0-9_]+)[ \t]*[(][ \t]*[)][ \t]*[{]*[ \t]*/\1/' \
      --language-force=kibishell \
      debootstrap functions scripts/debian/sid

Usage within Emacs:

  • M-.: search for a definition;
  • M-O M-.: next definition;
  • M-*: go back to the starting point;
  • M-x visit-tags-table: change the reference file.

Now that I can read that sh is supported, it is sufficient to drop --langdef and --regex-kibishell, and to adjust --language-force. Here it is: not that bad after all, only 6 symbols were missing, on a total of 63.

A last word on etags: it accepts -x so that a cross reference is written to the standard output, in the cxref format.