For the purpose of avoiding a "catch groove", *FX15 (which clears the remainder of the input buffer) is as good as *FX216 (which stops reading the rest of the function key definition). It's also a byte shorter, which probably only really matters if you like having lots of function key definitions on the go.
The one thing I was never fully happy about with this was the fact that LOADing, *EXECing or typing in a new program without clearing the function key definition risks overwriting the original program with the new one. OK, so the new program will redefine the key anyway with the correct filename; but there are always those few seconds, before you type RUN for the first time .....
So, for those (all too long .....) moments, how about this?
Code: Select all
This checks the first 4 characters after the verb in the first line of the program (which you will have to make different in each of your files) have not changed; if they have, it clears the input buffer with *FX15 (or you could use *FX216 as per JGH above) and therefore does nothing else (so it won't overwrite anything). If the first 4 characters are what it is expecting, it carries on to the next command and checks to see if the variable A exists (change this to match a variable set in your program). If the variable does exist, it clears the input buffer with *FX15 and does nothing else. If the input buffer has not been cleared (either because the first line of the program has changed, or because the variable still exists and therefore the program has not been edited) then the program will be saved and A will be given a value, so subsequent presses of f1 will not cause the program to be saved again.
This guards against overwriting a source file, if you load a new source file without changing the f1 function key definition, while still ensuring that the program will be saved if any line but the first is changed. Even if the key definition was on the first line, that's no use if you accidentally press f1 before running the freshly-loaded program.
You can probably guess what motivated this .....