How to Crop selected text? (delete all in line Except for selected text)

Help with writing and playing macros

How to Crop selected text? (delete all in line Except for selected text)

Postby Ghoulardi » Fri Dec 11, 2009 10:30 am

I wish UltraEdit had an option in the context menu or hotkey to CROP. It would look perfect under CUT and COPY.

Example:

CUT
COPY
CROP
PASTE

Anyway, is there a macro to do this? I thought this was a macro that even I could write but I'm not getting anywhere. :)

Example.

Say I select the text "regularly read" in the line below....

IDM does not regularly read or reply to the posts in this forum.

I hit my crop macro and bam! The result is....

regularly read
User avatar
Ghoulardi
Basic User
Basic User
 
Posts: 20
Joined: Thu Dec 14, 2006 12:00 am

Re: How to Crop selected text? (delete all in line Except for selected text)

Postby Ghoulardi » Fri Dec 11, 2009 10:43 am

Ok, I got it to do what I wanted. Maybe someone could post a better way but it does do what I needed. :D

Don't laugh!!

Hotkey "Shift + z"

InsertMode
ColumnModeOff
HexOff
UltraEditReOn
IfSel
Cut
SelectLine
Delete
Paste
"
"
EndIf

:)
User avatar
Ghoulardi
Basic User
Basic User
 
Posts: 20
Joined: Thu Dec 14, 2006 12:00 am

Re: How to Crop selected text? (delete all in line Except for selected text)

Postby Mofi » Fri Dec 11, 2009 11:25 am

Your macro version was also my first thought. But I don't like destroying the Windows clipboard and it produces too many undo steps. A better version is following:

InsertMode
ColumnModeOff
HexOff
IfSel
Clipboard 9
Copy
GotoLine 0 1
StartSelect
Key END
Paste
EndSelect
ClearClipboard
Clipboard 0
EndIf

This macro works only correct for lines with a line termination on end of every line (or string on end of file). On long lines and soft word wrap enabled it does not work because the GotoLine command sets the cursor always to real start of the line which can be different than start of current display line. For users with an older version of UltraEdit not supporting GotoLine 0 1 (= goto column 1 in current line) following macro does the same as the macro above.

InsertMode
ColumnModeOff
HexOff
IfSel
Clipboard 9
Copy
Key HOME
IfColNumGt 1
Key HOME
EndIf
StartSelect
Key END
Paste
EndSelect
ClearClipboard
Clipboard 0
EndIf

This second macro can be used when working with soft word wrap enabled. It just deletes the string to start and the string to end of the current display line (= part of the long line) resulting in a new long line which is automatically rewrapped.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4058
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: How to Crop selected text? (delete all in line Except for selected text)

Postby Ghoulardi » Fri Dec 11, 2009 4:30 pm

Yes I noticed after using it a bit that it produced to many undo steps.

Thanks a lot Mofi for posting a much better version. Added to my Macro List. :)
User avatar
Ghoulardi
Basic User
Basic User
 
Posts: 20
Joined: Thu Dec 14, 2006 12:00 am


Return to Macros