At 14.35 -0700 2009-10-22, daedalus wrote:
>I'm coming from Windows where most of the editors I used had a built-
>in way to duplicate a line. I cannot seem to locate that functionality
>in BBEdit. Is there a built-in way I'm just overlooking or a macro or
>something I can do that would allow me to accomplish this?
>
>Thanks,
>Richard

Here are a couple of scripts I wrote that I use almost daily. I've mapped them 
to cmd-opt-up and cmd-opt-down. The line at the selection point or all lines 
that the current selection touches will be duplicated. The resulting selection 
will be the entire duplicated lines.

I also have corresponding scripts to move line(s) upwards and downwards, but 
they are a little bit buggy (I haven't been able to work around all edge case 
quirks) so I don't include them here, but they are mapped to cmd-ctrl-up/down.

----------------------------------------
-- Duplicate line(s) downwards
-- Johan Sölve 2008-12-20
tell application "BBEdit"
        set selStart to (startLine of selection)
        set selEnd to (endLine of selection)
        set seloffset to (characterOffset of selection)
        set selLength to (length of selection)
        if selLength > 1 then
                -- check if full lines are selected, in that case deselect the 
trailing linebreak
                select (characters seloffset thru (seloffset + selLength - 2) 
of document 1)
                if (endLine of selection) < selEnd then set selEnd to (endLine 
of selection)
        else if selLength = 1 then
                -- a single character can only be a single line, but a selected 
empty line looks like two lines, fix this
                set selEnd to selStart
        end if
        set copylines to contents of (lines selStart thru selEnd) of document 1
        -- insert after last line of selection
        select insertion point after line selEnd of document 1
        set selection to return & copylines
        -- we have a new selection now, deselect the leading linebreak to make 
repeated duplicates work properly
        set seloffset to (characterOffset of selection)
        set selLength to (length of selection)
        select (characters (seloffset + 1) thru (seloffset + selLength - 1) of 
document 1)
end tell

----------------------------------------
-- Duplicate line(s) upwards
-- Johan Sölve 2008-12-20
tell application "BBEdit"
        set selStart to (startLine of selection)
        set selEnd to (endLine of selection)
        set seloffset to (characterOffset of selection)
        set selLength to (length of selection)
        if selLength > 1 then
                -- check if full lines are selected, in that case deselect the 
trailing linebreak
                select (characters seloffset thru (seloffset + selLength - 2) 
of document 1)
                if (endLine of selection) < selEnd then set selEnd to (endLine 
of selection)
        else if selLength = 1 then
                -- a single character can only be a single line, but a selected 
empty line looks like two lines, fix this
                set selEnd to selStart
        end if
        set copylines to contents of (lines selStart thru selEnd of document 1)
        -- insert before first line of selection
        select insertion point before line selStart of document 1
        set selection to copylines & return
        -- we have a new selection now, deselect the trailing linebreak to make 
repeated duplicates work properly
        set seloffset to (characterOffset of selection)
        set selLength to (length of selection)
        select (characters seloffset thru (seloffset + selLength - 2) of 
document 1)
end tell



-- 
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[email protected]
 (spam-safe email address, replace '-' with 'a')

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
-~----------~----~----~----~------~----~------~--~---

Reply via email to