Macro replacement for command Delete Next Word

Help with writing and playing macros

Macro replacement for command Delete Next Word

Postby twopigs » Fri Mar 11, 2011 9:35 am

Hello,

I would like to make a simple macro that does two things:

Ctrl-Delete (the shortcut to delete the next word)
Down Arrow

That's all. Is this possible, the macro recorder doesn't seem to want to record Ctrl+DEL and when I enter Ctrl+DEL when manually building a macro that doesn't work either.

Thanks for your time
TwoPigs
twopigs
Newbie
 
Posts: 2
Joined: Sat Oct 02, 2010 12:22 pm

Re: Macro replacement for command Delete Next Word

Postby Mofi » Fri Mar 11, 2011 10:57 am

This macro should do what you want. The green code emulates Ctrl+Del in insert mode when caret is not at beginning or middle of a word.

InsertMode
ColumnModeOff
HexOff
UnixReOff
IfSel
Delete
EndIf
IfCharIs 13
Delete
ExitMacro
EndIf
IfCharIs 10
Delete
ExitMacro
EndIf
IfCharIs 32
Find RegExp "[ ^t]+"
Replace ""
ExitMacro
EndIf
IfCharIs 9
Find RegExp "[ ^t]+"
Replace ""
ExitMacro
EndIf

Find RegExp "[~^t^r^n ]+[ ^t]++"
Replace ""
Key DOWN ARROW
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3936
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Macro replacement for command Delete Next Word

Postby twopigs » Fri Mar 11, 2011 12:01 pm

Wow - thanks megatons,

My little two lines replaced by all that code!? The thing is that I want this macro to work regardless of the cursor being inside a word or not.

You don't need to write another large macro, as I appreciate your time, I'll make due. However, ...
* I would like to know why I can't put the "Ctrl-Del" shortcut sequence into a macro?
* Are shortcuts not allowed in Macros?
* Can I somehow modify or add a shortcut?

Thanks again for your time.
twopigs
Newbie
 
Posts: 2
Joined: Sat Oct 02, 2010 12:22 pm

Re: Macro replacement for command Delete Next Word

Postby Mofi » Fri Mar 11, 2011 1:21 pm

Well, all the macro code is to replace original behavior of EditDeleteNextWord in any situation as usual in insert mode (column mode turned off) plus the additional cursor down.

IfSel
Delete
EndIf


is for deleting current selection if something is selected as Ctrl+DEL does in this case.


IfCharIs 13
Delete
ExitMacro
EndIf
IfCharIs 10
Delete
ExitMacro
EndIf


is for deleting the line termination if Ctrl+DEL is pressed with caret at end of a line (CRLF, or only LF, or only CR).


IfCharIs 32
Find RegExp "[ ^t]+"
Replace ""
ExitMacro
EndIf
IfCharIs 9
Find RegExp "[ ^t]+"
Replace ""
ExitMacro
EndIf


is for deleting just all spaces/tabs up to next non whitespace character or line termination if the caret is positioned on a space or tab character.


And the last block

Find RegExp "[~^t^r^n ]+[ ^t]++"
Replace ""
Key DOWN ARROW


is what you actually want, delete from current position of the caret everything up to beginning of next word or end of line.

With that code blocks you see that even a simple command needs lots of code inside UltraEdit to work in every case. And that was surely not all. Well, the last 2 blocks could be replaced by a simplified version which would have the advantage to be independent of the regular expression engine.

InsertMode
ColumnModeOff
HexOff
IfSel
Delete
EndIf
IfCharIs 13
Delete
ExitMacro
EndIf
IfCharIs 10
Delete
ExitMacro
EndIf

StartSelect
Key Ctrl+RIGHT ARROW
EndSelect
Delete
Key DOWN ARROW



The Command list in the macro editor list all possible commands and selecting one command in this list results in displaying all possible parameters of this command in the Non-numeric parameters list. On help page opened with Help button all the commands with all possible parameters are also listed and additionally explained. As you can see, the command Key supports only a few caret (cursor) moving commands. It is simply by design not possible to run any command from within a macro by simulating pressing its assigned hotkey.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3936
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros

cron