PHP code completion in TextMate
TextMate is a great all-round editor for simple (and some not-so-simple) tasks. For RoR, it's the dog's bullocks. I was, however, initially somewhat disappointed by its support for PHP.
Out of the box, TextMate doesn't support PHP code completion or provide you with an easy method of accessing the PHP documentation. I found, however, that you can easily configure it to do both of these things by downloading, installing and configuring the PHP Code Completion bundle.
To download and install the PHP code completion bundle, follow these instructions:
- Open Terminal
- Create a folder under /Library/Application Support/ called TextMate and a folder under that called /Bundles:
mkdir -p /Library/Application\ Support/TextMate/Bundles
- Switch to that folder:
cd /Library/Application\ Support/TextMate/Bundles
- Check out the bundle you want from the TextMate bundles repository:
svn co http://macromates.com/svn/Bundles/trunk/Bundles/PHPCodeCompletion.tmbundle
- If you had TextMate open during this, select Bundles → Bundle Editor → Reload Bundles.
Create a new PHP file and test out the code completion by typing the first few letters of a function name and pressing ⎋ (esc). If you press ⌥ F1 before code completion, you will see a list of similar functions and if you press it after completion, you will see some brief documentation on the function signature.
The PHP docs are probably the best I've seen for any programming language. The online version with comments is especially useful. Although TextMate doesn't have a built-in feature in the default bundles to access this documentation, the PHP code completion bundle you just installed does. It does require some configuration though.
With the PHP code completion bundle installed, you can access the PHP documentation by pressing Shift F1. The first time you do this, you will see a message telling you that you need to configure your settings.
To configure the PHP documentation:
- If you don't already have it, download the PHP documentation (.tar.gz version) to your computer. I placed the .tar.gz file in
/Users/aral/library/PHP_Manual/and unzipped it there. The unzipped files appear in an html folder so the path I entered in my preferences (see Step 4, below) was
/Users/aral/library/PHP_Manual/html/(do not leave out the trailing forward slash or else it won't work). Also, wherever you decide to place the documentaiton, make sure that none of the folder names on its path have a space in them.
- Click the Edit Preferences link in the PHPCodeCompletion Documentation window to open the PHPCodeCompletion preferences file in TextMate.
- Comment out the line that reads
$phpcc_configured = FALSE;and uncomment the one that sets the same flag to true.
- Set the path that you placed the documentation in to the value of the
- Save and close the preferences file.
Press Shift F1 on a function name to test out the documentation. If you see the familiar PHP web site appear, it means that you put the wrong path in the preferences file and that you are viewing the online docs as a backup. Of course, you may want to default to the online docs as they contain those invaluable user-submitted comments but it does make things slightly slower too.
That's it! You should now have code completion and documentation working for PHP in TextMate. Enjoy! :)