Post by Stefan on Jul 28, 2020 10:44:59 GMT -5
UPDATE: This macro and the associated key mapping has been superceded by enhancements to SPFLite starting with version 2.2.20255.
The new OPTIONS GENERAL setting 'Maintain screen position after Line Cmds' now natively implements this capability.
The new OPTIONS GENERAL setting 'Maintain screen position after Line Cmds' now natively implements this capability.
Hi All,
Some of you may have seen the discussions George and I have had about cursor and page positioning when editing files and moving around using scroll and/or mouse 'keys'.
In this case you can end up a long way from your first entered line command by the time you press <ENTER>. Depending on which line commands were used, the cursor may well return to an earlier action in a completely different part of the file.
I managed to prevent this behaviour, with a combination of KEYMAP and an edit macro.
The caveat:
Because the solution is crafted entirely 'external' to the SPFLite source code, it it is CLUMSY. By that I mean that it is not suitable to completely replace the 'normal' <ENTER> key.
I use a full-size keyboard which includes another key labelled "ENTER" in the numeric keypad section. I mapped that key to the 'bespoke' <ENTER> and trained myself to press it rather than my usual <ENTER> key when I know that I've entered a bunch of line commands and moved a long way through the file. Aside from specific cases (see "Known Issues" below), it works OK when editing a file but you should retain a 'normal' <ENTER> key for e.g. for File Manager.
Functional Requirement
(1) Execute any/all line commands as normal
(2) Prevent jumping around the file - ie. Override any cursor / page changes due to line commands entered on previous sections (pages) of the file.
(3) Leave the cursor on the same line & column as it would be if I had simply pressed <ENTER> without any line commands.
(4) Execute any/all primary commands entered, as normal.
The KEYMAP Part
A bespoke <ENTER> key is required, because of the sequence in which SPFLite executes the user's instructions when the (ENTER) interrupt is received.
(1) Store cursor row and column information
(2) Execute any/all line commands according to their priority order.
(3) Execute any/all primary commands.
The hiccup is that the coordinates saved in step (1) no longer point to the correct lines AFTER the line commands in step (2) have changed the file.
The revised <ENTER> key tackles this hiccup by labeling the line below the cursor line (.pc) and the top visible line of the screen (.pt).
The revised <ENTER> key also INSERTs the Macro call (CSR at the front of the Primary command line, to ensure that the page and cursor positions are restored BEFORE any user-supplied primary commands are executed in step (3).
The sequence (optimised for keystrokes) is: (SaveCursor)(LineNo)(Down)[.pc](Home)(SetInsert)[CSR ; ](RestoreInsert)(CondLineNo)[.pt](RestoreCursor)(Enter)
The CSR Macro part
The macro basically checks a couple of things to make sure we didn't mess up File Manager, restore the .pt line to the top of the display and the cursor to the .pc line, and removes the two line labels.
KNOWN ISSUES:
- PF12 (RETRIEVE) returns "CSR;". Hit PF12 twice to get actual previous command.
- DO NOT USE modified <ENTER> key when on File Manager page.
- The .pt and .pc labels overwrite any line command or other label placed on their respective lines.
- The .pc label will be placed in error on the "**** Bottom-of-Data ****" line if the modified <ENTER> key is used on the last actual data line.
- no doubt there may be others! - PF12 (RETRIEVE) returns "CSR;". Hit PF12 twice to get actual previous command.
- DO NOT USE modified <ENTER> key when on File Manager page.
- The .pt and .pc labels overwrite any line command or other label placed on their respective lines.
- The .pc label will be placed in error on the "**** Bottom-of-Data ****" line if the modified <ENTER> key is used on the last actual data line.
The code for macro CSR has been loaded to the 'Contributed Macros' section of this forum under subject "Custom Cursor Control - MACRO CSR"