On Sep 02, 2011, at 13:05, 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?
______________________________________________________________________

Hey Rick,

I have not tested this thoroughly, but it seems to be working alright with 
indented and non-indented tags.

Note that I'm not testing for the presence of tags, so it will simply act on 
the line where the insertion point is regardless.

--
Best Regards,
Chris

______________________________________________________________________


tell application "BBEdit"
  try
    tell text of front text document
      set start_Line to startLine of selection
      set bbFind to find "^\\s+" searching in line start_Line ¬
        options {returning results:true, search mode:grep}
      if found of bbFind = true then
        set indentSpace to found text of bbFind
      else
        set indentSpace to ""
      end if
      set iSpaceLen to length of indentSpace
      set text of selection to (return & indentSpace & tab & return & 
indentSpace)
      set newInsertionPoint to (characterOffset of selection) + (length of 
selection) - 1 - iSpaceLen
      select insertion point before character newInsertionPoint
    end tell
    
  on error errMsg number errNum
    set sep to "=============================="
    set e to sep & return & "Error: " & errMsg & return & sep & return ¬
      & "Error Number: " & errNum & return & sep
    beep
    display dialog e
  end try
end tell

-- 
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