Yes you can do this UE. I have macros that do similar things.
The only assumptions needed are your UE is set to allow positioning beyond end of line. And that the user has a text block selected.
One key in writing this is that you program subroutines. If you try to program a single macro to do this you'll have a monster that is a nightmare to write and a nightmare to debug.
Step 1: Make scratch file of just leading text.
- I use clipboard 9 to insulate ourselves from user.
- Add a blank line to file so we know that we can write loops and do EOL searches.
- The expression search replaces the "=" sign and all text that follows with nothing.
Here is what that macro would look like.
Code: Select all
Clipboard 9
Cut
NewFile
Paste
"
"
Find RegExp "^=*$"
Replace All ""
CONGRATS you have just built a variable file that contains JUST the leading text before equal sign.
Step 2: Determine max length line of file, put cursor in that column.
What we do is write a loop such that when get to the LAST line of file our cursor is guaranteed to be a the col position of the max length line in file. This is easy.
In a loop we do a down arrow, insert a space and then delete this space. We then press key END.
The effect of the above is simple. If the line we are on now was shorter than the previous line it now is blank padded to the previous lines length. If the line we are on now was longer than the previous line then the cursor will now be at this lines length.
We do this in a loop so by the time we hit end of file whatever column our cursor is in, that is guaranteed to be the max col length of the file.
Here is what that macro would look like:
Code: Select all
Top
Key END
Loop
IfEof
ExitLoop
EndIf
" "
Key BACKSPACE
Key END
Key DOWN ARROW
EndLoop
" "
Key BACKSPACE
Key DEL
Step 3: Make file fixed length.
Because we have just guaranteed that the last line is the longest line of file all we need to do is cut/paste the entire file in COLUMN mode. When we do this,
UE will automatically blank pad EVERY line to the size defined by the rectangle being used. Which in our case, the rectangle is as wide as the longest line. The next result will be a fixed length file.
Code: Select all
Top
ColumnModeOn
SelectToBottom
StartSelect
Key Ctrl+END
ColumnModeOff
ColumnModeOn
Cut
Paste
Step 4: Make scratch file of just TRAILING text.
Make a macro exactly like step 1, the only change is now we do an expression search & replace of
%*^= and replace with
=. This will make a scratch file containing JUST the TRAILING text because what we are doing is searching from start of line to an "=" sign and replacing that text with an equal sign.
Step 5: Format this trailing text and copy into paste buffer.
Now use the step 2 technique and get cursor on last line of file at max col position.
Then use the step 3 technique to get this file fixed length.
At this point our PASTE buffer contains what we want.
The file we are now in is useless to us. What we want is in our paste buffer. I have not found a clean way to get rid of a scratch window. The best method I've found is to simply save file to a dummy location and then close the window. Because I'm saving and closing a file, it is my preference to make it an empty file because as I said, this window is useless for us and we simply want it to go away.
Regardless of whether you save an empty file or file with text, the only new macro code you need is:
Step 6: Join the leading and trailing text.
When the above step finished, UE has no other choice than to bring you back to the last window you were in which happens to be the first scratch file window you made. This window contains all the LEADING text and is fixed length. Our paste buffer contains all the TRAILING text and is fixed length.
all we need to do is paste the two together in COLUMN mode.
CONGRATS! You now have that paragraph formatted exactly as user desired.
Step 7: Copy text to paste buffer, get rid of scratch window.
Put editor in normal mode select all and cut. We no longer want this window so do same technique as before save to a dummy location and close file.
Step 8: Paste our formatted text back out and were DONE.
When the above step finished, UE has again no other choice than to bring you back to the last window you were in, which happens to be the ORIGINAL window. Our cursor is already exactly where the original paragraph was located. Put editor back to "NORMAL" mode and paste selection.
Enjoy.