UnderLine a Word

Help with writing and playing macros

UnderLine a Word

Postby prashanth7582 » Sat Oct 27, 2007 3:15 pm

Hi All,

I need to Underline the Heading as Follows..

For Ex:

UnderLine a Word
---------------------

I am trying to Underline like above using Macros but not getting any ideas how to go with..

Any suggestions are appreciated..
User avatar
prashanth7582
Newbie
 
Posts: 9
Joined: Fri Jul 20, 2007 11:00 pm

Re: UnderLine a Word

Postby Bego » Sat Oct 27, 2007 7:48 pm

What is a heading? How can it be detected? What version do you use? Can you post an example? Do you know that underlining can only mean another line of "-"signs and no formatting?
Questions Questions.....
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: UnderLine a Word

Postby Mofi » Sun Oct 28, 2007 8:59 am

And you hopefully know that UltraEdit is a text editor and in plain text files it is not possible to store hidden style informations like bold, underline, font size, etc. So you can only configure the syntax highlighting engine to display words (not phrases) with a customized style.

Or are you talking about underlining with character '-'? Yes, Bego has already written all the questions necessary to write a macro. A software like a macro needs rules.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: UnderLine a Word

Postby prashanth7582 » Sun Oct 28, 2007 9:02 am

Hi Bego,

<<Do you know that underlining can only mean another line of "-"signs <<and no formatting?

I want to do the same as u stated above ..I want a series of "-" character under some specific word which I want to Highlight..

We can try it as follows :

Go to Next Line
Depending on the Length of the word selected,write "-" characters..

But I need to know how can I do the above using Macros..

I am using Ultraedit 13.10a+1 version..

I think I am clear now..
User avatar
prashanth7582
Newbie
 
Posts: 9
Joined: Fri Jul 20, 2007 11:00 pm

Re: UnderLine a Word

Postby Mofi » Sun Oct 28, 2007 10:34 am

Okay, now I have understood. You simply want to insert a line with '-' characters depending on the length of the current line. The following macro will do that.

The IfColNumGt 1 makes sure that the macro does nothing if the cursor is currently on an empty line.

The red highlighted part is just for security. It makes sure that the macro will also work when the cursor is on the last line of the file and this line has no line ending.

The rest is the real important part. The macro duplicates the current line, selects the duplicate without the line ending and uses an UltraEdit regular expression replace to replace any character in the selection with a '-'.

Note: The result will be wrong if the current line contains 1 or more tabs because every tab will be replaced only by 1 '-' instead of correct number of '-' according to current tab stop value(s) for that file.

ColumnModeOff
HexOff
Key END
IfColNumGt 1
InsertMode
UnixReOff
IfCharIs 13
Else
IfCharIs 10
Else
InsertLine
Key UP ARROW
EndIf
EndIf

DupeLine
Key HOME
IfColNumGt 1
Key HOME
EndIf
StartSelect
Key END
Find RegExp "?"
Replace All SelectText "-"
EndSelect
Key HOME
EndIf

Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro before command EndIf 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: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: UnderLine a Word

Postby prashanth7582 » Mon Oct 29, 2007 3:08 am

Hi Mofi,

Thanks for ur reply..

But it doesnt suite my need..Basically I select only a particular Word but ur macro selects the entire Line,duplicates it and replaces it by "-" characters..

Instead of duplicating the Entire Line,we need to copy the selected word,paste into next line and replace that word by "-" characters..

I think we need to get the column no here to paste it exactly below the selected text..

Any Ideas??
User avatar
prashanth7582
Newbie
 
Posts: 9
Joined: Fri Jul 20, 2007 11:00 pm

Re: UnderLine a Word

Postby Mofi » Tue Oct 30, 2007 10:58 am

Okay, here is a macro which inserts a line below with preceding spaces to start of the current selection and '-' for every character of the selection.

Again if there is anywhere 1 or more tabs in the current selection or the line part before the selection, the result will be not correct because every tab will be replaced by only 1 '-' or ' ' instead of correct number of '-' or ' ' according to current tab stop value(s) for that file.

The macro is quite more complicated as I first thought because I don't know your version of UltraEdit. So I was forced to use no v11+ features.

Also the macro should work on the last line of the file even when it has no line ending. That requires extra code.

And last I didn't know if you have actived Configuration - Miscellaneous - Home Key always Goto column 1 or not and some other configuration settings could also have an influence on the result of the macro. Therefore I have written the macro using a method which hopefully works with all possible UltraEdit configurations.

The macro property Continue if a Find with Replace not found or Continue if search string not found must be checked for this macro.

IfSel
InsertMode
ColumnModeOff
HexOff
UnixReOff
Clipboard 9
Cut
"
"
Key UP ARROW
DupeLine
SelectLine
Find RegExp "?"
Replace All SelectText " "
EndSelect
Key UP ARROW
Key DOWN ARROW
Paste
"
"
Key UP ARROW
SelectLine
Find RegExp "?"
Replace All SelectText "-"
EndSelect
Key UP ARROW
Key DOWN ARROW
StartSelect
Key END
CutAppend
IfCharIs 13
Delete
Else
IfCharIs 10
Delete
EndIf
EndIf
Key UP ARROW
Key BACKSPACE
Key UP ARROW
Key END
Paste
ClearClipboard
Clipboard 0
Key DOWN ARROW
Key END
Key UP ARROW
EndIf

Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro before command EndIf 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: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros