The first macro finds the longest line INCLUDING leading+trailing white chars/blanks. The macro property Continue if a Find with Replace not found must be checked for this macro. The file will be modified after macro execution although nothing is really changed, except the last line of the file was not terminated with a CR LF (or LF or CR only).
How it works:
First it checks if the last line of the file is terminated and if not, it inserts a line termination. That's important or the last line will be later always ignored.
Next it inserts a top of the line the UltraEdit style regular expression %???$. The number of ? is 500. Modify this value to the maximum line length you expect.
Next it selects this regular expression and searches for it.
If a line is found with exactly the number of characters (?), this is the longest line in the file. So it marks the line with a special string, goes to top of the file, deletes there the regular expression string (first line) and last uses a Find+Replace to go back to the longest line and deletes the marker string.
If the regular expression string is not found, it removes 1 ? and runs the regular expression search again, until either a line with exactly the current number of characters (?) is found or the regular expression does not contain any ? anymore (macro executed on an empty file).
Note: ^s with a regular expression search is only possible with an UltraEdit style regex. Unix or Perl are not supported. Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.
InsertMode
ColumnModeOff
HexOff
UnixReOff
Key DOWN ARROW
InsertMode
ColumnModeOff
HexOff
UnixReOff
Bottom
IfColNum 1
Else
"
"
EndIf Top
"%"
Loop 500
"?"
EndLoop
"$
"
Key UP ARROW
Loop
StartSelect
Key END
EndSelect
Find RegExp "^s"
IfFound
EndSelect
Key HOME
IfColNumGt 1
Key HOME
EndIf
"LoGeStLiNe!"
Top
DeleteLine
Find MatchCase "LoGeStLiNe!"
Replace ""
ExitLoop
EndIf
Key LEFT ARROW
IfColNumGt 2
Key BACKSPACE
Key HOME
Else
DeleteLine
ExitLoop
EndIf
EndLoop
For finding the longest line EXCLUDING leading+trailing white chars/blanks it's the easiest method to remove them temporarily. Insert after command Top following lines:
TrimTrailingSpaces
Find RegExp "%[ ^t]+"
Replace All ""
Use after macro execution File - Revert to Saved to restore the real file content while the cursor is on the longest line. If you want to prevent a modification of the file by mistake, insert the following lines after command UnixReOff into the macro to run the search on a copy of the original file: