More consistent text buffer tracking for programs

Since we open text buffers for analysis without opening document windows
for them, we keep a buffer dictionary for tracking them. If all the
opened files of a program are closed, we want to unload the program's
files (including the opened text buffers in the background).

In the parser, we also can get artifact variables, i.e. variables might
be registered as such while the user is typing, and then they aren't
removed when the cease to exist. Made a tweak in the parser to attempt
to change this behavior, but this is a tough thing to test so it
probably needs more work.