Skip to content

Instantly share code, notes, and snippets.

@9thbit
Forked from gingi/Join Line With Next.applescript
Last active December 12, 2015 09:49
Show Gist options
  • Save 9thbit/4754973 to your computer and use it in GitHub Desktop.
Save 9thbit/4754973 to your computer and use it in GitHub Desktop.
Join lines in BBEdit by placing a space character between the two lines.
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)
set contents of selection to " "
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment