On 01/15/2019, at 19:25, Venkat <[email protected]
<mailto:[email protected]>> wrote:
> Thank you so much! I don't know AppleScript very well, so I can't ask further
> questions to understand what exactly you're doing 😅 .
Hey Venkat,
Here's a commented version that may help.
--
Best Regards,
Chris
----------------------------------------------------------------
# Create a variable with the text to be inserted.
set textToInsert to "pdb.set_trace()" & linefeed
tell application "BBEdit"
tell front text window
# Get the line where the cursor is.
set start_Line to startLine of selection
# Get the character offset of the cursor.
set character_Offset to characterOffset of selection
tell text of line start_Line
# Find any leading space in the line where the cursor is.
set findRec to find "^\\h+" options {search mode:grep, case
sensitive:false, starting at top:false}
# Assign a variable to the text of the line where the cursor is.
set cLineText to its contents
end tell
# Assign a variable to the leading space of the line where the cursor
is (if found).
# Otherwise assing an empty string to that same variable.
if found of findRec = true then
set leadingSpacePad to found text of findRec
else
set leadingSpacePad to ""
end if
# Change the contents of the line where the cursor is to:
leadingSpacePad & textToInsert & cLineText
set contents of line start_Line to leadingSpacePad & textToInsert &
cLineText
# Reposition the cursor to the same position in the moved line.
select insertion point after character (character_Offset + (length of
leadingSpacePad) + (length of textToInsert) - 1)
end tell
end tell
----------------------------------------------------------------
--
This is the BBEdit Talk public discussion group. If you have a
feature request or need technical support, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <https://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].
Visit this group at https://groups.google.com/group/bbedit.