A macro version for deleting 1 to 4 spaces left the current position of the caret in a
*.py or
*.pyw file is:
Code: Select all
InsertMode
ColumnModeOff
IfSel
Key BACKSPACE
ExitMacro
EndIf
IfColNum 1
Key BACKSPACE
ExitMacro
EndIf
IfExtIs "py"
Else
IfExtIs "pyw"
Else
Key BACKSPACE
ExitMacro
EndIf
EndIf
Key LEFT ARROW
IfCharIs 32
Delete
Else
Delete
ExitMacro
EndIf
Loop 3
IfColNum 1
ExitLoop
EndIf
IfColNum 5
ExitLoop
EndIf
IfColNum 9
ExitLoop
EndIf
IfColNum 13
ExitLoop
EndIf
IfColNum 17
ExitLoop
EndIf
IfColNum 21
ExitLoop
EndIf
IfColNum 25
ExitLoop
EndIf
IfColNum 29
ExitLoop
EndIf
IfColNum 33
ExitLoop
EndIf
IfColNum 37
ExitLoop
EndIf
IfColNum 41
ExitLoop
EndIf
IfColNum 45
ExitLoop
EndIf
IfColNum 49
ExitLoop
EndIf
Key LEFT ARROW
IfCharIs 32
Delete
Else
Key RIGHT ARROW
ExitLoop
EndIf
EndLoop
The macro with indents for better understanding:
Code: Select all
InsertMode
ColumnModeOff
IfSel
Key BACKSPACE
ExitMacro
EndIf
IfColNum 1
Key BACKSPACE
ExitMacro
EndIf
IfExtIs "py"
Else
IfExtIs "pyw"
Else
Key BACKSPACE
ExitMacro
EndIf
EndIf
Key LEFT ARROW
IfCharIs 32
Delete
Else
Delete
ExitMacro
EndIf
Loop 3
IfColNum 1
ExitLoop
EndIf
IfColNum 5
ExitLoop
EndIf
IfColNum 9
ExitLoop
EndIf
IfColNum 13
ExitLoop
EndIf
IfColNum 17
ExitLoop
EndIf
IfColNum 21
ExitLoop
EndIf
IfColNum 25
ExitLoop
EndIf
IfColNum 29
ExitLoop
EndIf
IfColNum 33
ExitLoop
EndIf
IfColNum 37
ExitLoop
EndIf
IfColNum 41
ExitLoop
EndIf
IfColNum 45
ExitLoop
EndIf
IfColNum 49
ExitLoop
EndIf
Key LEFT ARROW
IfCharIs 32
Delete
Else
Key RIGHT ARROW
ExitLoop
EndIf
EndLoop
There is no macro command to find out if the active file is opened in hex edit mode. Do not run this macro on a file in hex edit mode although with UE/UES v2024.2.0.39 nothing happens on running the macro on a file opened in hex edit mode which does not have the file extension
.py or
.pyw according to my tests. For Python files opened in hex edit mode the behavior is similar to behavior on Python file opened in text edit mode depending on caret is in hex area (always just one byte deleted) or in text area (one to four bytes deleted depending on byte values).
UltraEdit macros do not support variables. That is the reason for the sequence of
IfColNum number with
ExitLoop and
EndIf. If the macro should support even more indent levels, there must be added some more of these command sequences. The
numbers and the
Loop number must be edited if something other than four spaces is used for indents in Python files.
The macro can be saved together with other often needed macros in a macro file being configured for automatic load on startup of UltraEdit. The binary code of the macro saved with UltraEdit/UEStudio v2024.2.0.39 is:
Code: Select all
0000h: 55 45 2D 4D 61 63 72 6F 31 00 88 00 50 00 79 00 ; UE-Macro1.ˆ.P.y.
0010h: 74 00 68 00 6F 00 6E 00 55 00 6E 00 69 00 6E 00 ; t.h.o.n.U.n.i.n.
0020h: 64 00 65 00 6E 00 74 00 00 00 00 00 00 00 00 00 ; d.e.n.t.........
0030h: 22 00 00 00 E0 00 00 00 04 08 00 00 20 49 20 6D ; "...à....... I m
0040h: 20 0E 20 43 20 38 20 30 20 15 20 06 20 14 20 31 ; . C 8 0 . . . 1
0050h: 20 43 20 38 20 30 20 15 20 06 20 8E 20 32 20 70 ; C 8 0 . . Ž 2 p
0060h: 79 20 17 20 8E 20 33 20 70 79 77 20 17 20 43 20 ; y . Ž 3 pyw . C
0070h: 38 20 30 20 15 20 06 20 06 20 4B 20 33 37 20 30 ; 8 0 . . . K 37 0
0080h: 20 10 20 31 20 20 20 30 20 2D 31 20 30 20 17 20 ; . 1 0 -1 0 .
0090h: 30 20 15 20 06 20 12 20 33 20 14 20 31 20 16 20 ; 0 . . . 3 . 1 .
00A0h: 06 20 14 20 35 20 16 20 06 20 14 20 39 20 16 20 ; . . 5 . . . 9 .
00B0h: 06 20 14 20 31 33 20 16 20 06 20 14 20 31 37 20 ; . . 13 . . . 17
00C0h: 16 20 06 20 14 20 32 31 20 16 20 06 20 14 20 32 ; . . . 21 . . . 2
00D0h: 35 20 16 20 06 20 14 20 32 39 20 16 20 06 20 14 ; 5 . . . 29 . . .
00E0h: 20 33 33 20 16 20 06 20 14 20 33 37 20 16 20 06 ; 33 . . . 37 . .
00F0h: 20 14 20 34 31 20 16 20 06 20 14 20 34 35 20 16 ; . 41 . . . 45 .
0100h: 20 06 20 4B 20 33 37 20 30 20 10 20 31 20 20 20 ; . K 37 0 . 1
0110h: 30 20 2D 31 20 30 20 17 20 4B 20 33 39 20 30 20 ; 0 -1 0 . K 39 0
0120h: 16 20 06 20 13 ; . . .
The macro is named here
PythonUnindent and has
Shift + BACKSPACE as hotkey. The macro properties are:
- Show cancel dialog for this macro … not checked
- Continue if search string not found … checked
- Disable screen refresh during macro playback not … checked
The two bytes
04 08 at byte offset
0038h define the hotkey. The first byte
04 must be modified to
00 for
BACKSPACE by opening the macro file in UltraEdit in hex edit mode and changing this byte.
08 is the byte value of the control character respectively key
BACKSPACE. The byte
04 before is a bit mask value for
Ctrl (bit 0 …
01), (left)
Alt (bit 1 …
02), (left)
Shift (bit 2 …
04).
I tested the macro with modification of hotkey from
Shift + BACKSPACE to
BACKSPACE using the manual edit of the modifier byte in binary macro file on a
*.py file opened in text edit mode with UE/UES v2024.2.0.39. The macro makes the deletion as usually done on pressing key
BACKSPACE on being executed on files with a different extension than
.py or
.pyw or does nothing on active file is opened in hex edit mode and does not have the extension
.py or
.pyw.