At 11:05 -0700 02/09/2011, Rick Yentzer wrote:

I'm attempting to write an applescript that will automate some keystrokes.

What I want to occur is when I'm inside a tag like so:

<tag>insertion point</tag>

I want to be able to run the script to get the following format:

<tag>

    insertion point

</tag>

This part I have been able to accomplish. But how do I get it to see if the tag is indented and if so, keep the insertion point and closing tag indented as well?


These things are so much more easily done using text filters, which operate on the lines of the selection, unless there is none, in which case they operate on the whole text of the doc.

Here's how I would do it:


#! /usr/bin/perl
while (<>) {
  $tabs = $1 if s~^(\t+)~~;
  s~(<[^>]+>) # opening tag = $1
  ([^<]+) # enclosed text = $2
  (<[^>]+>) # closing tag = $3.  Replace with:
  ~$tabs$1\n$tabs\t$2\n$tabs$3~x;
  print;
}

As you see, the skeleton of the script, and numberless similar scripts is:


        while(<>) {
          # substitutions, additions, deletions etc.
          print
        }

If you can use regular expressions in BBEdit's find dialogue then you can use them in a Perl script and you can write such filters with practically no knowledge of Perl. AppleScript sucks for such things. AppleScript is for user interaction and for doing things in the app that only Apple events can achieve.

JD

--
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 bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
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 "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Reply via email to