I hesitate to reply, because you'll probably be offended, but this is just too much to let lie. First off, there are no line numbers in the traditional sense--it's just Out
and In
. So, your mental mode of what's even happening here is probably wrong.
Not only is it a bad idea to try to keep line numbers consistent between kernel sessions, it's a bad idea even within a single session. No one writes Mathematica code by referencing Out
directly unless they're doing something very ad hoc or exceptional. You will find no robust packages/libraries that do this. You will find no examples from experienced Mathematica programmers that do this (unless, again, it's something extremely unusual). The whole idea is just a nightmare.
As for handling "programs reloaded from disc", Mathematica does this just fine. I can't imagine what you think "line numbers" have to do with this. Mathematica also handles "deletions" just fine. It also handles additions and edits. None of this has anything to do with "line numbers".
You've adopted a very particular and peculiar programming habit, and since it's your habit, you don't have an objective frame of reference from which to see how bad it truly is. You can read entire books on programming with Mathematica that will never reference Out
or In
explicitly. I think you'd be hard pressed to find any code examples on this site or on any other Mathematica related site where explicit references to Out
or In
are used. I've been writing Mathematica code for over 25 years, and I have literally never depended explicitly on "line numbers". One of the most frustrating things about BASIC was that it required you to explicitly referenc line numbers--it was a relief to learn other languages that didn't have this restriction. It boggles the mind to learn that someone wants to revive that pattern.
But, you must find your own path. So, if you are truly desperate for this kind of "line number" based programming pattern, you should look into $Line
. Explicitly manipulating it will make your code truly ugly, but that's your own affair.