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 <selection> 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: <<<selection>>>. Or
like this: #<selection># . 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
"[email protected]" 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 [email protected].
To post to this group, send email to [email protected].