Skip to content

Instantly share code, notes, and snippets.

@gingi
Created July 3, 2012 20:06
Show Gist options
  • Save gingi/3042634 to your computer and use it in GitHub Desktop.
Save gingi/3042634 to your computer and use it in GitHub Desktop.
BBEdit Script: Join Line With Next
tell application "BBEdit"
tell window 1
set currentLine to endLine of selection
set nextLine to currentLine + 1
-- Delete starting after the last non-whitespace character in the current line
set findDeleteStart to find "\\s*$" options {search mode:grep} ¬
searching in line currentLine
if found of findDeleteStart then
set firstCharacter to characterOffset of found object of findDeleteStart
else
set firstCharacter to characterOffset of line currentLine
end if
-- Delete until the first non-whitespace character in the next line
set findDeleteEnd to find "^\\s*" options {search mode:grep} ¬
searching in line nextLine
if found of findDeleteEnd then
set lastCharacter to characterOffset of (last character of (found object of findDeleteEnd))
else
set lastCharacter to (characterOffset of line nextLine) - 1
end if
-- Make the selection, then delete it
select (characters firstCharacter thru lastCharacter)
delete selection
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment