Automatic numbering of chapters in comment lines?

Help with writing and playing macros

Automatic numbering of chapters in comment lines?

Postby Peter » Mon Sep 24, 2007 7:00 am

Hello

writing my programm code with UE 10.10 I use a lot of lines for comments, and inside these comments I use a "hand made numbering":

Code: Select all
;; Step 1: setting variables
programcode ...

;; Step 2: calculate something
programcode ...

;; Step 3: display results
programcode

These numbers are in accordance with a program-description, written in MS Word.

If I have to change my code - i.e. I have to insert a new "Step 2: controll data", I have to insert a new line in MS Word and all following numbers are changed automatic.

In UE I have to change the numbering all following steps by hand:

Code: Select all
;; Step 3: calculate something
programcode ...

;; Step 4: display results
programcode


Is there any way to make this "numbering of comment lines" in an automatic way?

Best regards

Peter
User avatar
Peter
Basic User
Basic User
 
Posts: 33
Joined: Mon Nov 01, 2004 12:00 am
Location: Switzerland

Re: Automatic numbering of chapters in comment lines?

Postby Mofi » Mon Sep 24, 2007 7:30 am

You have to put into a macro file first my universal CountUp submacro posted at counter and available also in the macro files in the ZIP archive at Macro examples and reference for beginners and experts.

Then create the main macro which when executed renumbers your comments. The macro property Continue if a Find with Replace not found must be checked for this macro. If nothing is selected when the macro is executed it starts from top of the file and first number used is 1. If something is selected, it assumes that the number of the just inserted comment is selected and just renumbers everything below with the selected number+1 as first value for the next comment below.

InsertMode
ColumnModeOff
HexOff
UnixReOff
Clipboard 9
IfSel
Copy
Else
Top
"0"
StartSelect
Key LEFT ARROW
Cut
EndSelect
EndIf
Loop
Find RegExp ";;[ ^t]+Step[ ^t]+[0-9]+:"
IfNotFound
ExitLoop
EndIf
Key LEFT ARROW
SelectWord
PlayMacro 1 "CountUp"
EndLoop
ClearClipboard
Clipboard 0

Add UnixReOn 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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Automatic numbering of chapters in comment lines?

Postby Peter » Mon Sep 24, 2007 7:49 am

Thank you Mofi

I will check it.

Peter
User avatar
Peter
Basic User
Basic User
 
Posts: 33
Joined: Mon Nov 01, 2004 12:00 am
Location: Switzerland


Return to Macros