Duplicate Line not working as expected

This forum is user-to-user based and not regularly monitored by IDM.
Please see the note at the top of this page on how to contact IDM.

Duplicate Line not working as expected

Postby reaton » Mon Jul 09, 2007 2:16 pm

Hello All,

I am new to UE and have a problem with DuplicateLine command. It appears that DuplicateLine only works correctly if there is a 'Line terminator' present on the line you are trying to duplicate. For example if I type:

Code: Select all
       This a test

and immediately issue a DuplicateLine the results is:

Code: Select all
       This is a test      This is a test

It puts it on the same line. If I type in the same sentence and hit enter which puts a 'Line terminator' at the end and then issue the DuplicateLine command I get the following expected results:

Code: Select all
       This is a test 
       This is a test

The line is actually duplicated like I want. How can I get DuplicateLine to work regardless of whether there is a 'Line terminator' or not. This is a very common feature I use on a daily basis. Thanks.

Ronnie
reaton
Newbie
 
Posts: 3
Joined: Sun Jul 08, 2007 11:00 pm

Re: Duplicate Line not working as expected

Postby Mofi » Mon Jul 09, 2007 2:56 pm

A line must have a line termination or it is not a line. If the text at the end of a file does not end with a line termination, it is just a text (string) at the end of the file, but not a line.

Here is a macro which automatically appends the line termination when executing it for duplicating the current line.

InsertMode
ColumnModeOff
HexOff
Key END
IfCharIs 13
Else
IfCharIs 10
Else
"
"
Key UP ARROW
EndIf
EndIf
Clipboard 9
SelectLine
Copy
EndSelect
Key UP ARROW
Key DOWN ARROW
Paste
ClearClipboard
Clipboard 0

But this quick solution has 1 disadvantage: the cursor is always at start of the line after macro execution and not exactly at the same column in the new line as the command Duplicate Line does. I think, it cannot be better solved with a macro without special marking current cursor position before macro execution and run two replaces to delete this marker at the end of the macro to finally restore the cursor position. But that would produce additional undo steps which you maybe don't want.

A better solution would be to convert this macro to a script. In the script environment it is possible to get the current column number and set the cursor at the end of the script to this column in the new line. But this requires UE v13.10 or higher.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4054
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Duplicate Line not working as expected

Postby reaton » Mon Jul 09, 2007 7:42 pm

Hello Mofi,


Thanks.......macro works fine with files that end with .txt (test.txt). But on files that have no extension like (test) it does not work. How do I associated this macro for a file with no extension. Thanks.

Ronnie
reaton
Newbie
 
Posts: 3
Joined: Sun Jul 08, 2007 11:00 pm

Re: Duplicate Line not working as expected

Postby Mofi » Tue Jul 10, 2007 6:17 am

A macro does never depend on a file extension. This macro should be a part of a macro file which is automatically loaded during start of UltraEdit. The macro itself should have a hot key for fast execution. Whenever you want do duplicate a line, you can press this hot key and the macro will do the job independent of the line ending.

I have tested the macro on a new edit window which content was never saved into a file and it worked.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4054
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to UltraEdit General Discussion