The TextMate Super Function (AS3/PHP)
Following my obsession with TextMate snippets and commands, I created a function snippet which extended the basic function and added a few new useful features. This snippet is mapped to Shift + Enter. Just type the name of your function...
myFunction
and hit Shift + Enter after it. The following snippet is inserted:
/**
*
*
* @return
*/
public function myFunction()
{
}
The first tab stop is inside the parentheses so you can add some parameters, hit tab again to focus on the scope (public). We use a simple regular expression here to add "_" or "__" to the method name depending on if you type public|private|protected. The rest of the tabs go through the return statement, docblock and finally end inside the function declaration.
I've got both an AS3 and PHP version. Starting with the PHP version:
cat <<SNIPPET
/**
* $4
*
* @return $3
*/
${2:public} function ${2/(private)|(protected)|(.+)/(?1:__)(?2:_)(?3:)/}${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}($1)
{
$0
}
SNIPPET
And the AS3 version is basically the same with just a return type defined:
cat <<SNIPPET
/**
* $4
*
* @return ${5:$2}
*/
${3:public} function ${3/(private)|(protected)|(.+)/(?1:__)(?2:_)(?3:)/}${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}($1):${2:void}
{
$0${2/void$|(.+)/(?1:return null;)/}
}
SNIPPET
I'd also like to eventually add @param docs to the docblock as you type out parameters. Would love some suggestions there.
You can download both the PHP and AS3 Function Commands here. You can also download my TextMate theme Plum Dumb, or—if you're into PureMVC—you can download my PureMVC TextMate templates.