Created
September 13, 2011 18:34
-
-
Save bclennox/1214623 to your computer and use it in GitHub Desktop.
BBEdit Menu Script to act like TextMate's commenter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.