1. The macro environment does not support variables. To keep current caret position there are 3 possibilities:
- The macro code is converted to script code as scripts support variables and therefore can remember current line and column position and set caret back after making the collapses. Scripts added to the script list can be also executed by hotkey or chord. The disadvantage in comparison to a macro is that a Cancel dialog is always displayed and usually the content of active output window is overwritten by script status information.
- If you usually don't use bookmarks, the macro command ToggleBookmark can be inserted above first command Top to bookmark current line and column with configuration setting Bookmark column with line at Advanced - Configuration - Editor - Bookmarks checked. The second command Top at end of the macro must be replaced by the commands
GotoBookMark -1
ToggleBookmark
to move caret back to initial position on macro start.
- If you often use bookmarks, it is possible to insert a special string to mark current position of the caret by inserting for example above first command Top the write command "CaReT". Below second command Top the commands
Find MatchCase "CaReT"
Replace ""
need to be appended to the macro to restore the caret position and remove the marker string. The disadvantage of this solution is a modification of the file with producing 2 undo steps.
Whichever solution is used, restoring the caret position after script/macro execution works only if the caret before execution is not on a line which is collapsed after script/macro execution.
2. I do not really understand your second requirement. If you want to edit something in the collapsed lines, you have to expand this part first. This can be done easily by clicking with mouse button on the
[+] symbol left the collapsed lines or set caret on first line of collapsed block (with the
[+] symbol left) and execute the command
View - Hide/Show Lines - Hide/Show Selection. Do not select anything to expand a collapsed block. The hotkey for this command can be also configured at
Advanced - Configuration - Key Mapping.