PHP code completion in TextMate

Alongside Flex Builder 2, TextMate is my editor of choice on OS X.

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.

Code completion

To set up code completion in TextMate, you must first download the PHP Code Completion bundle. As you can see, that link leads to an SVN repository.

To download and install the PHP code completion bundle, follow these instructions:

  1. Open Terminal
  2. Create a folder under /Library/Application Support/ called TextMate and a folder under that called /Bundles:
    mkdir -p /Library/Application\ Support/TextMate/Bundles
  3. Switch to that folder:
    cd /Library/Application\ Support/TextMate/Bundles
  4. Check out the bundle you want from the TextMate bundles repository:
    svn co http://macromates.com/svn/Bundles/trunk/Bundles/PHPCodeCompletion.tmbundle
  5. 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.

Documentation

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:

  1. 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.
  2. Click the Edit Preferences link in the PHPCodeCompletion Documentation window to open the PHPCodeCompletion preferences file in TextMate.
  3. Comment out the line that reads $phpcc_configured = FALSE; and uncomment the one that sets the same flag to true.
  4. Set the path that you placed the documentation in to the value of the $phpcc_manual_path_to_local variable.
  5. 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! :)

Creative Commons LicenseThe PHP code completion in TextMate article by Aral Balkan, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.0 UK: England License.

18 Responses to “PHP code completion in TextMate”


  1. 1 kevin

    I have tried to svn this, but have been unable to get it to work, is it possible to please send the actual tmbundle to me? I keep getting an error that says svn: command unknown… Thanks for the writeup on the process, it sold me in wanting the code completion as I used to have that (almost standard with every editor on the windows side) though I am extremely new to Mac and am completely lost.

  2. 2 Rob McMichael

    You can download them from here
    http://www.imediatec.co.uk/tm/phpcc/

  3. 3 kevin

    you are very kind, thanks very much.

  4. 4 John Joyce

    Hi, I downloaded and installed this bundle yesterday. The fuction lookup works. In fact everything seems to be working except for code completion.
    Pressing the ESC key just gives me the system alert sound. “bonk”
    Did I miss something? Do I need to have the local documentation installed to use code completion?

    btw, getting SVN installed properly was a pain. packages out there install it to the system but don’t make it available to users. Had to find it, add it to the PATH then restart terminal to use it.

  5. 5 George

    Thanks for this post. I followed your instructions and it worked perfectly.

    I’m relatively new to TextMate and am really loving it. It is this kind of feature that really sets it apart.

    Thanks again!

  6. 6 Brian

    Link is not working!!
    Brian

  7. 7 Chris

    Appears that this has been moved to the disabled bundles:

    http://macromates.com/svn/Bundles/trunk/Disabled Bundles/PHPCodeCompletion.tmbundle/

  8. 8 Matt

    Thanks for the info, extremely helpful. :)
    Here’s some updates for new readers:

    1. Open Terminal, type ’svn’, if you see ‘-bash: svn: command not found’ you don’t have svn installed.

    2. You can install Martin Ott’s svn package from http://www.codingmonkeys.de/mbo/

    3. Follow steps 1 through 3 in this article

    4. Type this in place of step 4 above (so it pulls from the new location):

    svn co http://macromates.com/svn/Bundles/trunk/Disabled Bundles/PHPCodeCompletion.tmbundle/

  9. 9 Matt

    You need to put a “percent 20″ (a percent symbol % followed immediately by the number 20) in place of the space between the words ‘Disabled’ and ‘Bundles’ in previous svn checkout path (doesn’t appear to show up in the comments).

  10. 10 Nick

    Installed last night with no problem…. Thank you this helps a lot.

  11. 11 hsyn

    Installed and had no problem at all, thanks

  12. 12 Allan Odgaard

    The plain PHP bundle supports completion, documentation lookup, and quick function synopsis (see Bundles → PHP → Help) — I have now removed the PHPCodeCompletion bundle from the repository to avoid confusion.

  13. 13 Aral

    Thanks for the update, Allan :)

  14. 14 Alexandra

    Hy, I tried to install it but as long as i see none of the links are working!
    Thanks!

  15. 15 Sam

    @Alexandra Same problem here 404 on the URIs.

  1. 1 TextMate - text editor for MacOSX « Kenjun
  2. 2 TextMateでPHPマニュアルを参照するBundle « ZerockBlog
  3. 3 Netbeans vs TextMate — Josh Kim dot Org

Leave a Reply






Bad Behavior has blocked 0 access attempts in the last 7 days.