Surround Selection With...

2013-10-19 Thread Oliver Taylor
I'm attempting to create a script that surrounds the selected text with paired 
characters - in a smart way.

For example, if you want to surround the selection with  then just 
enter < and the script will do the right thing. I've got that working, but I'd 
love to make it a bit better.

For example, I might to surround the selection like this: <<>>. Or 
like this:  ## . Or like this: (( *selection* ))

Can anyone help me figure this out? Maybe this is beyond a simple script like 
this?

Here's what I've got so far...

--Display Dialog and Get Input
display dialog "Surround Selection With..." default answer ""

--Get Answer & Return Comment
set surround to (text returned of result)

tell application "BBEdit"
try
-- test to see if input has a matching character - {}()[] etc.
-- then surround the selection with the pair
if surround is in {"{"} then
set selection to "{" & selection & "}"
else if surround is in {"("} then
set selection to "(" & selection & ")"
else if surround is in {"["} then
set selection to "[" & selection & "]"
else if surround is in {"“"} then
set selection to "“" & selection & "”"
else if surround is in {"‘"} then
set selection to "‘" & selection & "’"
else if surround is in {"<"} then
set selection to "<" & selection & ">"
else
-- if there's no match then just surround with the 
input on both sides
set selection to surround & selection & surround
end if
end try
end tell

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.


Re: Surround Selection With...

2013-10-20 Thread Den Dowling
Have you tried Clippings in BBEdit yet? A Clipping is just 
a way to quickly add a chunk of commonly used text into your 
document. It also works with what you have selected before 
choosing the clipping.


For example, you select 'a few words' in your document, 
choose your Double Paren Clipping and, it converts to '((a few words))'.


You can access your Clippings in the top menu under the 
black C icon. There's a Clippings Palette you can keep open for 
easy access (Window>Palettes>Clippings). Or, you can also assign 
a keyboard shortcut to each of your Clippings.


Your example Double Paren Clipping would just be a plain 
text file that contains..

((#SELECT#))

Make new ones by starting a new file in BBE, write your 
clipping and choose Save as Clipping under the Clipping icon. 
Under the Clippings icon you can choose Open Clippings Folder to 
see all your Clipping files and organize them into different 
Sets or subfolders.


There are a bunch of other placeholders you can use besides 
#SELECT# like, #FILE#, #DATE# #CLIPBOARD#, etc.


See Chapter 12 in BBEdit Manual.

- Den.


10/19/13 8:26 PM, olivertay...@me.com (Oliver Taylor) apparently typed:

I'm attempting to create a script that surrounds the selected text with paired 
characters - in a smart way.

For example, if you want to surround the selection with 
 then just enter < and the script will do the right 
thing. I've got that working, but I'd love to make it a bit better.


For example, I might to surround the selection like this: 
<<>>. Or like this:  ## . Or like this: 
(( *selection* ))


Can anyone help me figure this out? Maybe this is beyond a simple script like 
this?

Here's what I've got so far...

--Display Dialog and Get Input
display dialog "Surround Selection With..." default answer ""

--Get Answer & Return Comment
set surround to (text returned of result)

tell application "BBEdit"
try
-- test to see if input has a matching character - {}()[] etc.
-- then surround the selection with the pair
if surround is in {"{"} then
set selection to "{" & selection & "}"
else if surround is in {"("} then
set selection to "(" & selection & ")"
else if surround is in {"["} then
set selection to "[" & selection & "]"
else if surround is in {"“"} then
set selection to "“" & selection & "”"
else if surround is in {"‘"} then
set selection to "‘" & selection & "’"
else if surround is in {"<"} then
set selection to "<" & selection & ">"
else
-- if there's no match then just surround with the input on both sides
set selection to surround & selection & surround
end if
end try
end tell



--
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email

"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

--- 
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.


Re: Surround Selection With...

2013-10-20 Thread Oliver Taylor
> On Oct 20, 2013, at 1:01 AM, Den Dowling  wrote:
> 
> Have you tried Clippings in BBEdit yet?

Oh yes, of course.

But I can't possibly anticipate all the characters I might want surround the 
selection with. This script allows you to surround with anything the user can 
think of. Plus, it would be a single hot-key for all surrounds, which I like 
the idea of. 

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 

--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.


Re: Surround Selection With...

2013-10-31 Thread Andy Guzman
Someone who is better at Python can probably clean this up / do a better 
job, but here is what I came up with. I'm also having a problem with my 
text filters inserting new lines all of a sudden... so that might need to 
be fixed too.

https://gist.github.com/andyguzman/7257334

Save that as a Text Filter. Then you can set up a key shortcut for it in 
the BBEdit or System Preferences, I believe.

I set a couple expected pairs, but you could add to that list. If you use a 
character that doesn't show up in that list it will just be used as is for 
the closing tag. I'm a super python novice and as such take no 
responsibility, etc. :-)

On Sunday, October 20, 2013 9:26:11 AM UTC-7, Oliver Taylor wrote:
>
> > On Oct 20, 2013, at 1:01 AM, Den Dowling > 
> wrote: 
> > 
> > Have you tried Clippings in BBEdit yet? 
>
> Oh yes, of course. 
>
> But I can't possibly anticipate all the characters I might want surround 
> the selection with. This script allows you to surround with anything the 
> user can think of. Plus, it would be a single hot-key for all surrounds, 
> which I like the idea of. 

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 

--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.