Trace Variable and Function Calls

I wrote TkCodex, but I haven't even looked at it in a month and I'm trying to remember how a mark-up note works. Just doing a search for anything involving "note" is going to get tedious. If I can remember which functions are involved, I'll have somewhere better to start. I could also check the instances of tagBind for a clue, presuming the perl/tk API is clear enough in my mind. But instead, I think I'll just glance through TkCodex's subroutine index.

So I start it up and get TkCodexII.pl (my working version) loaded in a window, then switch to the subroutine index with ctrl-z and scroll down with ctrl-l until I notice "notecreate".

Looking at this, I can tell it's almost certainly called by the "done" button (that API is fuzzy, but there). I might as well do a quick search to see where else notecreate() might be called from. TkCodex automatically switches to the user index (black background).

This is interesting because there is one extra instance besides the call (probably near the top) and the definition (where I am at line 872). So I click on 831. This takes me to a comment in marknote() which reads the global "$notetab" and %notehash are for notecreate() invoked by "done" button in TXT_Note:

marknote() is obviously what opens the note window, and I know notecreate() closes it. Also, I can now remember that $TXT_Note is a hash containing all the widgets of the note window, including the window itself which would be $TXT_Note{toplevel}, so let's see where else it's referenced.

There's a cluster of them from line 110-117, very likely where the widget is defined. And there's some corresponding to the location of marknote() and notecreate(). There's also some mysteriously at lines 525 and 528, so I clicked to go there and found displaynote() in the above view. It doesn't take me long to figure out that must be what is actually bound to the tag -- but I still can't remember how that's done! So I do another search for displaynote. There's only one reference outside of lines 505-522 so I go there.

That's where I find tagBind and bells start ringing.

While this example is contrived and could have been done almost as easily with vim and grep, using TkCodex has a number of advantages that will be compounded the more complex your tracing becomes. For example, since the text entry for searches has a command-line history, I can eliminate a highlighted variable with a few arrows up and the "unlite" button, and put it back later the same way. Also, the state of things in my actual text editor, if in use, remains unchanged.