Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
BBEdit Menu Script to act like TextMate's commenter
on menuselect(menuName, itemName)
tell application "BBEdit"
if (length of (selection of text window 1) > 0) then
return false
else
set documentMode to source language of text document 1
if (documentMode is "Ruby" or documentMode is "Unix Shell Script") then
set commentDelimiter to "# "
else
set commentDelimiter to "// "
end if
set theLineNumber to ((startLine of selection) of text window 1)
set theLineReference to (line theLineNumber of text document 1)
set theLine to (contents of theLineReference) as string
if (theLine begins with commentDelimiter) then
delete (characters 1 thru (length of commentDelimiter)) of theLineReference
else
select insertion point before (character 1 of theLineReference)
set selection to commentDelimiter
select insertion point before (character 1 of theLineReference)
end if
return true
end if
end tell
end menuselect
Owner

bclennox commented Sep 13, 2011

Note: You must use Finder to name this file "Text•Un/Comment Selection.scpt" and save it in your BBEdit Menu Scripts folder. Terminal and Script Editor do not allow slashes in filenames. See my article for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment