This has been rolling around in my mind for a day or two, and I thought of this hacky idea for a pound shop cross reference type of function:Coeus wrote: ↑Wed Oct 27, 2021 3:45 amI am not sure how hard this one would be.daveejhitchins wrote: ↑Sat Oct 23, 2021 10:32 am (3) When editing – it would be a good feature if you could follow a jump or procedure – possibly by holding down a key combination – and returning, in the case of a procedure.
If you're looking at an identifier, preceded by 0+ spaces, preceded by PROC, you're looking at a proc name. (And something similar applies to FN names too.)
When you hit the xref key, run this check on the cursor position. If it passes, the cursor was on a proc name. Note that proc name, and do a FIND for all occurences of it.
This would potentially produce too many results. So, to make this actually work nicely, improve/hack the FIND mechanism so that when initiated by the xref command (rather than by FIND or IFIND), it runs the above proc name check on each found occurrence, and also checks that only the full name matches rather than the prefix. Each match only counts as an occurrence if these check passes - so if you search for proc X, say, "DEFPROCX:" counts as an occurrence, but "X%=5" doesn't, nor does "DEFPROCXYZ".
The detokenized text is easily available so I figure you'd just do all of this by matching strings. For bonus points, skip stuff in REM and DATA statements - probably not a big deal though.
For returning, why not a general-purpose find location stack, which might be useful for FINDs anyway? - there's potentially some space free in zero page before you hit $70 that could be used for this. (Note the official BASIC Editor Zero Page Promise! Money back guarantee if not 100% satisfied) Another option might be to book some space at the top of page 1. The stack pointer is initialized to $ff on entry to the rom, but I bet it could be $e0 and there'd be no problem. I figured you'd be good just storing line number/offset in line, so 3 bytes per entry. 32 bytes gives you 10 entries... just how complicated are your BBC BASIC programs anyway?!
For GOTO and GOSUB, I reckon the xref command should just check if you're on a number - any number - and use the existing go to line functionality (preceded by a push to the location stack). You could go to the trouble of checking that you're actually on a GOTO, but this would probably become a bit fiddly with the comma-separated ON...GOTO syntax.
--Tom