Script to Duplicate Line

56 views
Skip to first unread message

Christopher Stone

unread,
Feb 1, 2012, 11:35:22 PM2/1/12
to BBEdit Talk Talk
Hey Folks,

For some time I've wanted a feature in BBEdit I've seen in other programming editors, and that is 'duplicate line'.

Of course it's easy enough to Cmd-L, Cmd-C, Cmd-V x 2, but when you do that the contents of the clipboard is compromised.

Frequently I want to copy some text from somewhere, duplicate a line in BBEdit, and paste the text from the clipboard into the duplicated line somewhere.

Or I might want to duplicate a line and do something else with it.

I finally took the time to write a script to duplicate the current line and then select it:

try
  tell application "BBEdit" to tell text of line (startLine of selection) of text document 1
    if (it as text) is not "" then
      set its text to ("" & it & return & it)
      select it
    end if
  end tell
on error eMsg number eNum
  set {c, s} to {return, "------------------------------------------"}
  set e to s & c & "Error: " & eMsg & c & s & c & "eNum: " & eNum & c & s
beep
display dialog e
end try

The script will fail silently if there is no text on the line where the cursor is.

--
Best Regards,
Chris

Charlie Garrison

unread,
Feb 2, 2012, 12:56:04 AM2/2/12
to bbe...@googlegroups.com
Good afternoon,

On 1/02/12 at 10:35 PM -0600, Christopher Stone
<listm...@thestoneforge.com> wrote:

>For some time I've wanted a feature in BBEdit I've seen in
>other programming editors, and that is 'duplicate line'.

Been done already, specifically:

<http://www.entropy.ch/blog/Mac+OS+X/2008/05/25/BBEdit-AppleScript-Improved-Duplicate-Lines-and-Select-Lines.html>

Along with some others:

<http://www.entropy.ch/blog/?query=bbedit>

Or the ones I use (almost, I made some minor changes):

<https://groups.google.com/group/bbedit/msg/d186393e8ab45284>


Charlie

--
Ꮚ Charlie Garrison ♊ <garr...@zeta.org.au>

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
http://www.ietf.org/rfc/rfc1855.txt

Christopher Stone

unread,
Feb 2, 2012, 1:36:09 AM2/2/12
to bbe...@googlegroups.com
On Feb 01, 2012, at 23:56, Charlie Garrison wrote:
Good afternoon,

Not in these parts.  :)

On 1/02/12 at 10:35 PM -0600, Christopher Stone <listm...@thestoneforge.com> wrote:
For some time I've wanted a feature in BBEdit I've seen in other programming editors, and that is 'duplicate line'.

Been done already, specifically:

It looks like there might be some useful stuff there.  Thanks.

Here's my script updated to handle one or more lines.

try
  tell application "BBEdit"
    tell text of lines (get startLine of selection) thru (get endLine of selection) of text document 1
      if (it as text) is not "" and (it as text) is not return then
        set its text to ("" & it & return & it)
        select it
      end if
    end tell
  end tell
on error eMsg number eNum
  set {c, s} to {return, "------------------------------------------"}
  set e to s & c & "Error: " & eMsg & c & s & c & "eNum: " & eNum & c & s
  beep
  display dialog e
end try

--
Best Regards,
Chris

Reply all
Reply to author
Forward
0 new messages