Author Topic: Multi-cursor aliases  (Read 2794 times)

Dennis

  • Senior Community Member
  • Posts: 3954
  • Hero Points: 515
Multi-cursor aliases
« on: December 18, 2020, 07:06:50 PM »
An alias can be created which instantiates multiple cursors when expanded.  (Document > [Language] Options... > Aliases)

For example, suppose you want to create a "fori" alias to iterate over a variable 'i' from 0 .. n.  You could define an alias as follows:
Code: [Select]
for (i%\| = 0%\c; i%\| < n%\c; ++i%\|) {
%\i%\c
}

Then when you type "fori<space>" the alias will expand and create three cursors so you can change the name of the iterator variable, then you can hit <TAB> to advance to the next cursor location to enter the start value, and continue tabbing to fill in the rest of the loop.  The first <TAB> will cancel the multiple cursor instances.

Note how the alias includes a default variable name 'i' that you can type over.  This is done to make the alias expand to something that still has clean syntax, otherwise, without those initial variables in place, beautify of alias expansion would have a hard time parsing the incomplete code.

As another example, here is an alias for printing an debug statement to show the value of an integer variable.  It creates two cursors, one for editing the name of the variable in the format string, and one to edit the name of the variable being printed.
"printv" alias:
Code: [Select]
printf("%\n+(%%d): %\|=%%%\c\n", __LINE__, %\|);

NOTE:
This is a feature that has been around for a while, however a fix in 25.0.1 makes it work more accurately, even when beautify on alias expansion is enabled.